Skip to content

Commit 5e69e66

Browse files
committed
improved tokenizer
1 parent dff22b3 commit 5e69e66

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/main/java/com/igormaznitsa/prologparser/tokenizer/Tokenizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -785,7 +785,7 @@ state, getLastTokenLine(),
785785
final char theChar;
786786

787787
if (Character.isISOControl(chr)) {
788-
theChar = StringUtils.isAllowedEscapeChar(chr) ? chr : '→';
788+
throw new PrologParserException("Unexpected control char: 0x" + Integer.toHexString(chr), this.prevLine, this.prevPos);
789789
} else {
790790
theChar = chr;
791791
}

src/test/java/com/igormaznitsa/prologparser/IntegrationTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@ public void testSwiCpl() {
9999

100100
@Test
101101
public void testParseStringWithSpecialChars() {
102-
final PrologParser parser = parseEd("'0\\'a \u0008Hello\\\nWorld\u0021\\r'.\"0'a \\xFF\\Another String\u0007\".");
102+
final PrologParser parser = parseEd("'0\\'a Hello\\\nWorld\u0021\\r'.\"0'a \\xFF\\Another String\".");
103103
PrologTerm term = parser.next();
104104

105105
assertEquals(ATOM, term.getTermType());
106106
assertEquals(PrologTerm.QuotingType.SINGLE_QUOTED, term.getQuotingType());
107-
assertEquals("0\\'a \\bHello\\nWorld!\\r", StringUtils.escapeString(term.getTermText(), SINGLE_QUOTED));
107+
assertEquals("0\\'a Hello\\nWorld!\\r", StringUtils.escapeString(term.getTermText(), SINGLE_QUOTED));
108108

109109
term = parser.next();
110110
assertNotNull(term);
111111
assertEquals(PrologTerm.QuotingType.DOUBLE_QUOTED, term.getQuotingType());
112-
assertEquals("0'a \u00FFAnother String\u0007", term.getTermText());
112+
assertEquals("0'a ÿAnother String", term.getTermText());
113113

114114
}
115115

@@ -896,10 +896,9 @@ private String parseSortAndJoin(final String text) {
896896

897897
@Test
898898
public void testStringWithIsoControl() {
899-
assertEquals("'hello→world'", parseSortAndJoin("'hello\u0000world'."));
900-
assertEquals("'hello→world'", parseSortAndJoin("'hello\u0001world'."));
901-
assertEquals("'hello\\nworld'", parseSortAndJoin("'hello\\\nworld'."));
902-
assertEquals("'hello\\nworld'", parseSortAndJoin("'hello\\\r\nworld'."));
899+
assertThrows(PrologParserException.class, ()-> parseEd("'hello\u0000world'.").next());
900+
assertEquals("'hello\\nworld'", parseEd("'hello\\\nworld'.").next().toString());
901+
assertEquals("'hello\\nworld'", parseEd("'hello\\\r\nworld'.").next().toString());
903902
}
904903

905904
@Test

0 commit comments

Comments
 (0)