Skip to content

Instantly share code, notes, and snippets.

@besquared
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save besquared/11751660c97962d2ee55 to your computer and use it in GitHub Desktop.
Save besquared/11751660c97962d2ee55 to your computer and use it in GitHub Desktop.
# Match [ [1,2,3], [4,5,6], ... ]
class Matrix
constructor(@rows) -> null
Matrix: [
o 'LEFT_BRACKET (MatrixRow)+ RIGHT_BRACKET', ->
new Matrix($2)
]
MatrixRow: [
o 'COMMA MatrixRow', -> $2
o 'LEFT_BRACKET (MatrixRowItem)+ RIGHT_BRACKET', -> $2
]
MatrixRowElement: [
o 'NUMBER', -> $1
o 'COMMA NUMBER', -> $2
]
@besquared
Copy link
Author

I guess technically you could simplify the matrix rule to 'LEFT_BRACKET (MatrixRow)+ RIGHT_BRACKET'

@RubenVerborgh
Copy link

Note that matrices like [, , , , , [, 2, 3] ] are also matched, which might or might not be desired.

@RubenVerborgh
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment