Skip to content

Commit 2b08756

Browse files
committed
improved list parsing
1 parent 3718bf4 commit 2b08756

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ private PrologTerm readList(final TokenizerResult openingBracket) {
336336
if (hasSeparator) {
337337
// '|' separator was found at the list
338338
if (rightPart == null) {
339-
throw new PrologParserException("There is not any term as the tail at the list", tokenizer.getLastTokenLine(), tokenizer.getLastTokenPos());
339+
throw new PrologParserException("There is not any term as the tail at the list", this.tokenizer.getLastTokenLine(), this.tokenizer.getLastTokenPos());
340+
}
341+
if (rightPart.getTermType() == TermType.ATOM && rightPart.getQuotingType() == PrologTerm.QuotingType.NO_QUOTED && ",".equals(rightPart.getTermText())) {
342+
throw new PrologParserException("Comma operator in list tail", this.tokenizer.getLastTokenLine(), this.tokenizer.getLastTokenPos());
340343
}
341344
leftPartFirst.replaceTail(rightPart);
342345
}

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,6 @@ public void testParseFloat() {
293293
final PrologTerm val = parseEd("298723987493287423423.00002342342300043324234324E+75.").next();
294294
assertEquals(ATOM, val.getTermType());
295295
assertEquals(PrologFloat.class, val.getClass());
296-
297-
final PrologTerm valAtom = parseEd("2.0E.").next();
298-
assertEquals(ATOM, valAtom.getTermType());
299-
assertEquals(PrologAtom.class, valAtom.getClass());
300296
}
301297

302298
@Test
@@ -1107,6 +1103,8 @@ public void testStandardTermOrder() {
11071103
*/
11081104
@Test
11091105
public void testConformity() {
1106+
assertEquals("writeq([a, b|','])", parseEd("writeq([a,b|',']).").next().toString());
1107+
assertEquals("X = 1", parseEd("X = 2'1.").next().toString());
11101108
assertEquals("writeq(- - 1)", parseEd("writeq(-(-(1))).").next().toString());
11111109
assertEquals("writeq(- - a)", parseEd("writeq(-(-a)).").next().toString());
11121110
assertEquals("writeq(- - - a)", parseEd("writeq(-(-(-a))).").next().toString());
@@ -1168,7 +1166,6 @@ public void testConformity() {
11681166
assertEquals("writeq(-- a)", parseEd("writeq(--(a)).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(0, FY, "--"))).next().toString());
11691167
assertEquals("writeq(10 mod 2)", parseEd("writeq(0xamod 2).").next().toString());
11701168

1171-
11721169
assertThrows(PrologParserException.class, () -> parseEd("integer(0'').").next());
11731170
assertThrows(PrologParserException.class, () -> parseEd("writeq('\\^J').").next());
11741171
assertThrows(PrologParserException.class, () -> parseEd("writeq(00'a).").next());
@@ -1192,14 +1189,13 @@ public void testConformity() {
11921189

11931190
assertThrows(PrologParserException.class, () -> parseEd("/**/ X = 1.e.", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(100, XF, "f"))).next());
11941191
assertThrows(PrologParserException.class, () -> parseEd("/**/ writeq(1 .2).").next());
1195-
// assertThrows(PrologParserException.class, () -> parseEd("X = 2'1.").next());
11961192
assertThrows(PrologParserException.class, () -> parseEd("is 0'mod'1.").next());
11971193
assertThrows(PrologParserException.class, () -> parseEd("X = '\\77777777777\\'.").next());
11981194
assertThrows(PrologParserException.class, () -> parseEd("X = '\\N'.").next());
11991195
assertThrows(PrologParserException.class, () -> parseEd("X = '\\9'.").next());
12001196
assertThrows(PrologParserException.class, () -> parseEd("a = '\\141'.").next());
12011197
assertThrows(PrologParserException.class, () -> parseEd("X = [] (1).").next());
1202-
// assertThrows(PrologParserException.class, () -> parseEd("writeq([a,b|,]).").next());
1198+
assertThrows(PrologParserException.class, () -> parseEd("writeq([a,b|,]).").next());
12031199
assertThrows(PrologParserException.class, () -> parseEd("(- - - -) = -(-(-(-))).").next());
12041200
assertThrows(PrologParserException.class, () -> parseEd("(- - -) = -(-(-)).").next());
12051201
assertThrows(PrologParserException.class, () -> parseEd("(- -) = -(-).").next());

0 commit comments

Comments
 (0)