aboutsummaryrefslogtreecommitdiff
path: root/nomsu.4.peg
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-09-13 16:01:57 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-09-13 16:02:40 -0700
commit4d48bf359df98512a2a741d48ea222d055b733c0 (patch)
treef05f33baf4dd776f3f68230a611beafedbb2da4b /nomsu.4.peg
parentea310306d73e0bc6542f7133825549ae4471b06a (diff)
Improvements to indented text parsing and error reporting.
Diffstat (limited to 'nomsu.4.peg')
-rw-r--r--nomsu.4.peg25
1 files changed, 20 insertions, 5 deletions
diff --git a/nomsu.4.peg b/nomsu.4.peg
index ed119c5..eb0c878 100644
--- a/nomsu.4.peg
+++ b/nomsu.4.peg
@@ -59,6 +59,10 @@ missing_bracket_error (Error):
missing_brace_error (Error):
{:error: {~ eol -> "Line ended before finding a closing }-brace" ~} :}
{:hint: {~ '' -> 'Put a "}" here' ~} :}
+disallowed_interpolation (Error):
+ {:error: {~ ("\" ('\:' / '(..)' / '[..]' / '{..}') (%nl (&(%nl) / =curr_indent ' ' [^%nl]*))*) ->
+ "Sorry, indented text interpolations are not currently supported on the first line of multi-line text." ~} :}
+ {:hint: {~ '' -> 'Move the code for the first line of text to the next line by ending this line with "\" and starting the next line indented with "..", followed by the code for the first line.' ~} :}
section_division: ("~")^+3 eol
@@ -124,7 +128,7 @@ inline_text (Text):
!(cool_indented_text / indented_text)
('"' _inline_text* ('"' / missing_quote_err / unexpected_code))
_inline_text:
- {~ (('\"' -> '"') / ('\\' -> '\') / escaped_char / [^%nl\"])+ ~}
+ {~ (('\"' -> '"') / ('\\' -> '\') / escaped_char / [^%nl\"]+)+ ~}
/ inline_text_interpolation
inline_text_interpolation:
"\" (
@@ -140,13 +144,24 @@ indented_text (Text):
(indented_plain_text / text_interpolation / {~ %nl+ (=curr_indent -> "") ~})*
unexpected_code?
{:curr_indent: %nil :}
+
+
+cool_quote:
+ '"' !(%nl+ !(=curr_indent))
cool_indented_text (Text):
({|
- '"' _inline_text* '\' %nl {:curr_indent: indent :} '..'
- (indented_plain_text / text_interpolation / {~ %nl+ (=curr_indent -> "") ~})*
- unexpected_code?
+ '"'
+ _inline_text*
+ (('\' %nl+ {:curr_indent: indent :} '..')
+ / disallowed_interpolation? {%nl+} {:curr_indent: indent :})
+ (indented_cool_plain_text / text_interpolation / {~ %nl+ (=curr_indent -> "") ~})*
+ ('"' eol / missing_quote_err)
|} -> unpack)
- ({(%nl &%nl)+}? %nl =curr_indent '..' _inline_text* '"')?
+indented_cool_plain_text (Text):
+ {~ ((("\" blank_lines =curr_indent "..") -> "") / (!text_interpolation ((!("\n") escaped_char) / ('\\' -> '\') / '\')) / (cool_quote / [^%nl"\])+)+
+ (%nl+ (=curr_indent -> ""))* ~}
+
+
-- Tracking text-lines-within-indented-text as separate objects allows for better debugging line info
indented_plain_text (Text):
{~ (("\\" -> "\") / (("\" blank_lines =curr_indent "..") -> "") / (!text_interpolation "\") / [^%nl\]+)+