Skip to content

Commit

Permalink
refactor: minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
lppedd authored and ftomassetti committed Sep 2, 2024
1 parent 3204454 commit b56322f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public abstract class Parser(input: TokenStream) : Recognizer<Token, ParserATNSi
}

override fun exitEveryRule(ctx: ParserRuleContext) {
if (ctx.children is ArrayList<*>) {
(ctx.children as ArrayList<*>).trimToSize()
val children = ctx.children

if (children is ArrayList<*>) {
children.trimToSize()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,8 @@ public interface Token {
public fun startPoint(): Point =
Point(line, charPositionInLine)

public fun endPoint(): Point? =
if (text == null) {
null
} else {
Point(line, charPositionInLine).advance(text!!)
}
public fun endPoint(): Point? {
val text = this.text ?: return null
return Point(line, charPositionInLine).advance(text)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ public open class IterativeParseTreeWalker : ParseTreeWalker() {
// No next, sibling, so move up
currentNode = nodeStack.removeFirst()
currentIndex = indexStack.pop()
} while (currentNode != null)

// The original condition was 'currentNode != null',
// but since nodeStack.removeFirst() throws if there
// is no element, the condition is always true
} while (true)
}
}
}

0 comments on commit b56322f

Please sign in to comment.