Lexer for the MoonBit programming language
///|
test "tokenize source text" {
let result = @lexer.tokens_from_string("let answer = 42", comment=false)
assert_eq(result.errors.length(), 0)
debug_inspect(
result.tokens.map(triple => triple.0),
content=(
#|[LET, LIDENT("answer"), EQUAL, INT("42"), EOF]
),
)
}///|
test "utf16 location mode keeps the same tokens" {
let source = "let x = \"😀\""
let normal = @lexer.tokens_from_string(source, comment=false)
let utf16 = @lexer.tokens_from_string_with_utf16_location(
source,
comment=false,
)
debug_inspect(
normal.tokens.map(triple => triple.0),
content=(
#|[LET, LIDENT("x"), EQUAL, STRING("😀"), EOF]
),
)
debug_inspect(
utf16.tokens.map(triple => triple.0),
content=(
#|[LET, LIDENT("x"), EQUAL, STRING("😀"), EOF]
),
)
}pub enum LexicalError {
IllegalCharacter(Char)
UnterminatedString
UnterminatedStringInVariableInterploation
InterpInvalidMultilineString
InterpInvalidComment
InterpInvalidAttribute
InterpMissingExpression
InvalidDotInt(String)
MissingIdentifierAfterDot
InvalidByteLiteral(String)
Reserved_keyword(String)
InvalidMetavarSyntax(String)
}impl Show for LexicalErrorLexer for the MoonBit programming language