Skip to content

Commit 9a8df9c

Browse files
committed
Add support for line comments
1 parent b11d1d9 commit 9a8df9c

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

asyncpi_test.go

+22
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,28 @@ func TestParseSend(t *testing.T) {
178178
}
179179
}
180180

181+
// Tests parsing with comment.
182+
func TestParseComment(t *testing.T) {
183+
test := TestCase{
184+
Input: `
185+
a(). # Receive
186+
187+
# blank line
188+
189+
0 #end`,
190+
Output: `recv(a,[]).inact`,
191+
FreeNames: newNames("a"),
192+
}
193+
proc, err := Parse(strings.NewReader(test.Input))
194+
if err != nil {
195+
t.Fatal(err)
196+
}
197+
if strings.TrimSpace(proc.String()) != test.Output {
198+
t.Errorf("Parse: `%s` not parsed as recv `%s`.\nparsed: %s",
199+
test.Input, test.Output, proc)
200+
}
201+
}
202+
181203
// Tests syntax error.
182204
func TestParseFailed(t *testing.T) {
183205
incomplete := `(new a`

scanner.go

+11
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ func (s *scanner) Scan() (token tok, value string, startPos, endPos TokenPos) {
8484
return kREPEAT, string(ch), startPos, endPos
8585
case ',':
8686
return kCOMMA, string(ch), startPos, endPos
87+
case '#':
88+
s.skipToEOL()
89+
return s.Scan()
8790
}
8891

8992
return kILLEGAL, string(ch), startPos, endPos
@@ -125,3 +128,11 @@ func (s *scanner) skipWhitespace() {
125128
}
126129
}
127130
}
131+
132+
func (s *scanner) skipToEOL() {
133+
for {
134+
if ch := s.read(); ch == '\n' || ch == eof {
135+
break
136+
}
137+
}
138+
}

0 commit comments

Comments
 (0)