Skip to content

Commit f2ff19c

Browse files
committed
fixed case when operator merged with number and recognized as radix
1 parent 45adbe6 commit f2ff19c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ TokenizerResult readNextToken() {
292292
PrologTerm.QuotingType quoting = PrologTerm.QuotingType.NO_QUOTED;
293293

294294
int radix = 10;
295+
char detectedRadixChar = ' ';
295296

296297
TokenizerState state = LOOK_FOR;
297298
boolean specCharDetected = false;
@@ -568,19 +569,26 @@ TokenizerResult readNextToken() {
568569
if (chr == 'x') {
569570
radixCharFound = true;
570571
radix = 16;
572+
detectedRadixChar = chr;
571573
strBuffer.clear();
572574
} else if (chr == 'o') {
573575
radixCharFound = true;
574576
radix = 8;
577+
detectedRadixChar = chr;
575578
strBuffer.clear();
576579
} else if (chr == 'b') {
577580
radixCharFound = true;
578581
radix = 2;
582+
detectedRadixChar = chr;
579583
strBuffer.clear();
580584
}
581585
}
582586
if (!radixCharFound) {
583587
push(chr);
588+
if (strBuffer.isEmpty() && detectedRadixChar != ' ') {
589+
push(detectedRadixChar);
590+
strBuffer.append('0');
591+
}
584592
return this.tokenizerResultPool.find().setData(
585593
makeTermFromString(strBuffer.toString(), radix, quoting, state),
586594
TokenizerState.INTEGER,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ public void testConformity() {
11381138
assertEquals("write_canonical(1 p (p p 2))", parseEd("write_canonical(1 p p p 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, FY, "p"), Op.make(9, YFX, "p"))).next().toString());
11391139
assertEquals("write_canonical(1 p p p 2)", parseEd("write_canonical(1 p p p 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, FY, "p"), Op.make(9, XFY, "p"))).next().toString());
11401140
assertEquals("write_canonical(1 p p p 2)", parseEd("write_canonical(1 p p p 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(7, FY, "p"), Op.make(9, YFX, "p"))).next().toString());
1141-
// assertEquals("atom('.\'-\'.')",parseEd("atom('.\'-\'.').").next().toString());
1141+
assertEquals("atom('.\\\'-\\\'.')", parseEd("atom('.\\\'-\\\'.').").next().toString());
11421142
assertEquals("op(0, xfy, '|')", parseEd("op(0,xfy,'|').").next().toString());
11431143
assertEquals("writeq((a | b))", parseEd("/**/ writeq((a|b)).").next().toString());
11441144
assertEquals("X is 10.0 ** (-323)", parseEd("X is 10.0** -323.").next().toString());
@@ -1156,12 +1156,12 @@ public void testConformity() {
11561156
assertEquals("writeq(nop(1))", parseEd("writeq(nop (1)).").next().toString());
11571157
assertEquals("writeq(1 = f)", parseEd("/**/ writeq(1 = f).").next().toString());
11581158
assertEquals("write_canonical(a - - - b)", parseEd("write_canonical(a- - -b).").next().toString());
1159-
// assertEquals("writeq(0 bop 2)",parseEd("writeq(0bop 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop","bo","b","op","xor"))).next().toString());
1159+
assertEquals("writeq(0 bop 2)", parseEd("writeq(0bop 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop", "bo", "b", "op", "xor"))).next().toString());
11601160
assertEquals("writeq(0 bop 2)", parseEd("/**/ writeq(0 bop 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop", "bo", "b", "op", "xor"))).next().toString());
1161-
// assertEquals("writeq(0 bo 2)",parseEd("/**/ writeq(0bo 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop","bo","b","op","xor"))).next().toString());
1162-
// assertEquals("writeq(0 b 2)",parseEd("/**/ writeq(0b 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop","bo","b","op","xor"))).next().toString());
1163-
// assertEquals("writeq(0 op 2)",parseEd("/**/ writeq(0op 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop","bo","b","op","xor"))).next().toString());
1164-
// assertEquals("writeq(0 xor 2)",parseEd("/**/ writeq(0xor 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop","bo","b","op","xor"))).next().toString());
1161+
assertEquals("writeq(0 bo 2)", parseEd("/**/ writeq(0bo 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop", "bo", "b", "op", "xor"))).next().toString());
1162+
assertEquals("writeq(0 b 2)", parseEd("/**/ writeq(0b 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop", "bo", "b", "op", "xor"))).next().toString());
1163+
assertEquals("writeq(0 op 2)", parseEd("/**/ writeq(0op 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop", "bo", "b", "op", "xor"))).next().toString());
1164+
assertEquals("writeq(0 xor 2)", parseEd("/**/ writeq(0xor 2).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(9, YFX, "bop", "bo", "b", "op", "xor"))).next().toString());
11651165
assertEquals("writeq('^`')", parseEd("writeq('^`').").next().toString());
11661166
assertEquals("writeq('\\b\\r\\f\\t\\n')", parseEd("writeq('\\b\\r\\f\\t\\n').").next().toString());
11671167
assertEquals("writeq(-- a)", parseEd("writeq(--(a)).", DefaultParserContext.of(FLAG_BLOCK_COMMENTS, Op.make(20, FX, "--"))).next().toString());

0 commit comments

Comments
 (0)