Skip to content

Instantly share code, notes, and snippets.

@vendethiel
Last active December 28, 2015 12:59
Show Gist options
  • Save vendethiel/7504300 to your computer and use it in GitHub Desktop.
Save vendethiel/7504300 to your computer and use it in GitHub Desktop.
ForBody: [
o 'FOR Range ForExtra', -> extend {source: LOC(2) new Value($2)}, $3
o 'ForStart ForSource ForExtra', ->
$2.own = $1.own; $2.name = $1[0]; $2.index = $1[1]
extend $2, $3
]
ForStart: [
o 'FOR ForVariables', -> $2
o 'FOR OWN ForVariables', -> $3.own = yes; $3
]
# An array of all accepted values for a variable inside the loop.
# This enables support for pattern matching.
ForValue: [
o 'Identifier'
o 'ThisProperty'
o 'Array', -> new Value $1
o 'Object', -> new Value $1
]
# An array or range comprehension has variables for the current element
# and (optional) reference to the current index. Or, *key, value*, in the case
# of object comprehensions.
ForVariables: [
o 'ForValue', -> [$1]
o 'ForValue , ForValue', -> [$1, $3]
]
# The source of a comprehension is an array or object with an optional guard
# clause. If it's an array comprehension, you can also choose to step through
# in fixed-size increments.
ForSource: [
o 'FORIN Expression', -> source: $2
o 'FOROF Expression', -> source: $2, object: yes
]
ForExtra: [
o '', -> {}
o 'BY Expression', -> step: $2
o 'WHEN Expression', -> guard: $2
o 'BY Expression WHEN EXPRESSION', -> step: $2, guard: $4
o 'WHEN Expression BY EXPRESSION', -> guard: $2, step: $4
]
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment