mirror of
https://github.com/HigherOrderCO/Bend.git
synced 2024-08-15 14:50:42 +03:00
Add multi line comment syntax
This commit is contained in:
parent
29f2098ce5
commit
f288ae7f12
@ -1093,14 +1093,31 @@ impl<'a> Parser<'a> for TermParser<'a> {
|
||||
continue;
|
||||
}
|
||||
if c == '#' {
|
||||
while let Some(c) = self.peek_one() {
|
||||
if c != '\n' {
|
||||
self.advance_one();
|
||||
if let Some(c) = self.peek_one() {
|
||||
if c == '{' {
|
||||
self.advance_one();
|
||||
while let Some(c) = self.peek_one() {
|
||||
self.advance_one();
|
||||
if c == '}' {
|
||||
if let Some('#') = self.peek_one() {
|
||||
self.advance_one();
|
||||
break;
|
||||
} else {
|
||||
self.advance_one();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
while let Some(c) = self.peek_one() {
|
||||
if c != '\n' {
|
||||
self.advance_one();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.advance_one(); // Skip the newline character as well
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
@ -1243,12 +1260,35 @@ pub trait ParserCommons<'a>: Parser<'a> {
|
||||
continue;
|
||||
}
|
||||
if c == '#' {
|
||||
while let Some(c) = self.peek_one() {
|
||||
if c != '\n' {
|
||||
self.advance_one();
|
||||
char_count += 1;
|
||||
if let Some(c) = self.peek_one() {
|
||||
if c == '{' {
|
||||
self.advance_one();
|
||||
char_count += 1;
|
||||
while let Some(c) = self.peek_one() {
|
||||
self.advance_one();
|
||||
char_count += 1;
|
||||
if c == '}' {
|
||||
if let Some('#') = self.peek_one() {
|
||||
self.advance_one();
|
||||
char_count += 1;
|
||||
break;
|
||||
} else {
|
||||
self.advance_one();
|
||||
char_count += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
while let Some(c) = self.peek_one() {
|
||||
if c != '\n' {
|
||||
self.advance_one();
|
||||
char_count += 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
55
tests/golden_tests/parse_file/multi_line_comment.bend
Normal file
55
tests/golden_tests/parse_file/multi_line_comment.bend
Normal file
@ -0,0 +1,55 @@
|
||||
#{
|
||||
|
||||
|
||||
|
||||
|
||||
}#
|
||||
|
||||
def main:
|
||||
#{
|
||||
ok
|
||||
#}#
|
||||
#
|
||||
return 0
|
||||
|
||||
#{foo type}#
|
||||
type Foo:
|
||||
#{foo constructor}#
|
||||
Foo { foo }
|
||||
|
||||
#{bar type}#
|
||||
object Bar { bar }
|
||||
#{
|
||||
# ignore
|
||||
# }#
|
||||
|
||||
#{X x x x}#
|
||||
(X x x x) = #{ x }# x #{ x }#
|
||||
|
||||
#{V}#
|
||||
type V
|
||||
= #{V constructor}# V
|
||||
|
||||
(String/is_empty s) =
|
||||
#{test if string is nil}#
|
||||
match s #{
|
||||
|
||||
}#{
|
||||
String/Nil: 1
|
||||
String/Cons: 0
|
||||
}
|
||||
|
||||
def String/not_empty(s):
|
||||
#{test if string if not nil}#
|
||||
match s:
|
||||
#{
|
||||
its
|
||||
not
|
||||
}#
|
||||
case String/Nil:
|
||||
return 0
|
||||
case String/Cons:
|
||||
#{
|
||||
it
|
||||
is}#
|
||||
return 1
|
23
tests/snapshots/parse_file__multi_line_comment.bend.snap
Normal file
23
tests/snapshots/parse_file__multi_line_comment.bend.snap
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
source: tests/golden_tests.rs
|
||||
input_file: tests/golden_tests/parse_file/multi_line_comment.bend
|
||||
---
|
||||
(X) = λ%arg0 λ%arg1 λ%arg2 use x = %arg2; x
|
||||
|
||||
(String/is_empty) = λ%arg0 use s = %arg0; match s = s { String/Nil: 1; String/Cons: 0; }
|
||||
|
||||
(main) = 0
|
||||
|
||||
(String/not_empty) = λ%arg0 use s = %arg0; match s = s { String/Nil: 0; String/Cons: 1; }
|
||||
|
||||
(Foo/Foo) = λfoo λ%x (%x Foo/Foo/tag foo)
|
||||
|
||||
(Bar) = λbar λ%x (%x Bar/tag bar)
|
||||
|
||||
(V/V) = λ%x (%x V/V/tag)
|
||||
|
||||
(Foo/Foo/tag) = 0
|
||||
|
||||
(Bar/tag) = 0
|
||||
|
||||
(V/V/tag) = 0
|
Loading…
Reference in New Issue
Block a user