Parser of Cirru Grammer
Cirru is an indentation-based grammar. You may use it to create your own DSLs or scripting languages.
You may also find another implementation written in Go.
npm install --save cirru-parser
require 'cirru-parser'syntaxTree = parse codefilenamesimplifiedTree = pare codefilenameinfo = caution char
code in Cirru grammar,
filename is optional:
A token in
syntaxTree is like:
token =text: 'get'x: 0y: 0ex: 1ey: 1path: 'a.cirru'
And expressions here are just tokens in arrays, like:
pare is short for
filename is optional.
simplifiedTree does not contain informations of files,
like line numbers, file content, which are needed in
A token from
pare is a string, i.e. the
text field of parsing results.
Demo: http://repo.cirru.org/parser/ .
By typing on the left you should see the
pare results on the right.
For short, there are then rules of Cirru:
- It indents with 2 spaces
- Parentheses are closed in the same line it opened
- Strings are quoted with double quotes:
$folds followed tokens in an expression
,unfolds followed tokens in an expression
Here's a Gist showing how it's parsed(not including the steps solving
Also you may debug
index.html in a browser after compiling the code:
npm igulp start# view generated index.html in a web server
- switch to
- Rewritten with new solution from Go
- drop caution