Added documentation and implemented empty functionarguments

This commit is contained in:
abzicht
2019-03-10 13:41:02 +01:00
parent 6c84544521
commit 1dfff7ac0e

View File

@@ -7,8 +7,6 @@
%options case-insensitive
/* string is used to detect blocks that are surrounded by double quotes. */
/* copied from /src/diagrams/flowchart/parser/flow.jison */
%x click
%x href
%x callbackname
@@ -20,16 +18,37 @@
\#[^\n]* /* skip comments */
\%%[^\n]* /* skip comments */
"href"[\s]+["] this.begin("href"); /* return the next double quoted word after 'href' */
<href>["] this.popState(); /* e.g. return https://example.com for 'href "https://example.com"' */
/*
---interactivity command---
'href' adds a link to the specified task. 'href' can only be specified when the
line was introduced with 'click'.
'href "<link>"' attaches the specified link to the task that was specified by 'click'.
*/
"href"[\s]+["] this.begin("href");
<href>["] this.popState();
<href>[^"]* return 'href';
/*
---interactivity command---
'call' adds a callback to the specified task. 'call' can only be specified when
the line was introdcued with 'click'.
'call <callbackname>(<args>)' attaches the function 'callbackname' with the specified
arguments to the task that was specified by 'click'.
Function arguments are optional: 'call <callbackname>()' simply executes 'callbackname' without any arguments.
*/
"call"[\s]+ this.begin("callbackname");
<callbackname>\([\s]*\) this.popState();
<callbackname>\( this.popState(); this.begin("callbackargs");
<callbackname>[^(]* return 'callbackname';
<callbackargs>\) this.popState();
<callbackargs>[^)]* return 'callbackargs';
/*
'click' is the keyword to introduce a line that contains interactivity commands.
'click' must be followed by an existing task-id. All commands are attached to
that id.
'click <id>' can be followed by href or call commands in any desired order
*/
"click"[\s]+ this.begin("click");
<click>[\s\n] this.popState();
<click>[^\s\n]* return 'click';
@@ -79,17 +98,31 @@ statement
| taskTxt taskData {yy.addTask($1,$2);$$='task';}
;
/*
click allows any combination of href and call.
*/
clickStatement
: click callbackname callbackargs {$$ = $1;yy.setClickEvent($1, $2, $3);}
: click callbackname {$$ = $1;yy.setClickEvent($1, $2, null);}
| click callbackname callbackargs {$$ = $1;yy.setClickEvent($1, $2, $3);}
| click callbackname href {$$ = $1;yy.setClickEvent($1, $2, null);yy.setLink($1,$3);}
| click callbackname callbackargs href {$$ = $1;yy.setClickEvent($1, $2, $3);yy.setLink($1,$4);}
| click href callbackname {$$ = $1;yy.setClickEvent($1, $3, null);yy.setLink($1,$2);}
| click href callbackname callbackargs {$$ = $1;yy.setClickEvent($1, $3, $4);yy.setLink($1,$2);}
| click href {$$ = $1;yy.setLink($1, $2);}
;
clickStatementDebug
: click callbackname callbackargs {$$=$1+' ' + $2 + ' ' + $3;}
| click callbackname callbackargs href {$$=$1+' ' + $2 + ' ' + $3 + ' ' + $4;}
| click href callbackname callbackargs {$$=$1+' ' + $2 + ' ' + $3 + ' ' + $4;}
| click href {$$=$1+' ' + $2;}
;
%%
: click callbackname {$$=$1 + ' ' + $2;}
| click callbackname href {$$=$1 + ' ' + $2 + ' ' + $3;}
| click callbackname callbackargs {$$=$1 + ' ' + $2 + ' ' + $3;}
| click callbackname callbackargs href {$$=$1 + ' ' + $2 + ' ' + $3 + ' ' + $4;}
| click href callbackname {$$=$1 + ' ' + $2 + ' ' + $3;}
| click href callbackname callbackargs {$$=$1 + ' ' + $2 + ' ' + $3 + ' ' + $4;}
| click href {$$=$1 + ' ' + $2;}
;%%