diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-14 14:41:17 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-07-14 14:41:32 -0700 |
| commit | d535dc57940f6c9558d3b588d53b44a87b2a8ed2 (patch) | |
| tree | f0c8ecfcc65d302bbbfa3a867f60a56f3263310c /nomsu.peg | |
| parent | 01a4f36398bfe66a7286a83fdd797c8b20541681 (diff) | |
Fixed up comment generation to old standards
Diffstat (limited to 'nomsu.peg')
| -rw-r--r-- | nomsu.peg | 87 |
1 files changed, 40 insertions, 47 deletions
@@ -1,37 +1,34 @@ -- Nomsu version 2 file (File): - %nl* {:curr_indent: ' '* :} + comment? blank_lines? (chunk (nl_nodent chunk_delimeter nl_nodent chunk)*)? - %nl* + blank_lines? (!! .+ -> "Parse error" !!)? nodent: =curr_indent !(" ") indent: =curr_indent " " -blank_lines: %nl (%ws* %nl)* -eol: (!. / &%nl) - -comment (Comment): - !inline_comment - "#" {~ [^%nl]* (blank_lines (indent -> '') [^%nl]*)* ~} -inline_comment (Comment): - "#(" {~ (inline_comment / [^%nl])* ~} ")#" +blank_lines: %nl ((nodent comment / %ws*) %nl)* +eol: %ws* eol_comment? (!. / &%nl) nl_nodent: blank_lines nodent -nl_indent: blank_lines {:curr_indent: indent :} +nl_indent: blank_lines {:curr_indent: indent :} (comment nl_nodent)? + +comment: + "#" (({} {~ [^%nl]* ((%nl (!indent %ws* %nl)*) (indent -> '') [^%nl]*)* ~} %userdata) => add_comment) +eol_comment: + "#" (({} {[^%nl]*} %userdata) => add_comment) -chunk: block / ((comment nl_nodent)* (action / expression)? (nl_nodent comment)*) -chunk_delimeter: ("~")^+3 +chunk: block / action / expression +chunk_delimeter: ("~")^+3 eol inline_block (Block): - inline_statement (%ws* ";" %ws* inline_statement)+ (%ws* inline_comment)* + inline_statement (%ws* ";" %ws* inline_statement)+ block (Block): - block_line (nl_nodent block_line)+ (nl_nodent comment)* -block_line: - statement %ws* (!! [^%nl]+ -> "Unexpected character while parsing block line" !!)? + statement (nl_nodent statement)+ -statement: (comment nl_nodent)* (action / expression) %ws* (!! [^%nl]+ -> "Unexpected character while parsing line" !!)? -inline_statement: (inline_comment %ws*)* (inline_action / inline_expression) +statement: (action / expression) (eol / (!! [^%nl]+ -> "Unexpected character while parsing line" !!)) +inline_statement: (inline_action / inline_expression) noindex_inline_expression: number / variable / inline_text / inline_list / inline_dict / inline_nomsu @@ -39,22 +36,21 @@ noindex_inline_expression: %ws* (inline_block / inline_action / inline_expression) %ws* (%ws* ',' %ws* (inline_block / inline_action / inline_expression) %ws*)* (")" - / (!! %ws* eol -> 'Line ended without finding a closing )-parenthesis' !!) + / (!! eol -> 'Line ended without finding a closing )-parenthesis' !!) / (!! [^%nl]+ -> 'Unexpected character while parsing subexpression' !!) ) ) inline_expression: index_chain / noindex_inline_expression indented_expression: indented_text / indented_nomsu / indented_list / indented_dict / ({| - ("(..)" / ":")? nl_indent (comment nl_nodent)* - (block / action / expression) + ("(..)")? nl_indent + (block / action / expression) (nl_nodent comment)* (!! [^%nl]+ -> "Unexpected character while parsing indented expression" !!)? |} -> unpack) expression: inline_expression / (":" %ws* - (!! eol -> "Missing expression after the ':'" !!)? - (inline_block / inline_action / inline_expression) %ws* eol) + (inline_block / inline_action / inline_expression / (!! '' -> "Missing expression after the ':'" !!))) / indented_expression inline_nomsu (EscapedNomsu): "\" inline_expression @@ -62,8 +58,7 @@ indented_nomsu (EscapedNomsu): "\" ( noindex_inline_expression / (":" %ws* - (!! eol -> "Missing expression after the '\:'" !!)? - (inline_block / inline_action / inline_expression) %ws* eol) + (inline_block / inline_action / inline_expression) (!! '' -> "Missing expression after the '\:'" !!)) / indented_expression) index_chain (IndexChain): @@ -72,23 +67,21 @@ index_chain (IndexChain): -- Actions need either at least 1 word, or at least 2 tokens inline_action (Action): !chunk_delimeter - (inline_comment %ws*)* - ( (inline_expression ((%ws* inline_comment)* %ws* (inline_expression / word))+) - / (word ((%ws* inline_comment)* %ws* (inline_expression / word))*)) - ((%ws* inline_comment)* %ws* ":" %ws* (inline_block / inline_action / inline_expression + ( (inline_expression (%ws* (inline_expression / word))+) + / (word (%ws* (inline_expression / word))*)) + (%ws* ":" %ws* (inline_block / inline_action / inline_expression / (!! '' -> "Missing expression after the ':'" !!)))? action (Action): !chunk_delimeter - (inline_comment %ws*)* - ( (expression (((nl_nodent comment)* nl_nodent "..")? %ws* (inline_comment %ws*)* (expression / word))+) - / (word (((nl_nodent comment)* nl_nodent "..")? %ws* (inline_comment %ws*)* (expression / word))*)) + ( (expression ((nl_nodent "..")? %ws* (expression / word))+) + / (word ((nl_nodent "..")? %ws* (expression / word))*)) word: !number { %operator_char+ / %ident_char+ } text_word (Text): word inline_text (Text): - !('".."' %ws* eol) + !('".."' eol) '"' ({~ (('\"' -> '"') / ('\\' -> '\') / %escaped_char / [^%nl\"])+ ~} / inline_text_interpolation)* @@ -102,16 +95,16 @@ inline_text_interpolation: %ws* (inline_block / inline_action / inline_expression) %ws* (%ws* ',' %ws* (inline_block / inline_action / inline_expression) %ws*)* (")" - / (!! %ws* eol -> 'Line ended without finding a closing )-parenthesis' !!) + / (!! eol -> 'Line ended without finding a closing )-parenthesis' !!) / (!! [^%nl]+ -> 'Unexpected character while parsing Text interpolation' !!))) ) indented_text (Text): - '".."' %ws* %nl {:curr_indent: indent :} + '".."' eol %nl {:curr_indent: indent :} (indented_plain_text / text_interpolation / {~ blank_lines (=curr_indent -> "") ~})* (!! [^%nl]+ -> "Unexpected character while parsing Text" !!)? indented_plain_text (Text): - {~ (("\\" -> "\") / (("\" (blank_lines =curr_indent comment)* blank_lines =curr_indent "..") -> "") / (!text_interpolation "\") / [^%nl\]+)+ + {~ (("\\" -> "\") / (("\" blank_lines =curr_indent "..") -> "") / (!text_interpolation "\") / [^%nl\]+)+ (blank_lines (=curr_indent -> ""))* ~} text_interpolation: inline_text_interpolation / ("\" indented_expression blank_lines =curr_indent "..") @@ -127,16 +120,16 @@ inline_list (List): "[" %ws* (inline_list_item (%ws* ',' %ws* inline_list_item)* (%ws* ',')?)? %ws* ("]" / (","? ( - (!! %ws* eol -> "Line ended before finding a closing ]-bracket" !!) + (!! eol -> "Line ended before finding a closing ]-bracket" !!) /(!! [^%nl]+ -> "Unexpected character while parsing List" !!)? ))) indented_list (List): - "[..]" nl_indent (comment nl_nodent)* - list_line (nl_nodent list_line)* + "[..]" eol nl_indent + list_line (nl_nodent list_line)* (nl_nodent comment)* (","? (!! [^%nl]+ -> "Unexpected character while parsing List" !!))? list_line: - (inline_list_item %ws* "," %ws*)+ %ws* eol - / (inline_list_item %ws* "," %ws*)* (action / expression) + (inline_list_item %ws* "," %ws*)+ eol + / (inline_list_item %ws* "," %ws*)* (action / expression) eol inline_list_item: inline_block / inline_action / inline_expression inline_dict (Dict): @@ -144,16 +137,16 @@ inline_dict (Dict): "{" %ws* (inline_dict_entry (%ws* ',' %ws* inline_dict_entry)*)? %ws* ("}" / (","? ( - (!! %ws* eol -> "Line ended before finding a closing }-brace" !!) + (!! eol -> "Line ended before finding a closing }-brace" !!) / (!! [^%nl]* -> "Unexpected character while parsing Dictionary" !!) ))) indented_dict (Dict): - "{..}" nl_indent (comment nl_nodent)* - dict_line ((nl_nodent comment)* nl_nodent dict_line)* (nl_nodent comment)* + "{..}" eol nl_indent + dict_line (nl_nodent dict_line)* (nl_nodent comment)* (","? (!! [^%nl]+ -> "Unexpected character while parsing Dictionary" !!))? dict_line: - (inline_dict_entry %ws* "," %ws*)+ %ws* eol - / (inline_dict_entry %ws* "," %ws*)* dict_entry + (inline_dict_entry %ws* "," %ws*)+ eol + / (inline_dict_entry %ws* "," %ws*)* dict_entry eol dict_entry(DictEntry): dict_key (%ws* ":" %ws* (action / expression))? inline_dict_entry(DictEntry): |
