Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@seancribbs
Created May 10, 2009 01:40
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 seancribbs/109469 to your computer and use it in GitHub Desktop.
Save seancribbs/109469 to your computer and use it in GitHub Desktop.
rules <- space? declaration_sequence space?
declaration_sequence <- head:declaration tail:(space declaration)*
declaration <- nonterminal space '<-' space parsing_expression
parsing_expression <- choice / sequence / primary
choice <- head:alternative tail:(space? '/' space? alternative)+
sequence <- head:labeled_sequence_primary tail:(space labeled_sequence_primary)+
alternate <- sequence / primary
primary <- prefix atomic / atomic suffix / atomic
labeled_sequence_primary <- label sequence_primary
label <- (alpha_char alphanumeric_char*) ':' / ''
sequence_primary <- prefix atomic / atomic suffix / atomic
suffix <- repetition_suffix / optional_suffix
optional_suffix <- '?'
repetition_suffix <- '+' / '*'
prefix <- '&' / '!' / '~'
atomic <- terminal / nonterminal / parenthesized_expression
parenthesized_expression <- '(' space? parsing_expression space? ')'
nonterminal <- !keyword_inside_grammar (alpha_char alphanumeric_char*)
terminal <- quoted_string / character_class / anything_symbol
quoted_string <- (single_quoted_string / double_quoted_string)
double_quoted_string <- '"' string:(!'"' ("\\\\" / '\"' / .))* '"'
single_quoted_string <- "'" string:(!"'" ("\\\\" / "\\'" / .))* "'"
character_class <- '[' characters:(!']' ('\\' . /!'\\' .))+ ']'
anything_symbol <- '.'
non_space_char <- !space .
alpha_char <- [A-Za-z_]
alphanumeric_char <- alpha_char / [0-9]
space <- (white / comment_to_eol)+
comment_to_eol <- '#' (!"\\n" .)*
white <- [ \t\n\r]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment