|
23 | 23 | * <block> :== ( <comment> | <command> | <control> | <function> | |
24 | 24 | * <statement> )[0..n] |
25 | 25 | * |
26 | | - * <control> :== <if> | <for> | <while> | <repeat> |
| 26 | + * <control> :== <if> | <for> | <while> | <repeat> | <upon> |
27 | 27 | * <if> :== \IF{<cond>} <block> |
28 | 28 | * ( \ELIF{<cond>} <block> )[0..n] |
29 | 29 | * ( \ELSE <block> )[0..1] |
|
32 | 32 | * <for> :== \FOR{<cond>} <block> \ENDFOR |
33 | 33 | * <while> :== \WHILE{<cond>} <block> \ENDWHILE |
34 | 34 | * <repeat> :== \REPEAT <block> \UNTIL{<cond>} |
| 35 | + * <upon> :== \UPON{<cond>} <block> \EDNUPON |
35 | 36 | * |
36 | 37 | * <function> :== \FUNCTION{<name>}{<params>} <block> \ENDFUNCTION |
37 | 38 | * (same for <procedure>) |
@@ -261,6 +262,7 @@ Parser.prototype._parseControl = function() { |
261 | 262 | if ((controlNode = this._parseIf())) return controlNode; |
262 | 263 | if ((controlNode = this._parseLoop())) return controlNode; |
263 | 264 | if ((controlNode = this._parseRepeat())) return controlNode; |
| 265 | + if ((controlNode = this._parseUpon())) return controlNode; |
264 | 266 | }; |
265 | 267 |
|
266 | 268 | Parser.prototype._parseFunction = function() { |
@@ -361,6 +363,23 @@ Parser.prototype._parseRepeat = function() { |
361 | 363 | return repeatNode; |
362 | 364 | }; |
363 | 365 |
|
| 366 | +Parser.prototype._parseUpon = function() { |
| 367 | + if (!this._lexer.accept('func', 'upon')) return null; |
| 368 | + |
| 369 | + var uponNode = new ParseNode('upon'); |
| 370 | + |
| 371 | + // { <cond> } <block> |
| 372 | + this._lexer.expect('open'); |
| 373 | + uponNode.addChild(this._parseCond()); |
| 374 | + this._lexer.expect('close'); |
| 375 | + uponNode.addChild(this._parseBlock()); |
| 376 | + |
| 377 | + // \ENDUPON |
| 378 | + this._lexer.expect('func', 'endupon'); |
| 379 | + |
| 380 | + return uponNode; |
| 381 | +}; |
| 382 | + |
364 | 383 | var IO_STATEMENTS = ['ensure', 'require', 'input', 'output']; |
365 | 384 | var STATEMENTS = ['state', 'print', 'return']; |
366 | 385 | Parser.prototype._parseStatement = function(acceptStatements) { |
|
0 commit comments