adding the notion of existence -- postfixing an expression with a question mark will check if to see if it's not null or undefined

This commit is contained in:
Jeremy Ashkenas
2010-01-01 12:31:05 -05:00
parent 3489eec6ee
commit ff80f8d423
2 changed files with 19 additions and 1 deletions

View File

@@ -19,7 +19,7 @@ token INDENT OUTDENT
# Declare order of operations.
prechigh
nonassoc UMINUS SPLAT NOT '!' '!!' '~' '++' '--'
nonassoc UMINUS SPLAT NOT '!' '!!' '~' '++' '--' '?'
left '*' '/' '%'
left '+' '-'
left '<<' '>>' '>>>'
@@ -72,6 +72,7 @@ rule
| Switch
| Extends
| Splat
| Existence
| Comment
;
@@ -181,6 +182,10 @@ rule
| Expression INSTANCEOF Expression { result = OpNode.new(val[1], val[0], val[2]) }
;
Existence:
Expression '?' { result = ExistenceNode.new(val[0]) }
;
# Function definition.
Code:
ParamList "=>" Block { result = CodeNode.new(val[0], val[2]) }