diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-03 00:52:01 -0800 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-01-03 00:52:01 -0800 |
| commit | cfee75b21b307b5d57c215cad5b1c089c91182fc (patch) | |
| tree | e6d605892aced717a4519f7860c0b143d11819a6 /nomsu.peg | |
| parent | 3bd12b5331f7e5ec939cb8130350ea68fcbd6ceb (diff) | |
Reworked {} a bit and added dicts to the core language. Did some more
testing on string interpolations too.
Diffstat (limited to 'nomsu.peg')
| -rw-r--r-- | nomsu.peg | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -15,10 +15,10 @@ statement: functioncall / expression noeol_statement: noeol_functioncall / noeol_expression inline_statement: inline_functioncall / inline_expression -inline_thunk (Thunk): {| "{" %ws* inline_statements %ws* "}" |} +inline_thunk (Thunk): {| "(" %ws* ":" %ws* inline_statements %ws* ")" |} eol_thunk (Thunk): {| ":" %ws* noeol_statements eol |} indented_thunk (Thunk): - {| (":" / "{..}") indent + {| ":" indent statements (nodent statements)* (dedent / (("" -> "Error while parsing thunk") => error)) |} @@ -28,10 +28,10 @@ eol_nomsu (Nomsu): "\" noeol_expression indented_nomsu (Nomsu): "\" expression inline_expression: - number / variable / inline_string / inline_list / inline_nomsu + number / variable / inline_string / inline_list / inline_dict / inline_nomsu / inline_thunk / ("(" %ws* inline_statement %ws* ")") noeol_expression: - indented_string / indented_nomsu / indented_list / indented_thunk + indented_string / indented_nomsu / indented_list / indented_dict / indented_thunk / ("(..)" indent statement (dedent / (("" -> "Error while parsing indented expression") => error)) @@ -55,10 +55,13 @@ inline_string (String): |} '"' indented_string (String): '".."' %ws* line_comment? %nl %gt_nodented? {| - ({~ (("\\" -> "\") / (%nl+ {~ %gt_nodented -> "" ~}) / [^%nl\])+ ~} / string_interpolation)* + ({~ + (("\\" -> "\") / (("\" eol %nl %gt_nodented "..") -> "") + / (%nl+ {~ %gt_nodented -> "" ~}) / [^%nl\])+ + ~} / string_interpolation)* |} ((!.) / (&(%nl+ !%gt_nodented)) / (("" -> "Error while parsing String") => error)) - -string_interpolation: "\" ((noeol_expression dotdot?) / dotdot) +string_interpolation: + "\" (variable / inline_list / inline_dict / inline_thunk / ("(" %ws* inline_statement %ws* ")")) number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / ([0-9]+)))-> tonumber) @@ -78,6 +81,19 @@ list_line: / (functioncall / expression) inline_list_item: inline_functioncall / inline_expression +inline_dict (Dict): + "{" %ws* {| (inline_dict_item (comma inline_dict_item)* comma?)? |} %ws* "}" +indented_dict (Dict): + "{..}" indent {| + dict_line (nodent dict_line)* + |} + (dedent / (("" -> "Error while parsing dict") => error)) +dict_line: + (inline_dict_item (comma inline_dict_item)* (comma (functioncall / expression)?)?) + / {| {:dict_key: inline_expression / word :} %ws* "=" %ws* {:dict_value: functioncall / expression :} |} +inline_dict_item: + {| {:dict_key: inline_expression / word :} %ws* "=" %ws* {:dict_value: inline_functioncall / inline_expression :} |} + block_comment: "#.." [^%nl]* (%nl (%ws* &%nl))* %nl %indented [^%nl]+ (%nl ((%ws* ((!.) / &%nl)) / (!%dedented [^%nl]+)))* line_comment: "#" [^%nl]* |
