Compare commits

...

1 Commits

Author SHA1 Message Date
078ffa02b0 Add the at token 2024-11-26 16:19:00 -06:00
2 changed files with 14 additions and 0 deletions

View File

@ -67,6 +67,8 @@ pub enum TokenType {
Unknown,
/// The ? symbol, used for optional values.
QuestionMark,
/// The @ symbol.
At,
}
/// Most KCL tokens correspond to LSP semantic tokens (but not all).
@ -93,6 +95,7 @@ impl TryFrom<TokenType> for SemanticTokenType {
| TokenType::DoublePeriod
| TokenType::Hash
| TokenType::Dollar
| TokenType::At
| TokenType::Unknown => {
anyhow::bail!("unsupported token type: {:?}", token_type)
}

View File

@ -92,6 +92,7 @@ pub fn token(i: &mut Input<'_>) -> PResult<Token> {
'}' | ')' | ']' => brace_end,
',' => comma,
'?' => question_mark,
'@' => at,
'0'..='9' => number,
':' => colon,
'.' => alt((number, double_period, period)),
@ -268,6 +269,16 @@ fn question_mark(i: &mut Input<'_>) -> PResult<Token> {
))
}
fn at(i: &mut Input<'_>) -> PResult<Token> {
let (value, range) = '@'.with_span().parse_next(i)?;
Ok(Token::from_range(
range,
i.state.module_id,
TokenType::At,
value.to_string(),
))
}
fn colon(i: &mut Input<'_>) -> PResult<Token> {
let (value, range) = ':'.with_span().parse_next(i)?;
Ok(Token::from_range(