diff options
author | Araq <rumpf_a@web.de> | 2014-02-02 14:34:37 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-02-02 14:34:37 +0100 |
commit | c30f6cfcf11cf5e61d708db476d7a6fcb62aab23 (patch) | |
tree | aa661e3fb6da6bdc03199448c7e2adc5a03783af | |
parent | 7196c7637e00581f94ca9c02782f34ef7d480e2f (diff) | |
download | Nim-c30f6cfcf11cf5e61d708db476d7a6fcb62aab23.tar.gz |
cleaned up command expressions
-rw-r--r-- | compiler/parser.nim | 11 | ||||
-rw-r--r-- | doc/grammar.txt | 3 | ||||
-rw-r--r-- | doc/manual.txt | 18 | ||||
-rw-r--r-- | tests/parser/tcommand_as_expr.nim | 15 |
4 files changed, 29 insertions, 18 deletions
diff --git a/compiler/parser.nim b/compiler/parser.nim index 4497e360a..7c740559c 100644 --- a/compiler/parser.nim +++ b/compiler/parser.nim @@ -642,8 +642,7 @@ proc primarySuffix(p: var TParser, r: PNode): PNode = #| | '.' optInd ('type' | 'addr' | symbol) generalizedLit? #| | '[' optInd indexExprList optPar ']' #| | '{' optInd indexExprList optPar '}' - #| | &( '`'|IDENT|literal|'cast') expr ^+ ',' # command syntax - #| (doBlock | macroColon)? + #| | &( '`'|IDENT|literal|'cast') expr # command syntax result = r while p.tok.indent < 0: case p.tok.tokType @@ -680,10 +679,10 @@ proc primarySuffix(p: var TParser, r: PNode): PNode = if p.tok.tokType != tkComma: break getTok(p) optInd(p, a) - if p.tok.tokType == tkDo: - parseDoBlocks(p, result) - else: - result = parseMacroColon(p, result) + if p.tok.tokType == tkDo: + parseDoBlocks(p, result) + else: + result = parseMacroColon(p, result) break else: break diff --git a/doc/grammar.txt b/doc/grammar.txt index 54c2217d8..63e898e11 100644 --- a/doc/grammar.txt +++ b/doc/grammar.txt @@ -59,8 +59,7 @@ primarySuffix = '(' (exprColonEqExpr comma?)* ')' doBlocks? | '.' optInd ('type' | 'addr' | symbol) generalizedLit? | '[' optInd indexExprList optPar ']' | '{' optInd indexExprList optPar '}' - | &( '`'|IDENT|literal|'cast') expr ^+ ',' # command syntax - (doBlock | macroColon)? + | &( '`'|IDENT|literal|'cast') expr # command syntax condExpr = expr colcom expr optInd ('elif' expr colcom expr optInd)* 'else' colcom expr diff --git a/doc/manual.txt b/doc/manual.txt index baa0f3366..2ccd4c1e9 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -1315,12 +1315,9 @@ Examples: .. code-block:: nimrod - type - TCallback = proc (x: int) {.cdecl.} - - proc printItem(x: Int) = ... + proc printItem(x: int) = ... - proc forEach(c: TCallback) = + proc forEach(c: proc (x: int) {.cdecl.}) = ... forEach(printItem) # this will NOT work because calling conventions differ @@ -2459,6 +2456,17 @@ notation. (Thus an operator can have more than two parameters): assert `*+`(3, 4, 6) == `*`(a, `+`(b, c)) + +Command invocation syntax +------------------------- + +Routines can be invoked without the ``()`` if the call is syntactially +a statement. This `command invocation syntax`:idx: also works for +expressions, but then only a single argument may follow. This restriction +means ``echo f 1, f 2`` is parsed as ``echo(f(1), f(2))`` and not as +``echo(f(1, f(2)))``. + + Closures -------- diff --git a/tests/parser/tcommand_as_expr.nim b/tests/parser/tcommand_as_expr.nim index f6868a2fc..a9747b0ac 100644 --- a/tests/parser/tcommand_as_expr.nim +++ b/tests/parser/tcommand_as_expr.nim @@ -1,12 +1,17 @@ discard """ - output: "12" + output: '''140 +5-120''' """ +proc optarg(x:int):int = x +proc singlearg(x:int):int = 20*x +echo optarg 1, singlearg 2 + + proc foo(x: int): int = x-1 proc foo(x, y: int): int = x-y -let x = foo 7.foo, # comment here - foo(1, foo 8) -# 12 = 6 - -6 -echo x +let x = optarg foo 7.foo +let y = singlearg foo(1, foo 8) +echo x, y |