refactor: remove offset property from position
Merge request lab2425_spring/WACC_37!16
This commit is contained in:
commit
af909b1492
@ -197,46 +197,46 @@ object ast {
|
|||||||
object Snd extends ParserBridgePos1[LValue, Snd]
|
object Snd extends ParserBridgePos1[LValue, Snd]
|
||||||
|
|
||||||
// Parser bridges
|
// Parser bridges
|
||||||
case class Position(line: Int, column: Int, offset: Int)
|
case class Position(line: Int, column: Int)
|
||||||
|
|
||||||
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)): A
|
||||||
infix def from(op: Parsley[?]): Parsley[A] = error((pos, offset).zipped(con) <~ op)
|
infix def from(op: Parsley[?]): Parsley[A] = error(pos.map(con) <~ op)
|
||||||
final def <#(op: Parsley[?]): Parsley[A] = this from op
|
final def <#(op: Parsley[?]): Parsley[A] = this from op
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ParserBridgePos0[+A] extends ParserSingletonBridgePos[A] {
|
trait ParserBridgePos0[+A] extends ParserSingletonBridgePos[A] {
|
||||||
def apply()(pos: Position): A
|
def apply()(pos: Position): A
|
||||||
|
|
||||||
override final def con(pos: (Int, Int), offset: Int): A =
|
override final def con(pos: (Int, Int)): A =
|
||||||
apply()(Position(pos._1, pos._2, offset))
|
apply()(Position(pos._1, pos._2))
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ParserBridgePos1[-A, +B] extends ParserSingletonBridgePos[A => B] {
|
trait ParserBridgePos1[-A, +B] extends ParserSingletonBridgePos[A => B] {
|
||||||
def apply(a: A)(pos: Position): B
|
def apply(a: A)(pos: Position): B
|
||||||
def apply(a: Parsley[A]): Parsley[B] = error(ap1((pos, offset).zipped(con), a))
|
def apply(a: Parsley[A]): Parsley[B] = error(ap1(pos.map(con), a))
|
||||||
|
|
||||||
override final def con(pos: (Int, Int), offset: Int): A => B =
|
override final def con(pos: (Int, Int)): A => B =
|
||||||
this.apply(_)(Position(pos._1, pos._2, offset))
|
this.apply(_)(Position(pos._1, pos._2))
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ParserBridgePos2[-A, -B, +C] extends ParserSingletonBridgePos[(A, B) => C] {
|
trait ParserBridgePos2[-A, -B, +C] extends ParserSingletonBridgePos[(A, B) => C] {
|
||||||
def apply(a: A, b: B)(pos: Position): C
|
def apply(a: A, b: B)(pos: Position): C
|
||||||
def apply(a: Parsley[A], b: => Parsley[B]): Parsley[C] = error(
|
def apply(a: Parsley[A], b: => Parsley[B]): Parsley[C] = error(
|
||||||
ap2((pos, offset).zipped(con), a, b)
|
ap2(pos.map(con), a, b)
|
||||||
)
|
)
|
||||||
|
|
||||||
override final def con(pos: (Int, Int), offset: Int): (A, B) => C =
|
override final def con(pos: (Int, Int)): (A, B) => C =
|
||||||
apply(_, _)(Position(pos._1, pos._2, offset))
|
apply(_, _)(Position(pos._1, pos._2))
|
||||||
}
|
}
|
||||||
|
|
||||||
trait ParserBridgePos3[-A, -B, -C, +D] extends ParserSingletonBridgePos[(A, B, C) => D] {
|
trait ParserBridgePos3[-A, -B, -C, +D] extends ParserSingletonBridgePos[(A, B, C) => D] {
|
||||||
def apply(a: A, b: B, c: C)(pos: Position): D
|
def apply(a: A, b: B, c: C)(pos: Position): D
|
||||||
def apply(a: Parsley[A], b: => Parsley[B], c: => Parsley[C]): Parsley[D] = error(
|
def apply(a: Parsley[A], b: => Parsley[B], c: => Parsley[C]): Parsley[D] = error(
|
||||||
ap3((pos, offset).zipped(con), a, b, c)
|
ap3(pos.map(con), a, b, c)
|
||||||
)
|
)
|
||||||
|
|
||||||
override final def con(pos: (Int, Int), offset: Int): (A, B, C) => D =
|
override final def con(pos: (Int, Int)): (A, B, C) => D =
|
||||||
apply(_, _, _)(Position(pos._1, pos._2, offset))
|
apply(_, _, _)(Position(pos._1, pos._2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user