diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-30 15:10:37 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-30 15:11:18 -0800 |
| commit | 056357162551993e3e7d3a0ac778ed46aafdc083 (patch) | |
| tree | 1ef81cd3df6b1125e65d514f22fc4396bd99ec76 /nomsu.peg | |
| parent | d7abcba34db025876ad1922a71c8cba2449b867f (diff) | |
Overhaul of indentations. Now strictly requiring exactly 4 spaces
everywhere, and supporting indented string interpolations.
Diffstat (limited to 'nomsu.peg')
| -rw-r--r-- | nomsu.peg | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -10,7 +10,7 @@ shebang: "#!" [^%nl]* %nl statement: functioncall / expression indented_block (Block): - {| indent + {| ("(..)")? indent statement (nodent statement)* (dedent / (("" -> "Error while parsing block") => error)) |} @@ -36,20 +36,28 @@ functioncall (FunctionCall): word (Word): { %operator / (!number plain_word) } inline_text (Text): - !('".."' %ws* line_comment? %nl (%ws* %nl)* %gt_nodent) + !('".."' eol) '"' {| ({~ (('\"' -> '"') / ('\\' -> '\') / %escaped_char / [^%nl\"])+ ~} / text_interpolation)* |} '"' +-- Have to use "%indent" instead of "indent" etc. to avoid messing up text lines that start with "#" indented_text (Text): - '".."' %ws* line_comment? %nl %gt_nodent? {| + '".."' eol %nl {| + {~ (%nl*) (%indent -> "") ~} ({~ - (("\\" -> "\") / (("\" eol %nl %gt_nodent "..") -> "") - / (%nl+ {~ %gt_nodent -> "" ~}) / [^%nl\])+ + (("\\" -> "\") / (("\" eol %nl+ %nodent "..") -> "") + / (%nl+ {~ %nodent -> "" ~}) / [^%nl\])+ ~} / text_interpolation)* - |} ((!.) / (&(%nl+ !%gt_nodent)) / (("" -> "Error while parsing Text") => error)) + |} (((!.) &%dedent) / (&(%nl %dedent)) / (("" -> "Error while parsing Text") => error)) text_interpolation: - "\" (variable / inline_list / inline_dict / inline_text / ("(" %ws* (inline_functioncall / inline_expression) %ws* ")")) + "\" ( + variable / inline_list / inline_dict / inline_text + / ("(" %ws* (inline_functioncall / inline_expression) %ws* ")") + / (%ws* (block_comment / line_comment)? nodent "..") + / (indented_text %nl+ %nodent "..") + / ((indented_list / indented_block) nodent "..") + ) number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / ([0-9]+)))-> tonumber) @@ -84,7 +92,7 @@ dict_line: inline_dict_item: {| {:dict_key: inline_expression / word :} %ws* ":" %ws* {:dict_value: inline_functioncall / inline_expression :} |} -block_comment(Comment): "#.." { [^%nl]* (%nl %gt_nodent [^%nl]*)* } +block_comment(Comment): "#.." { [^%nl]* (%nl+ %indent [^%nl]* (%nl+ %nodent [^%nl]*)* %dedent)? } line_comment(Comment): "#" { [^%nl]* } eol: %ws* line_comment? (!. / &%nl) |
