Current section

Files

Jump to
caffeine_lang src caffeine_lang frontend token.gleam
Raw

src/caffeine_lang/frontend/token.gleam

/// A token with source position information.
pub type PositionedToken {
PositionedToken(token: Token, line: Int, column: Int)
}
/// A token produced by the tokenizer.
pub type Token {
KeywordExpectations
KeywordUnmeasured
KeywordMeasured
KeywordBy
KeywordExtends
KeywordRequires
KeywordProvides
KeywordIn
KeywordX
KeywordString
KeywordInteger
KeywordFloat
KeywordBoolean
KeywordList
KeywordDict
KeywordOptional
KeywordDefaulted
KeywordType
KeywordURL
KeywordPercentage
LiteralString(String)
LiteralInteger(Int)
LiteralFloat(Float)
LiteralPercentage(Float)
LiteralTrue
LiteralFalse
SymbolLeftBrace
SymbolRightBrace
SymbolLeftParen
SymbolRightParen
SymbolLeftBracket
SymbolRightBracket
SymbolColon
SymbolComma
SymbolStar
SymbolPipe
SymbolEquals
SymbolDotDot
WhitespaceNewline
WhitespaceIndent(Int)
CommentLine(String)
CommentSection(String)
Identifier(String)
EOF
}
/// Convert token to string for error messages.
pub fn to_string(tok: Token) -> String {
case tok {
KeywordExpectations -> "Expectations"
KeywordUnmeasured -> "Unmeasured"
KeywordMeasured -> "measured"
KeywordBy -> "by"
KeywordExtends -> "extends"
KeywordRequires -> "Requires"
KeywordProvides -> "Provides"
KeywordIn -> "in"
KeywordX -> "x"
KeywordString -> "String"
KeywordInteger -> "Integer"
KeywordFloat -> "Float"
KeywordBoolean -> "Boolean"
KeywordList -> "List"
KeywordDict -> "Dict"
KeywordOptional -> "Optional"
KeywordDefaulted -> "Defaulted"
KeywordType -> "Type"
KeywordURL -> "URL"
KeywordPercentage -> "Percentage"
LiteralString(s) -> "\"" <> s <> "\""
LiteralInteger(_) -> "integer"
LiteralFloat(_) -> "float"
LiteralPercentage(_) -> "percentage"
LiteralTrue -> "true"
LiteralFalse -> "false"
SymbolLeftBrace -> "{"
SymbolRightBrace -> "}"
SymbolLeftParen -> "("
SymbolRightParen -> ")"
SymbolLeftBracket -> "["
SymbolRightBracket -> "]"
SymbolColon -> ":"
SymbolComma -> ","
SymbolStar -> "*"
SymbolPipe -> "|"
SymbolEquals -> "="
SymbolDotDot -> ".."
WhitespaceNewline -> "newline"
WhitespaceIndent(_) -> "indent"
CommentLine(_) -> "comment"
CommentSection(_) -> "section comment"
Identifier(name) -> name
EOF -> "end of file"
}
}