Skip to content

Commit

Permalink
feat: Add more token
Browse files Browse the repository at this point in the history
  • Loading branch information
sbwtw committed Nov 1, 2024
1 parent 5727dba commit b194d98
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ impl StLexerBuilder {
TokenKind::Byte,
TokenKind::Real,
TokenKind::LReal,
TokenKind::Array
TokenKind::Array,
TokenKind::Adr,
TokenKind::SizeOf
];

self.keywords = keywords;
Expand Down Expand Up @@ -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, '_')
Expand Down
6 changes: 6 additions & 0 deletions lib/src/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions lsp/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lsp/src/lsp_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ impl From<TokenTypes> for SemanticTokenType {
pub enum TokenModifiers {
None,
Static,
Global,
Declare,
}

impl From<TokenModifiers> for SemanticTokenModifier {
fn from(value: TokenModifiers) -> Self {
match value {
TokenModifiers::None => SemanticTokenModifier::new("none"),
TokenModifiers::Static => SemanticTokenModifier::STATIC,
TokenModifiers::Global => SemanticTokenModifier::new("global"),
TokenModifiers::Declare => SemanticTokenModifier::DECLARATION,
}
}
}

0 comments on commit b194d98

Please sign in to comment.