Skip to content

Instantly share code, notes, and snippets.

@bvssvni
Last active August 29, 2015 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bvssvni/18aa2ebac87081cafdd0 to your computer and use it in GitHub Desktop.
Save bvssvni/18aa2ebac87081cafdd0 to your computer and use it in GitHub Desktop.
Notation for reasoning about parsing - described in its own notation
whitespace { optional }:
whitespace?
token("whitespace")
select(
token("?") as optional
token("!") as !optional
)
whitespace?
parameter { name, args, value }:
whitespace?
until_whitespace_or_any("{") as name
whitespace?
token("{")
whitespace?
while(!token("}"))
whitespace?
until_whitespace_or_any(",").push_to(args)
whitespace?
?(
whitespace!
token("as")
whitespace!
until_whitespace as value
)
whitespace?
token(":")
whitespace?
new_line
select(
tab_indent
point_to(parameter, "This parameter lacks a body")
)
token { text_value, inverted, predicate }:
token("token")
whitespace?
token("(")
whitespace?
text as text_value
whitespace?
token(")")
?(
whitespace!
token("as")
whitespace!
token("!") as inverted
until_whitespace as predicate
)
whitespace?
select { args }:
whitespace?
token("select")
whitespace?
token("(")
new_line
while(!token(")"))
whitespace?
whole_line.push_to(args)
new_line
optional { args }:
whitespace?
token("?")
whitespace?
token("(")
new_line
while(!token(")"))
whitespace?
whole_line.push_to(args)
new_line
until_whitespace { predicate }:
whitespace?
token("until_whitespace")
?(
whitespace!
token("as")
whitespace!
until_whitespace as predicate
)
whitespace?
until_whitespace_or_any { text_value, predicate, push_value }:
whitespace?
token("until_whitespace_or_any")
whitespace?
token("(")
whitespace?
text as text_value
whitespace?
token(")")
select(
predicate { value } as predicate:
whitespace!
token("as")
whitespace!
until_whitespace as value
push_value { value } as push_value:
token(".push_to")
whitespace?
token("(")
whitespace?
until_whitespace as value
whitespace?
token(")")
)
whitespace?
new_line { }:
whitespace?
token("new_line")
whitespace?
tab_indent { }:
whitespace?
token("tab_indent")
whitespace?
point_to { part, error_message }:
whitespace?
token("point_to")
whitespace?
token("(")
until_whitespace_or_any(",") as part
whitespace?
token(",")
whitespace?
text as error_message
whitespace?
token(")")
whitespace?
text { value }:
whitespace?
token("text")
whitespace!
token("as")
whitespace!
until_whitespace as value
whitespace?
while { end_token }:
whitespace?
token("while")
whitespace?
token("(")
whitespace?
token("!token")
whitespace?
token("(")
whitespace?
text as end_token
whitespace?
token(")")
whitespace?
new_line
select(
tab_indent
point_to(while, "This while block lacks a body")
)
whole_line { push_value }:
whitespace?
token("whole_line.push_to")
whitespace?
token("(")
whitespace?
until_whitespace as push_value
whitespace?
token(")")
whitespace?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment