diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-30 13:47:40 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-30 13:47:40 -0700 |
| commit | aafce3a76584d16950a19f81d8f62ca5c4bb1dca (patch) | |
| tree | b7d403646486aa120541de6463b297e269000beb | |
| parent | f6e9bdc1c021552b4c52d427a54cb71a4ff8e2ac (diff) | |
Fix for parsing empty files, adding hex number literals (0xdeadbeef),
and fix for long strings ending with an indented interpolation.
| -rw-r--r-- | nomsu.2.peg | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/nomsu.2.peg b/nomsu.2.peg index 1f096af..4f9c4c4 100644 --- a/nomsu.2.peg +++ b/nomsu.2.peg @@ -2,7 +2,7 @@ file: {:curr_indent: ' '* :} (((action / expression / inline_block / indented_block) eol !.) - / file_chunks / blank_lines / '') + / file_chunks / empty_block) %ws* (!! .+ -> "Parse error" !!)? shebang: "#!" (!"nomsu" [^%nl])* "nomsu" %ws+ "-V" %ws* {:version: [0-9.]+ :} [^%nl]* @@ -17,6 +17,10 @@ top_block (Block): {:curr_indent: ' '* :} comment? blank_lines? statement (nl_nodent statement)* +empty_block (Block): + {:curr_indent: ' '* :} + comment? blank_lines? + nodent: =curr_indent !(" ") indent: =curr_indent " " blank_lines: %nl ((nodent comment / %ws*) %nl)* @@ -117,9 +121,9 @@ indented_plain_text (Text): {~ (("\\" -> "\") / (("\" blank_lines =curr_indent "..") -> "") / (!text_interpolation "\") / [^%nl\]+)+ (%nl+ (=curr_indent -> ""))* ~} text_interpolation: - inline_text_interpolation / ("\" indented_expression blank_lines =curr_indent "..") + inline_text_interpolation / ("\" indented_expression (blank_lines =curr_indent "..")?) -number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / ([0-9]+)))-> tonumber) +number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / "0x" [0-9a-fA-F]+ / ([0-9]+)))-> tonumber) -- Variables can be nameless (i.e. just %) and can only contain identifier chars. -- This ensures you don't get weird parsings of `%x+%y` or `%'s thing`. |
