refactor: add position tracking to AST, UnaryOp, BinaryOp #7

Merged
gk1623 merged 3 commits from ast-position-tracking into master 2025-02-05 17:42:59 +00:00
2 changed files with 192 additions and 109 deletions
Showing only changes of commit 539403fd36 - Show all commits

View File

@@ -183,13 +183,6 @@ object ast {
// Parser bridges // Parser bridges
case class Position(line: Int, column: Int, offset: Int) case class Position(line: Int, column: Int, offset: Int)
private def applyCon[A, B](
con: ((Int, Int), Int, Int) => A => B
)(ops: => Parsley[A]): Parsley[B] =
(pos, offset, withWidth(ops)).zipped.map { (pos, off, res) =>
con(pos, off, res._2)(res._1)
}
trait ParserSingletonBridgePos[+A] extends ErrorBridge { trait ParserSingletonBridgePos[+A] extends ErrorBridge {
protected def con(pos: (Int, Int), offset: Int): A protected def con(pos: (Int, Int), offset: Int): A
infix def from(op: Parsley[?]): Parsley[A] = error((pos, offset).zipped(con) <~ op) infix def from(op: Parsley[?]): Parsley[A] = error((pos, offset).zipped(con) <~ op)