Skip to content

Commit 9b45b72

Browse files
committed
Add support for single-line # comments
Comments currently do not go into the AST, they are just ignored when parsing the file. Resolves #32.
1 parent aa505e7 commit 9b45b72

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/grammar.rustpeg

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,13 @@ identifier -> String
231231
_identifier -> String
232232
= !reserved_identifier i:$([a-zA-Z_][a-zA-Z0-9_]*[!?]?) { i.to_string() }
233233

234-
__ = whitespace*
234+
__ = #quiet<(whitespace / comment)*>
235235

236-
whitespace = #quiet<[ \t\n]>
236+
comment = "#" (!eol_char .)*
237+
238+
eol_char = [\n\r]
239+
240+
whitespace = [ \t\n\r]
237241

238242
EQUALS = #quiet<"="> / #expected("equals")
239243

tests/run-pass/comments.bl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# comment
2+
fn f() {#comment
3+
var x = 5; # comment
4+
if true { #comment
5+
# comment
6+
x = 20;#comment
7+
} # comment
8+
else {
9+
x = 10;
10+
} # comment
11+
return x; #comment
12+
# comment
13+
} #comment
14+
# comment
15+
assert_eq(f(), 20); # comment

0 commit comments

Comments
 (0)