From b194d980304cd7f0ac2d597fe749d9e1033eae87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Sat, 2 Nov 2024 01:37:50 +0800 Subject: [PATCH] feat: Add more token --- lib/src/parser/lexer.rs | 9 ++++++++- lib/src/parser/token.rs | 6 ++++++ lsp/src/lsp.rs | 5 +++++ lsp/src/lsp_types.rs | 4 ++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/src/parser/lexer.rs b/lib/src/parser/lexer.rs index 8b7a1a6..0c6d10d 100644 --- a/lib/src/parser/lexer.rs +++ b/lib/src/parser/lexer.rs @@ -202,7 +202,9 @@ impl StLexerBuilder { TokenKind::Byte, TokenKind::Real, TokenKind::LReal, - TokenKind::Array + TokenKind::Array, + TokenKind::Adr, + TokenKind::SizeOf ]; self.keywords = keywords; @@ -448,6 +450,11 @@ impl<'input> StLexer<'input> { TokenKind::Identifier(st_str) } + // literal with type annotation prefix, like: int#123 or lreal#1.234e1 + fn type_annotation_literal(&mut self) -> TokenKind { + todo!() + } + fn is_valid_identifier_character(&self, ch: char) -> bool { if self.options.allow_unicode_identifier { ch.is_alphabetic() || ch.is_ascii_alphanumeric() || matches!(ch, '_') diff --git a/lib/src/parser/token.rs b/lib/src/parser/token.rs index 79a93f3..c473d8a 100644 --- a/lib/src/parser/token.rs +++ b/lib/src/parser/token.rs @@ -157,6 +157,10 @@ pub enum TokenKind { Type, /// 'END_TYPE' EndType, + /// 'SizeOf' Operator + SizeOf, + /// 'Adr' Operator + Adr, /// 'BIT', one bit type Bit, /// 'BOOL', boolean type @@ -329,6 +333,8 @@ impl From<&TokenKind> for String { TokenKind::Persistent => "PERSISTENT", TokenKind::Type => "TYPE", TokenKind::EndType => "END_TYPE", + TokenKind::SizeOf => "SIZEOF", + TokenKind::Adr => "ADR", TokenKind::Int => "INT", TokenKind::Real => "REAL", TokenKind::LReal => "LREAL", diff --git a/lsp/src/lsp.rs b/lsp/src/lsp.rs index d025258..fd1c199 100644 --- a/lsp/src/lsp.rs +++ b/lsp/src/lsp.rs @@ -18,6 +18,11 @@ fn semantic_token_type_id(tok: &TokenKind) -> (u32, u32) { op if op.is_operator() => (TokenTypes::Operator as u32, TokenModifiers::None as u32), // builtin-types TokenKind::Int => (TokenTypes::Type as u32, TokenModifiers::None as u32), + // builtin-operators + TokenKind::SizeOf | TokenKind::Adr => ( + TokenTypes::BuiltinFunction as u32, + TokenModifiers::None as u32, + ), // keywords TokenKind::If | TokenKind::Then diff --git a/lsp/src/lsp_types.rs b/lsp/src/lsp_types.rs index 126ae3b..baac807 100644 --- a/lsp/src/lsp_types.rs +++ b/lsp/src/lsp_types.rs @@ -34,6 +34,8 @@ impl From for SemanticTokenType { pub enum TokenModifiers { None, Static, + Global, + Declare, } impl From for SemanticTokenModifier { @@ -41,6 +43,8 @@ impl From for SemanticTokenModifier { match value { TokenModifiers::None => SemanticTokenModifier::new("none"), TokenModifiers::Static => SemanticTokenModifier::STATIC, + TokenModifiers::Global => SemanticTokenModifier::new("global"), + TokenModifiers::Declare => SemanticTokenModifier::DECLARATION, } } }