diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-17 14:12:11 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-17 14:12:51 -0700 |
| commit | 0442c8dd216f16c7371873a8e8fd8bf83d30dad0 (patch) | |
| tree | f3ca5f178b9851d27d95bf060f966e2398ef9a6a /nomsu.2.peg | |
| parent | be06fc096aa28358914bd6a76b4ea380a04b8873 (diff) | |
Overhaul of comment handling, plus a few fixes (e.g. a fix for indented
text that begins with a nomsu comment)
Diffstat (limited to 'nomsu.2.peg')
| -rw-r--r-- | nomsu.2.peg | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/nomsu.2.peg b/nomsu.2.peg index f6a5d23..58ae33d 100644 --- a/nomsu.2.peg +++ b/nomsu.2.peg @@ -1,6 +1,7 @@ -- Nomsu version 2 file (FileChunks): {:curr_indent: ' '* :} + ("#!" (!"nomsu" [^%nl])* "nomsu" %ws+ "-V" %ws* {:version: ([0-9.]+ -> tonumber) :} [^%nl]*)? comment? blank_lines? (chunk (nl_nodent section_division nl_nodent chunk)*)? blank_lines? @@ -61,13 +62,16 @@ index_chain (IndexChain): -- Actions need either at least 1 word, or at least 2 tokens inline_action (Action): !section_division - ( (inline_expression (%ws* (inline_expression / word))+) - / (word (%ws* (inline_expression / word))*)) + ( ((smushed_action / inline_expression) (%ws* (smushed_action / inline_expression / word))+) + / (word (%ws* (smushed_action / inline_expression / word))*)) (%ws* inline_block)? action (Action): !section_division - ( (expression ((nl_nodent "..")? %ws* (expression / word))+) - / (word ((nl_nodent "..")? %ws* (expression / word))*)) + ( ((smushed_action / expression) ((nl_nodent "..")? %ws* (smushed_action / expression / word))+) + / (word ((nl_nodent "..")? %ws* (smushed_action / expression / word))*)) +smushed_action (Action): + !section_division + (index_chain / noindex_inline_expression / word+) (index_chain / noindex_inline_expression / word+ / "(" %ws* ")")+ word: !number { %operator_char+ / %ident_char+ } @@ -93,20 +97,20 @@ inline_text_interpolation: ) indented_text (Text): - '".."' eol %nl {:curr_indent: indent :} - (indented_plain_text / text_interpolation / {~ blank_lines (=curr_indent -> "") ~})* + '".."' eol %nl {%nl*} {:curr_indent: indent :} + (indented_plain_text / text_interpolation / {~ %nl+ (=curr_indent -> "") ~})* (!! [^%nl]+ -> "Unexpected character while parsing Text" !!)? indented_plain_text (Text): {~ (("\\" -> "\") / (("\" blank_lines =curr_indent "..") -> "") / (!text_interpolation "\") / [^%nl\]+)+ - (blank_lines (=curr_indent -> ""))* ~} + (%nl+ (=curr_indent -> ""))* ~} text_interpolation: inline_text_interpolation / ("\" indented_expression blank_lines =curr_indent "..") number (Number): (("-"? (([0-9]+ "." [0-9]+) / ("." [0-9]+) / ([0-9]+)))-> tonumber) --- Variables can be nameless (i.e. just %) and can't contain operators like apostrophe --- which is a hack to allow %'s to parse as "%" and "' s" separately -variable (Var): "%" {(%ident_char+ ((!"'" %operator_char+) / %ident_char+)*)?} +-- 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`. +variable (Var): "%" {%ident_char*} inline_list (List): !('[..]') |
