Removed semicolons and compound statements, added support for (foo: a b)
style syntax for thunks that continue till the end of paren groups.
This commit is contained in:
parent
2df539a762
commit
a4c8e5ce65
21
nomsu.peg
21
nomsu.peg
@ -1,25 +1,21 @@
|
|||||||
file (File):
|
file (File):
|
||||||
{| shebang?
|
{| shebang?
|
||||||
(ignored_line %nl)*
|
(ignored_line %nl)*
|
||||||
statements (nodent statements)*
|
statement (nodent statement)*
|
||||||
(%nl ignored_line)*
|
(%nl ignored_line)*
|
||||||
(!. / (("" -> "Parse error") => error)?) |}
|
(!. / (("" -> "Parse error") => error)?) |}
|
||||||
|
|
||||||
shebang: "#!" [^%nl]* %nl
|
shebang: "#!" [^%nl]* %nl
|
||||||
|
|
||||||
inline_statements: inline_statement (semicolon inline_statement)*
|
|
||||||
noeol_statements: (inline_statement semicolon noeol_statements) / noeol_statement
|
|
||||||
statements: (inline_statement semicolon statements) / statement
|
|
||||||
|
|
||||||
statement: functioncall / expression
|
statement: functioncall / expression
|
||||||
noeol_statement: noeol_functioncall / noeol_expression
|
noeol_statement: noeol_functioncall / noeol_expression
|
||||||
inline_statement: inline_functioncall / inline_expression
|
inline_statement: inline_functioncall / inline_expression
|
||||||
|
|
||||||
inline_thunk (Thunk): {| "(" %ws* ":" %ws* inline_statements %ws* ")" |}
|
inline_thunk (Thunk): {| ":" %ws* inline_statement |}
|
||||||
eol_thunk (Thunk): {| ":" %ws* noeol_statements eol |}
|
eol_thunk (Thunk): {| ":" %ws* noeol_statement eol |}
|
||||||
indented_thunk (Thunk):
|
indented_thunk (Thunk):
|
||||||
{| ":" indent
|
{| ":" indent
|
||||||
statements (nodent statements)*
|
statement (nodent statement)*
|
||||||
(dedent / (("" -> "Error while parsing thunk") => error))
|
(dedent / (("" -> "Error while parsing thunk") => error))
|
||||||
|}
|
|}
|
||||||
|
|
||||||
@ -29,7 +25,7 @@ indented_nomsu (Nomsu): "\" expression
|
|||||||
|
|
||||||
inline_expression:
|
inline_expression:
|
||||||
number / variable / inline_string / inline_list / inline_dict / inline_nomsu
|
number / variable / inline_string / inline_list / inline_dict / inline_nomsu
|
||||||
/ inline_thunk / ("(" %ws* inline_statement %ws* ")")
|
/ ("(" %ws* (inline_thunk / inline_statement) %ws* ")")
|
||||||
noeol_expression:
|
noeol_expression:
|
||||||
indented_string / indented_nomsu / indented_list / indented_dict / indented_thunk
|
indented_string / indented_nomsu / indented_list / indented_dict / indented_thunk
|
||||||
/ ("(..)" indent
|
/ ("(..)" indent
|
||||||
@ -40,7 +36,7 @@ expression: eol_thunk / eol_nomsu / noeol_expression
|
|||||||
|
|
||||||
-- Function calls need at least one word in them
|
-- Function calls need at least one word in them
|
||||||
inline_functioncall (FunctionCall):
|
inline_functioncall (FunctionCall):
|
||||||
{| (inline_expression %ws*)* word (%ws* (inline_expression / word))* |}
|
{| (inline_expression %ws*)* word (%ws* (inline_expression / word))* (%ws* inline_thunk)?|}
|
||||||
noeol_functioncall (FunctionCall):
|
noeol_functioncall (FunctionCall):
|
||||||
{| (noeol_expression %ws*)* word (%ws* (noeol_expression / word))* |}
|
{| (noeol_expression %ws*)* word (%ws* (noeol_expression / word))* |}
|
||||||
functioncall (FunctionCall):
|
functioncall (FunctionCall):
|
||||||
@ -50,7 +46,7 @@ word (Word): { %operator / (!number plain_word) }
|
|||||||
|
|
||||||
inline_string (String):
|
inline_string (String):
|
||||||
'"' {|
|
'"' {|
|
||||||
({~ (('\"' -> '"') / ('\\' -> '\') / %escape_char / [^%nl\"])+ ~}
|
({~ (('\"' -> '"') / ('\\' -> '\') / ('\..' -> '..') / %escape_char / [^%nl\"])+ ~}
|
||||||
/ string_interpolation)*
|
/ string_interpolation)*
|
||||||
|} '"'
|
|} '"'
|
||||||
indented_string (String):
|
indented_string (String):
|
||||||
@ -61,7 +57,7 @@ indented_string (String):
|
|||||||
~} / string_interpolation)*
|
~} / string_interpolation)*
|
||||||
|} ((!.) / (&(%nl+ !%gt_nodented)) / (("" -> "Error while parsing String") => error))
|
|} ((!.) / (&(%nl+ !%gt_nodented)) / (("" -> "Error while parsing String") => error))
|
||||||
string_interpolation:
|
string_interpolation:
|
||||||
"\" (variable / inline_list / inline_dict / inline_thunk / ("(" %ws* inline_statement %ws* ")"))
|
"\" (variable / inline_list / inline_dict / inline_string / ("(" %ws* (inline_thunk / inline_statement) %ws* ")"))
|
||||||
|
|
||||||
number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / ([0-9]+)))-> tonumber)
|
number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / ([0-9]+)))-> tonumber)
|
||||||
|
|
||||||
@ -103,6 +99,5 @@ indent: eol (%nl ignored_line)* %nl %indented ((block_comment/line_comment) (%nl
|
|||||||
nodent: eol (%nl ignored_line)* %nl %nodented
|
nodent: eol (%nl ignored_line)* %nl %nodented
|
||||||
dedent: eol (%nl ignored_line)* (((!.) &%dedented) / (&(%nl %dedented)))
|
dedent: eol (%nl ignored_line)* (((!.) &%dedented) / (&(%nl %dedented)))
|
||||||
comma: %ws* "," %ws*
|
comma: %ws* "," %ws*
|
||||||
semicolon: %ws* ";" %ws*
|
|
||||||
dotdot: nodent ".." %ws*
|
dotdot: nodent ".." %ws*
|
||||||
plain_word: ([a-zA-Z0-9_] / %utf8_char)+
|
plain_word: ([a-zA-Z0-9_] / %utf8_char)+
|
||||||
|
Loading…
Reference in New Issue
Block a user