Skip to content

Commit

Permalink
v.2.1.1
Browse files Browse the repository at this point in the history
* change optional block main argument to beprimarily  a loop argument, if exists
* optional block with NO optional args is rendered anyway (different from previous versions)
  • Loading branch information
Nikos M committed Nov 29, 2016
1 parent 890e990 commit 1764275
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
**Grammar Template**

A block inside `[..]` represents an optional block of `code` (depending on passed parameters) and `<..>` describe placeholders for `query` parameters / variables (i.e `non-terminals`).
The optional block of code depends on whether **all** optional parameters defined inside (with `<?..>`, `<?!..>` or `<*..>` for rest parameters) exist. Then, that block (and any nested blocks it might contain) is output, else bypassed.
The optional block of code depends on whether **all** optional parameters defined inside (with `<?..>`, `<?!..>` or `<*..>` and `<{n,m}..>` for rest parameters) exist. Then, that block (and any nested blocks it might contain) is output, else bypassed.

A block defined with `:=[..]` represents a (recursive) sub-template, which can be used to render any deep/structured argument a needed (see below).

Expand Down Expand Up @@ -223,4 +223,4 @@ output:
* handle boolean-like optional arguments [DONE, through setting (empty) default value for optional argumement, is handled as pure boolean on/off flag argument]
* optimise parsing and rendering [DONE]
* support some basic and/or user-defined functions [DONE, similar custom function definition as custom sub-template, calls function if custom function with same name has been defined]
* support both `pre-` and `post-` (repeat) grammar operators, i.e both `<?symbol>`,`<*symbol>`,`<{0,2}symbol>` and `<symbol>?`,`<symbol>*`,`<symbol>{0,2}` for more familiar grammar syntax [DONE, via extra parameter in template instantiation]
* support both `pre-` and `post-` (repeat) grammar operators, i.e both `<?symbol>`,`<*symbol>`,`<{n,m}symbol>` and `<symbol>?`,`<symbol>*`,`<symbol>{n,m}` for more familiar grammar syntax [DONE, via extra parameter in template instantiation]
12 changes: 12 additions & 0 deletions src/js/GrammarTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,18 @@ function multisplit( tpl, delims, postop )
else if ( optional )
{
// handle multiple optional arguments for same optional block
if ( (start_i !== end_i) && (cur_arg.start === cur_arg.end) )
{
// set as main arg a loop arg, if exists
cur_arg.name = argument;
cur_arg.key = nested;
cur_arg.stpl = template;
cur_arg.dval = default_value;
cur_arg.opt = optional;
cur_arg.neg = negative;
cur_arg.start = start_i;
cur_arg.end = end_i;
}
opt_args = new StackEntry(opt_args, [argument,nested,negative,start_i,end_i,optional]);
}
else if ( !optional && (null === cur_arg.name) )
Expand Down
2 changes: 1 addition & 1 deletion src/js/GrammarTemplate.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/php/GrammarTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ public static function multisplit( $tpl, $delims, $postop=false )
else if ( $optional )
{
// handle multiple optional arguments for same optional block
if ( ($start_i !== $end_i) && ($cur_arg->start === $cur_arg->end) )
{
// set as main arg a loop arg, if exists
$cur_arg->name = $argument;
$cur_arg->key = $nested;
$cur_arg->stpl = $template;
$cur_arg->dval = $default_value;
$cur_arg->opt = $optional;
$cur_arg->neg = $negative;
$cur_arg->start = $start_i;
$cur_arg->end = $end_i;
}
$opt_args = new GrammarTemplate__StackEntry($opt_args, array($argument,$nested,$negative,$start_i,$end_i,$optional));
}
else if ( !$optional && (null === $cur_arg->name) )
Expand Down
10 changes: 10 additions & 0 deletions src/python/GrammarTemplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,16 @@ def multisplit( tpl, delims, postop=False ):

elif optional:
# handle multiple optional arguments for same optional block
if (start_i != end_i) and (cur_arg['start'] == cur_arg['end']):
# set as main arg a loop arg, if exists
cur_arg['name'] = argument
cur_arg['key'] = nested
cur_arg['stpl'] = template
cur_arg['dval'] = default_value
cur_arg['opt'] = optional
cur_arg['neg'] = negative
cur_arg['start'] = start_i
cur_arg['end'] = end_i
opt_args = StackEntry(opt_args, [argument,nested,negative,start_i,end_i,optional])

elif (not optional) and (cur_arg['name'] is None):
Expand Down

0 comments on commit 1764275

Please # to comment.