Skip to content

Commit

Permalink
basic recursive parser
Browse files Browse the repository at this point in the history
  • Loading branch information
StoneCypher committed May 21, 2017
1 parent 18d4cf2 commit 21600eb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -37,3 +37,5 @@ jspm_packages
.node_repl_history

build/

.DS_Store
42 changes: 42 additions & 0 deletions src/js/jssm-dot.peg
@@ -0,0 +1,42 @@
/*
* Simple Arithmetics Grammar
* ==========================
*
* Accepts expressions like "2 * (3 + 4)" and computes their value.
*/

Expression
= Whitespace ExpList Whitespace

Integer "integer"
= [0-9]+ { return parseInt(text(), 10); }

ForwardArrow "forward arrow"
= "->"

TwoWayArrow "two way arrow"
= "<->"

Arrow
= ForwardArrow / TwoWayArrow

Label "label"
= [0-9a-zA-Z]+

Subexp
= Whitespace arrow:Arrow Whitespace label:Label Whitespace tail:Subexp* { return {kind: arrow, to: label, se:(tail === [])? undefined : tail}; }

Exp
= label:Label se:Subexp Whitespace ';' Whitespace {
const unroll = function(dive) { return true; }
return {from: label, se:(se === [])? undefined : se};
}

SubexpItem
= Subexp

ExpList
= exp:Exp*

Whitespace "whitespace"
= [ \t\n\r\v]*

0 comments on commit 21600eb

Please sign in to comment.