File tree Expand file tree Collapse file tree 5 files changed +17
-6
lines changed
main/java/com/igormaznitsa/prologparser
test/java/com/igormaznitsa/prologparser Expand file tree Collapse file tree 5 files changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -80,4 +80,9 @@ public String toString() {
8080 final String result = this .value .toEngineeringString ();
8181 return result .indexOf ('.' ) < 0 ? result + ".0" : result ;
8282 }
83+
84+ @ Override
85+ public boolean isNegative () {
86+ return this .value .signum () < 0 ;
87+ }
8388}
Original file line number Diff line number Diff line change @@ -113,4 +113,9 @@ public Number getNumber() {
113113 public BigInteger getIntValue () {
114114 return this .value ;
115115 }
116+
117+ @ Override
118+ public boolean isNegative () {
119+ return this .value .signum () < 0 ;
120+ }
116121}
Original file line number Diff line number Diff line change @@ -48,5 +48,7 @@ public String getTermText() {
4848 return toString ();
4949 }
5050
51+ public abstract boolean isNegative ();
52+
5153 public abstract PrologNumeric neg ();
5254}
Original file line number Diff line number Diff line change @@ -233,7 +233,7 @@ private boolean isOperator() {
233233
234234 @ Override
235235 public String toString () {
236- return savedTerm . toString ();
236+ return "TreeItem[" + ( this . savedTerm == null ? "null" : this . savedTerm . toString ()) + ']' ;
237237 }
238238
239239 PrologTerm convertToTermAndRelease () {
@@ -298,9 +298,10 @@ PrologTerm convertToTermAndRelease() {
298298 right = this .rightBranch == null ? null : this .rightBranch .convertToTermAndRelease ();
299299 }
300300
301- // this code replaces '-'(number) to '-number'
302- if (right instanceof PrologNumeric && wrapper .getQuotingType () == PrologTerm .QuotingType .NO_QUOTED && left == null && right .getTermType () == TermType .ATOM ) {
303- if ("-" .equals (wrapper .getTermText ())) {
301+ // this code replaces '-'(number) to '-number' if number is not negative one
302+ if ("-" .equals (wrapper .getTermText ()) && left == null && right instanceof PrologNumeric ) {
303+ final PrologNumeric numeric = (PrologNumeric ) right ;
304+ if (!numeric .isNegative ()) {
304305 result = ((PrologNumeric ) right ).neg ();
305306 break ;
306307 }
Original file line number Diff line number Diff line change @@ -263,8 +263,6 @@ public void testParseInteger() {
263263 checkIntegerWithoutPPE ("0" , 0 );
264264 checkIntegerWithoutPPE ("1" , 1 );
265265 checkIntegerWithoutPPE ("1313" , 1313 );
266- checkIntegerWithoutPPE ("-0" , 0 );
267- checkIntegerWithoutPPE ("-97" , -97 );
268266 checkIntegerWithoutPPE ("-97" , -97 );
269267 checkIntegerWithoutPPE (Long .toString (Long .MAX_VALUE ), Long .MAX_VALUE );
270268
You can’t perform that action at this time.
0 commit comments