|
32 | 32 | import com.igormaznitsa.prologparser.tokenizer.OpAssoc; |
33 | 33 | import com.igormaznitsa.prologparser.tokenizer.TermWrapper; |
34 | 34 | import com.igormaznitsa.prologparser.utils.SoftObjectPool; |
35 | | - |
36 | 35 | import java.util.ArrayList; |
37 | 36 |
|
38 | 37 | final class AstItem { |
@@ -135,27 +134,19 @@ public TermType getType() { |
135 | 134 |
|
136 | 135 | public AstItem findRoot() { |
137 | 136 | AstItem result = this; |
138 | | - while (!Thread.currentThread().isInterrupted()) { |
139 | | - final AstItem theParent = result.parentItem; |
140 | | - if (theParent == null) { |
141 | | - break; |
142 | | - } else { |
143 | | - result = theParent; |
144 | | - } |
| 137 | + AstItem theParent; |
| 138 | + while ((theParent = result.parentItem) != null) { |
| 139 | + result = theParent; |
145 | 140 | } |
146 | 141 | return result; |
147 | 142 | } |
148 | 143 |
|
149 | 144 | public AstItem findFirstNodeWithSuchOrLowerPrecedence(final int precedence) { |
150 | 145 | AstItem result = this; |
151 | 146 |
|
152 | | - while (!Thread.currentThread().isInterrupted()) { |
153 | | - final AstItem itsParent = result.parentItem; |
154 | | - if (itsParent == null || result.getPrecedence() >= precedence) { |
155 | | - break; |
156 | | - } else { |
157 | | - result = itsParent; |
158 | | - } |
| 147 | + AstItem itsParent; |
| 148 | + while ((itsParent = result.parentItem) != null && result.getPrecedence() < precedence) { |
| 149 | + result = itsParent; |
159 | 150 | } |
160 | 151 |
|
161 | 152 | return result; |
@@ -271,17 +262,17 @@ public PrologTerm convertToTermAndRelease() { |
271 | 262 | if (operator.getArity() == terms.length) { |
272 | 263 | return new PrologStruct(operator, terms, wrapper.getLine(), wrapper.getPos()); |
273 | 264 | } else { |
274 | | - final Op appropriateOperator = this.parser.getContext().findOpForName(this.parser, operator.getText()).findForArity(terms.length); |
275 | | - |
276 | | - if (appropriateOperator == null) { |
277 | | - if (operator.getArity() == 1) { |
278 | | - return new PrologStruct(operator, new PrologTerm[]{blockContent}, wrapper.getLine(), wrapper.getPos()); |
279 | | - } else { |
280 | | - return new PrologStruct(new PrologAtom(wrapper.getText(), Quotation.SINGLE, wrapper.getLine(), wrapper.getPos()), terms, wrapper.getLine(), wrapper.getPos()); |
281 | | - } |
| 265 | + final Op appropriateOperator = this.parser.getContext().findOpForName(this.parser, operator.getText()).findForArity(terms.length); |
| 266 | + |
| 267 | + if (appropriateOperator == null) { |
| 268 | + if (operator.getArity() == 1) { |
| 269 | + return new PrologStruct(operator, new PrologTerm[]{blockContent}, wrapper.getLine(), wrapper.getPos()); |
282 | 270 | } else { |
283 | | - return new PrologStruct(appropriateOperator, terms, wrapper.getLine(), wrapper.getPos()); |
| 271 | + return new PrologStruct(new PrologAtom(wrapper.getText(), Quotation.SINGLE, wrapper.getLine(), wrapper.getPos()), terms, wrapper.getLine(), wrapper.getPos()); |
284 | 272 | } |
| 273 | + } else { |
| 274 | + return new PrologStruct(appropriateOperator, terms, wrapper.getLine(), wrapper.getPos()); |
| 275 | + } |
285 | 276 | } |
286 | 277 |
|
287 | 278 | } else { |
@@ -347,8 +338,8 @@ public PrologTerm convertToTermAndRelease() { |
347 | 338 | final PrologTerm thatTerm = thisStruct.getTermAt(0); |
348 | 339 |
|
349 | 340 | if (thatTerm.getType() == TermType.STRUCT && (thatTerm.getFunctor() == Op.VIRTUAL_OPERATOR_BLOCK || thatTerm.getFunctor() == Op.VIRTUAL_OPERATOR_CURLY_BLOCK)) { |
350 | | - // rolling normal blocks |
351 | | - result = thatTerm.isBlock() && (this.isBlock()&& (this.parentItem == null || (this.parentItem != null && this.parentItem.isBlock()))) ? thatTerm : thisStruct; |
| 341 | + // rolling normal blocks |
| 342 | + result = thatTerm.isBlock() && (this.isBlock() && (this.parentItem == null || (this.parentItem != null && this.parentItem.isBlock()))) ? thatTerm : thisStruct; |
352 | 343 | } else { |
353 | 344 | result = thisStruct; |
354 | 345 | } |
|
0 commit comments