Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 4469971

Browse files
committed
Fixes issue of literal # crashing parser. Closes #1
1 parent f738017 commit 4469971

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

Clog/src/main/java/com/caseyjbrooks/clog/parseltongue/TokenStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ Token getAny() {
129129
ch = chars.removeFirst();
130130
column++;
131131

132-
if(ch == '#' && chars.peekFirst() == '{') {
132+
if(ch == '#' && chars.size() > 0 && chars.peekFirst() == '{') {
133133
chars.removeFirst();
134134
column++;
135135
ungetTokens.push(new Token(Token.Type.CLOG_START));
136136
return new Token(Token.Type.ANY, s);
137137
}
138-
else if(ch == '{' && chars.peekFirst() == '}') {
138+
else if(ch == '{' && chars.size() > 0 && chars.peekFirst() == '}') {
139139
// chars.removeFirst();
140140
// column++;
141141
ungetTokens.push(new Token(Token.Type.CLOG_SIMPLE));
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
version: '2.0.7'
3+
---
4+
5+
- Fixes issue of literal `#` crashing parser. Closes #1

Clog/src/test/java/com/caseyjbrooks/clog/ParseltongueTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,27 @@ public void testIndexers() {
482482
assertEquals(expectedOutput, output);
483483
}
484484

485+
// Test Bugfixes
486+
//----------------------------------------------------------------------------------------------------------------------
487+
488+
@Test
489+
public void testBugFixes() {
490+
Parseltongue parseltongue = new Parseltongue();
491+
parseltongue.findSpells(ParseltongueTest.class);
492+
493+
String input, expectedOutput, output;
494+
495+
input = "#";
496+
expectedOutput = "#";
497+
output = parseltongue.format(input);
498+
assertEquals(expectedOutput, output);
499+
500+
input = "# and a #{$1} clog and also another # followed by another #{$2} clog";
501+
expectedOutput = "# and a 1 clog and also another # followed by another 2 clog";
502+
output = parseltongue.format(input, 1, 2);
503+
assertEquals(expectedOutput, output);
504+
}
505+
485506
//test spells
486507
//--------------------------------------------------------------------------------------------------
487508

0 commit comments

Comments
 (0)