cleaned up command expressions
This commit is contained in:
parent
7196c7637e
commit
c30f6cfcf1
4 changed files with 29 additions and 18 deletions
|
|
@ -642,8 +642,7 @@ proc primarySuffix(p: var TParser, r: PNode): PNode =
|
||||||
#| | '.' optInd ('type' | 'addr' | symbol) generalizedLit?
|
#| | '.' optInd ('type' | 'addr' | symbol) generalizedLit?
|
||||||
#| | '[' optInd indexExprList optPar ']'
|
#| | '[' optInd indexExprList optPar ']'
|
||||||
#| | '{' optInd indexExprList optPar '}'
|
#| | '{' optInd indexExprList optPar '}'
|
||||||
#| | &( '`'|IDENT|literal|'cast') expr ^+ ',' # command syntax
|
#| | &( '`'|IDENT|literal|'cast') expr # command syntax
|
||||||
#| (doBlock | macroColon)?
|
|
||||||
result = r
|
result = r
|
||||||
while p.tok.indent < 0:
|
while p.tok.indent < 0:
|
||||||
case p.tok.tokType
|
case p.tok.tokType
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,7 @@ primarySuffix = '(' (exprColonEqExpr comma?)* ')' doBlocks?
|
||||||
| '.' optInd ('type' | 'addr' | symbol) generalizedLit?
|
| '.' optInd ('type' | 'addr' | symbol) generalizedLit?
|
||||||
| '[' optInd indexExprList optPar ']'
|
| '[' optInd indexExprList optPar ']'
|
||||||
| '{' optInd indexExprList optPar '}'
|
| '{' optInd indexExprList optPar '}'
|
||||||
| &( '`'|IDENT|literal|'cast') expr ^+ ',' # command syntax
|
| &( '`'|IDENT|literal|'cast') expr # command syntax
|
||||||
(doBlock | macroColon)?
|
|
||||||
condExpr = expr colcom expr optInd
|
condExpr = expr colcom expr optInd
|
||||||
('elif' expr colcom expr optInd)*
|
('elif' expr colcom expr optInd)*
|
||||||
'else' colcom expr
|
'else' colcom expr
|
||||||
|
|
|
||||||
|
|
@ -1315,12 +1315,9 @@ Examples:
|
||||||
|
|
||||||
.. code-block:: nimrod
|
.. code-block:: nimrod
|
||||||
|
|
||||||
type
|
proc printItem(x: int) = ...
|
||||||
TCallback = proc (x: int) {.cdecl.}
|
|
||||||
|
|
||||||
proc printItem(x: Int) = ...
|
proc forEach(c: proc (x: int) {.cdecl.}) =
|
||||||
|
|
||||||
proc forEach(c: TCallback) =
|
|
||||||
...
|
...
|
||||||
|
|
||||||
forEach(printItem) # this will NOT work because calling conventions differ
|
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))
|
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
|
Closures
|
||||||
--------
|
--------
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,17 @@
|
||||||
discard """
|
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: int): int = x-1
|
||||||
proc foo(x, y: int): int = x-y
|
proc foo(x, y: int): int = x-y
|
||||||
|
|
||||||
let x = foo 7.foo, # comment here
|
let x = optarg foo 7.foo
|
||||||
foo(1, foo 8)
|
let y = singlearg foo(1, foo 8)
|
||||||
# 12 = 6 - -6
|
|
||||||
echo x
|
|
||||||
|
|
||||||
|
echo x, y
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue