diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-16 18:12:56 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-05-16 18:13:02 -0700 |
| commit | 6f6c4377b236902566794c3d06820f3fdd7ec28c (patch) | |
| tree | a3074d4d7c46585a9ece036455ff97b9ab12effc /nomsu.peg | |
| parent | af9dc0702568dc45b8809523dde760bb99aafbcb (diff) | |
Initial working version.
Diffstat (limited to 'nomsu.peg')
| -rw-r--r-- | nomsu.peg | 42 |
1 files changed, 19 insertions, 23 deletions
@@ -11,18 +11,16 @@ statement: (action / expression) (eol / (({} ([^%nl]* -> "Error while parsing li inline_statement: inline_action / inline_expression inline_block (Block): - {| inline_statement (%ws* ";" %ws* inline_statement)+ |} -> Tuple + inline_statement (%ws* ";" %ws* inline_statement)+ block (Block): - {| statement (nodent (statement / (({} ([^%nl]* -> "Error while parsing block line")) => error)))+ |} -> Tuple + statement (nodent (statement / (({} ([^%nl]* -> "Error while parsing block line")) => error)))+ -inline_nomsu (Nomsu): "\" noindex_inline_expression -indented_nomsu (Nomsu): +inline_nomsu (EscapedNomsu): "\" noindex_inline_expression +indented_nomsu (EscapedNomsu): "\" (noindex_inline_expression / (":" %ws* (inline_block / inline_action / inline_expression) eol) / indented_expression) index_chain (IndexChain): - {| - noindex_inline_expression ("." (text_word / noindex_inline_expression))+ - |} -> Tuple + noindex_inline_expression ("." (text_word / noindex_inline_expression))+ noindex_inline_expression: number / variable / inline_text / inline_list / inline_dict / inline_nomsu @@ -47,30 +45,30 @@ expression: -- Function calls need at least one word in them inline_action (Action): - {| (inline_expression %ws*)* word (%ws* (inline_expression / word))* - (%ws* ":" %ws* (inline_block / inline_action / inline_expression))?|} -> Tuple + (inline_expression %ws*)* word (%ws* (inline_expression / word))* + (%ws* ":" %ws* (inline_block / inline_action / inline_expression))? action (Action): - {| (expression (dotdot? %ws*))* word ((dotdot? %ws*) (expression / word))* |} -> Tuple + (expression (dotdot? %ws*))* word ((dotdot? %ws*) (expression / word))* word (Word): { %operator / (!number plain_word) } -text_word (Text): {| {%operator / (!number plain_word)} |} -> Tuple +text_word (Text): {%operator / (!number plain_word)} inline_text (Text): !('".."' eol) - '"' ({| + '"' ( ({~ (('\"' -> '"') / ('\\' -> '\') / %escaped_char / [^%nl\"])+ ~} / inline_text_interpolation)* - |} -> Tuple) ('"' / (({} ([^%nl]*->'Failed to find a closing " mark on the same line')) => error)) + ) ('"' / (({} ([^%nl]*->'Failed to find a closing " mark on the same line')) => error)) -- Have to use "%indent" instead of "indent" etc. to avoid messing up text lines that start with "#" indented_text (Text): - '".."' eol %nl ({| + '".."' eol %nl ( {~ (%nl*) (%indent -> "") ~} ({~ (("\\" -> "\") / (("\" nodent "..") -> "")/ (%nl+ {~ %nodent -> "" ~}) / [^%nl\] / (!text_interpolation "\"))+ ~} / text_interpolation)* - |} -> Tuple) (((!.) &%dedent) / (&(%nl %dedent)) / (({} (non_dedent_error -> "Error while parsing Text")) => error)) + ) (((!.) &%dedent) / (&(%nl %dedent)) / (({} (non_dedent_error -> "Error while parsing Text")) => error)) inline_text_interpolation: "\" ( variable / inline_list / inline_dict / inline_text @@ -93,12 +91,11 @@ variable (Var): "%" { plain_word? } inline_list (List): !('[..]') - "[" %ws* ({| (inline_list_item (comma inline_list_item)* comma?)? |} -> Tuple) %ws* + "[" %ws* (inline_list_item (comma inline_list_item)* comma?)? %ws* ("]" / (({} ([^%nl]*->"Failed to find a closing ] on the same line")) => error)) indented_list (List): - "[..]" indent ({| + "[..]" indent list_line (nodent list_line)* - |} -> Tuple) (dedent / (({} (non_dedent_error -> "Error while parsing list")) => error)) list_line: ((action / expression) !comma) @@ -107,21 +104,20 @@ inline_list_item: inline_block / inline_action / inline_expression inline_dict (Dict): !('{..}') - "{" %ws* ({| (inline_dict_entry (comma inline_dict_entry)*)? |} -> Tuple) %ws* + "{" %ws* (inline_dict_entry (comma inline_dict_entry)*)? %ws* ("}" / (({} (%ws* comma? (!. / &%nl)->"Failed to find a closing } on the same line")) => error) / (({} ([^%nl]*->"Error while parsing dictionary")) => error)) indented_dict (Dict): - "{..}" indent ({| + "{..}" indent dict_line (nodent dict_line)* - |} -> Tuple) (dedent / (({} (non_dedent_error -> "Error while parsing dict")) => error)) dict_line: (dict_entry !comma) / (inline_dict_entry (comma dict_line?)?) dict_entry(DictEntry): - {| dict_key %ws* ":" %ws* (action / expression) |} -> Tuple + dict_key %ws* ":" %ws* (action / expression) inline_dict_entry(DictEntry): - {| dict_key %ws* (":" %ws* (inline_block / inline_action / inline_expression)?) |} -> Tuple + dict_key %ws* (":" %ws* (inline_block / inline_action / inline_expression)?) dict_key: text_word / inline_expression |
