me.tomassetti.kolasu.mapping.Mapping.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kolasu Show documentation
Show all versions of kolasu Show documentation
Framework to support building languages with Kotlin
package me.tomassetti.kolasu.mapping
import me.tomassetti.kolasu.model.Node
import me.tomassetti.kolasu.model.Point
import me.tomassetti.kolasu.model.Position
import org.antlr.v4.runtime.ParserRuleContext
import org.antlr.v4.runtime.Token
interface ParseTreeToAstMapper {
fun map(parseTreeNode: PTN) : ASTN
}
fun Token.startPoint() = Point(line, charPositionInLine)
fun Token.endPoint() = Point(line, charPositionInLine + text.length)
fun ParserRuleContext.toPosition(considerPosition: Boolean) : Position? {
return if (considerPosition) Position(start.startPoint(), stop.endPoint()) else null
}