Skip to content

Commit e74bb4d

Browse files
committed
Merge pull request #1 from gitlarryf/comment-fixes
Fixed lexer to deal with incorrectly formatted Comments and Block Commen...
2 parents 77211c6 + e3f8030 commit e74bb4d

File tree

7 files changed

+56
-0
lines changed

7 files changed

+56
-0
lines changed

lexer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,15 @@ std::vector<Token> tokenize(const std::string &source)
232232
t.text.push_back(c);
233233
}
234234
} else if (c == '%') {
235+
if (i+1 >= source.length()) {
236+
break;
237+
}
235238
if (source.at(i+1) == '|') {
236239
int level = 0;
237240
do {
241+
if (i+1 >= source.length()) {
242+
error(t, "Missing closing comment '|%'");
243+
}
238244
if (source.at(i) == '%' && source.at(i+1) == '|') {
239245
level++;
240246
i += 2;

t/comments-block.simple

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%! Missing closing comment '|%'
2+
3+
%| Block Comment, without proper ending comment token.

t/comments-block2.simple

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
%! Missing closing comment '|%'
2+
3+
%| This test is specifically designed to BEGIN the Block-Comment ending token,
4+
but leaving off the last part of it, as well as ANY other data in the file.
5+
This will test the lexers ability to handle a case where it THINKS the
6+
token is ABOUT to end, but it does not, which is why there is NO LF at the
7+
end of this file, and why the test result appears at the top. |%
8+
9+
%| Block Comment, without proper ending comment token.|

t/comments-block3.simple

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%! Missing closing comment '|%'
2+
3+
%| Block Comment, without proper ending comment token.%|

t/comments-block4.simple

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
%! Missing closing comment '|%'
2+
3+
%| Block Comment, without proper ending comment token.%|%%

t/comments-block5.simple

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%= Passed.
2+
3+
%| This test is testing the COMMENT token on the last line of a source file.
4+
A line that does not end, thus making sure the lexer lexes the line properly
5+
and prints the correct "Test Passed" message to the test harness. |%
6+
7+
print("Passed.")%

t/comments.simple

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
%|--------------------------------------------------------------------------|%
2+
%| Testing "FlowerBox Comments..." |%
3+
%| Test Set : comments.simple |%
4+
%| Created On : 2014-10-21 |%
5+
%| Updated On : 2014-10-21 |%
6+
%| Created By : Larry Frieson |%
7+
%|--------------------------------------------------------------------------|%
8+
print("FlowerBox Comments ok.")
9+
%= FlowerBox Comments ok.
10+
11+
% Regular Simple-Lang comments...
12+
print("Regular Comments ok.")
13+
14+
%= Regular Comments ok.
15+
16+
%|
17+
%|
18+
%|
19+
Testing Nested Comments...
20+
|%
21+
|%
22+
|%
23+
24+
print("Nested Comments ok.")
25+
%= Nested Comments ok.

0 commit comments

Comments
 (0)