aboutsummaryrefslogtreecommitdiff
path: root/nomsu.6.peg
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-18 15:18:49 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-18 15:18:49 -0800
commit32b258868ccd35b6fce3cf5fa6221da74868bc0b (patch)
tree52a4a5d6c953332485dd5958a956b424102287cf /nomsu.6.peg
parentd92685ab9502ccb173999dbe2d95fe0658cd5dff (diff)
Fix for parsing an indented top_block that starts with a comment and has
code after it.
Diffstat (limited to 'nomsu.6.peg')
-rw-r--r--nomsu.6.peg10
1 files changed, 6 insertions, 4 deletions
diff --git a/nomsu.6.peg b/nomsu.6.peg
index 39b0629..9b82345 100644
--- a/nomsu.6.peg
+++ b/nomsu.6.peg
@@ -2,9 +2,8 @@
file <-
{:curr_indent: ' '* :}
(((methodchain / action / expression / inline_block) eol !.)
- / file_chunks / comment? blank_lines?)
+ / file_chunks / comment? (blank_lines ws*)?)
{:curr_indent: %nil :}
- (unexpected_code .+)?
!.
shebang <- "#!" (!"nomsu" [^%nl])* "nomsu" ws+ "-V" ws* [0-9.]+ [^%nl]* (%nl / !.)
@@ -20,7 +19,7 @@ section_division <- ("~")^+3 eol
eof <- !.
eol <- ws* (&%nl / !.)
nodent <- (unexpected_indent [^%nl]* / =curr_indent)
-indent <- {~ =curr_indent " " ~}
+indent <- {=curr_indent " "}
blank_lines <- %nl ((nodent comment / ws*) %nl)*
nl_nodent <- blank_lines nodent
nl_indent <- blank_lines tab_error? {:curr_indent: indent :} (comment nl_nodent)*
@@ -31,7 +30,7 @@ comment (Comment) <-
top_block (Block) <-
- comment? blank_lines? statement (nl_nodent statement)*
+ (comment nl_nodent)? statement (nl_nodent statement)*
inline_block (Block) <-
":" ws* (inline_statement (ws* ";" ws* inline_statement)*)?
@@ -244,6 +243,9 @@ _unexpected_code (Error) <-
{:error: {~ [^%nl]+ -> "Couldn't parse this code" ~} :}
unexpected_chunk (Error) <-
{:error: {~ .+ -> "Couldn't parse this code" ~} :}
+unexpected_space (Error) <-
+ {:error: {~ ws+ -> "Messed up indentation" ~} :}
+ {:hint: {~ '' -> 'Either make sure this line is aligned with the one above it, or make sure the previous line ends with something that uses indentation, like ":" or "(..)"' ~} :}
unexpected_indent (Error) <-
{:error: {~ (=curr_indent ws+) -> "Messed up indentation" ~} :}
{:hint: {~ '' -> 'Either make sure this line is aligned with the one above it, or make sure the previous line ends with something that uses indentation, like ":" or "(..)"' ~} :}