feat: lexer implements ErrorConfig for improved error messages
This commit is contained in:
parent
3aae08ffd4
commit
5016fefc14
@ -4,7 +4,39 @@ import parsley.Parsley
|
|||||||
import parsley.character
|
import parsley.character
|
||||||
import parsley.token.{Basic, Lexer}
|
import parsley.token.{Basic, Lexer}
|
||||||
import parsley.token.descriptions.*
|
import parsley.token.descriptions.*
|
||||||
|
import parsley.token.errors._
|
||||||
|
import parsley.errors._
|
||||||
|
|
||||||
|
val errConfig = new ErrorConfig {
|
||||||
|
override def labelSymbol = Map(
|
||||||
|
"!=" -> Label("binary operator"),
|
||||||
|
"%" -> Label("binary operator"),
|
||||||
|
"&&" -> Label("binary operator"),
|
||||||
|
"*" -> Label("binary operator"),
|
||||||
|
"+" -> Label("binary operator"),
|
||||||
|
"-" -> Label("binary operator"),
|
||||||
|
"/" -> Label("binary operator"),
|
||||||
|
"<" -> Label("binary operator"),
|
||||||
|
"<=" -> Label("binary operator"),
|
||||||
|
"==" -> Label("binary operator"),
|
||||||
|
">" -> Label("binary operator"),
|
||||||
|
">=" -> Label("binary operator"),
|
||||||
|
"||" -> Label("binary operator"),
|
||||||
|
"!" -> Label("unary operator"),
|
||||||
|
"len" -> Label("unary operator"),
|
||||||
|
"ord" -> Label("unary operator"),
|
||||||
|
"chr" -> Label("unary operator"),
|
||||||
|
"bool" -> Label("valid type"),
|
||||||
|
"char" -> Label("valid type"),
|
||||||
|
"int" -> Label("valid type"),
|
||||||
|
"pair" -> Label("valid type"),
|
||||||
|
"string" -> Label("valid type"),
|
||||||
|
"fst" -> Label("pair extraction"),
|
||||||
|
"snd" -> Label("pair extraction"),
|
||||||
|
"false" -> Label("boolean value"),
|
||||||
|
"true" -> Label("boolean value")
|
||||||
|
)
|
||||||
|
}
|
||||||
object lexer {
|
object lexer {
|
||||||
private val desc = LexicalDesc.plain.copy(
|
private val desc = LexicalDesc.plain.copy(
|
||||||
nameDesc = NameDesc.plain.copy(
|
nameDesc = NameDesc.plain.copy(
|
||||||
@ -43,7 +75,7 @@ object lexer {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val lexer = Lexer(desc)
|
private val lexer = Lexer(desc, errConfig)
|
||||||
val ident = lexer.lexeme.names.identifier
|
val ident = lexer.lexeme.names.identifier
|
||||||
val integer = lexer.lexeme.integer.decimal32[Int]
|
val integer = lexer.lexeme.integer.decimal32[Int]
|
||||||
val negateCheck = lexer.nonlexeme.symbol("-") ~> character.digit
|
val negateCheck = lexer.nonlexeme.symbol("-") ~> character.digit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user