Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
preprocessor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Normann Rion
preprocessor
Commits
2b3519e3
Verified
Commit
2b3519e3
authored
5 years ago
by
Houtan Bastani
Browse files
Options
Downloads
Patches
Plain Diff
macro processor: add for syntax for shortcut with filtering comprehension
closes #28
parent
def99f9d
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
doc/macroprocessor/macroprocessor.tex
+16
-2
16 additions, 2 deletions
doc/macroprocessor/macroprocessor.tex
src/macro/Parser.yy
+30
-26
30 additions, 26 deletions
src/macro/Parser.yy
with
46 additions
and
28 deletions
doc/macroprocessor/macroprocessor.tex
+
16
−
2
View file @
2b3519e3
...
...
@@ -399,12 +399,26 @@ end;
\end{frame}
\begin{frame}
[fragile=singleslide]
\frametitle
{
Loop directive
}
\begin{block}
{
Syntax
}
\frametitle
{
Loop directive
(1/2)
}
\begin{block}
{
Syntax
1
}
\verb
+
@#for
+
\textit
{
variable
\_
name
}
\verb
+
in
+
\textit
{
array
\_
expr
}
\\
\verb
+
+
\textit
{
loop
\_
body
}
\\
\verb
+
@#endfor
+
\end{block}
\begin{block}
{
Syntax 2
}
\verb
+
@#for
+
\textit
{
tuple
}
\verb
+
in
+
\textit
{
array
\_
expr
}
\\
\verb
+
+
\textit
{
loop
\_
body
}
\\
\verb
+
@#endfor
+
\end{block}
\begin{block}
{
Syntax 3
}
\verb
+
@#for
+
\textit
{
tuple
\_
or
\_
variable
}
\verb
+
in
+
\textit
{
array
\_
expr
}
\verb
+
when
+
\textit
{
expr
}
\\
\verb
+
+
\textit
{
loop
\_
body
}
\\
\verb
+
@#endfor
+
\end{block}
\end{frame}
\begin{frame}
[fragile=singleslide]
\frametitle
{
Loop directive (2/2)
}
\begin{block}
{
Example: before macro processing
}
\small
\begin{verbatim}
...
...
This diff is collapsed.
Click to expand it.
src/macro/Parser.yy
+
30
−
26
View file @
2b3519e3
...
...
@@ -95,11 +95,10 @@ using namespace macro;
%type <DirectivePtr> directive directive_one_line directive_multiline for if ifdef ifndef text eval
%type <vector<pair<ExpressionPtr, vector<DirectivePtr>>>> if_list if_list1
%type <pair<ExpressionPtr, vector<DirectivePtr>>> elseif else
%type <ExpressionPtr> primary_expr oper_expr colon_expr expr
%type <ExpressionPtr> primary_expr oper_expr colon_expr expr
for_when
%type <FunctionPtr> function
%type <VariablePtr> symbol
%type <vector<VariablePtr>> comma_name
%type <vector<ExpressionPtr>> comma_expr function_args tuple_comma_expr
%%
...
...
@@ -149,38 +148,43 @@ directive_multiline : for
| ifndef
;
for_begin : FOR { driver.pushContext(); } ;
for_when : %empty
{ $$ = shared_ptr<Expression>(); }
| WHEN expr
{ $$ = $2; }
;
for : for_begin symbol IN expr EOL statements ENDFOR
{
vector<VariablePtr> vvnp = {$2};
auto vdp = driver.popContext();
vdp.emplace_back(make_shared<TextNode>("\n", driver.env, @7));
$$ = make_shared<For>(vvnp, $4, vdp, driver.env, @$);
}
| for_begin LPAREN comma_name RPAREN IN expr EOL statements ENDFOR
for : FOR { driver.pushContext(); } expr IN expr for_when EOL statements ENDFOR
{
vector<VariablePtr> vvnp;
for (auto & it : $3)
auto tmpt = dynamic_pointer_cast<Tuple>($3);
auto tmpv = dynamic_pointer_cast<Variable>($3);
if (tmpv)
vvnp.emplace_back(tmpv);
else if (tmpt)
for (auto & it : tmpt->getValue())
{
auto vnp = dynamic_pointer_cast<Variable>(it);
if (!vnp)
error(@$, "For loop indices must be variables");
vvnp.
push
_back(vnp);
vvnp.
emplace
_back(vnp);
}
else
error(@1, "For loop indices must be a variable or a tuple");
auto vdp = driver.popContext();
vdp.emplace_back(make_shared<TextNode>("\n", driver.env, @9));
$$ = make_shared<For>(vvnp, $6, vdp, driver.env, @$);
}
;
comma_name : NAME
{ $$ = vector<VariablePtr>{make_shared<Variable>($1, driver.env, @$)}; }
| comma_name COMMA NAME
{ $1.emplace_back(make_shared<Variable>($3, driver.env, @3)); $$ = $1; }
if (!$6)
$$ = make_shared<For>(vvnp, $5, vdp, driver.env, @$);
else
{
auto tmpc = make_shared<Comprehension>(true, $3, $5, $6, driver.env, @6);
$$ = make_shared<For>(vvnp, tmpc, vdp, driver.env, @$);
}
}
;
if : IF { driver.pushContext(); } if_list ENDIF
{ $$ = make_shared<If>($3, driver.env, @$); }
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment