Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion lsp/src/analysis/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ pub trait ASTVisitor {
ExpressionKind::TokenList(toks) => self.visit_token_list(toks, expression.span),
ExpressionKind::Call(callee, arguments) => {
self.visit_call(callee, arguments, expression.span)
}
},
ExpressionKind::Ident(expr) => self.visit_ident(expr, expression.span),
ExpressionKind::Sprintf(str, args) => self.visit_sprintf(str, args, expression.span),
}
}

Expand Down Expand Up @@ -303,6 +305,12 @@ pub trait ASTVisitor {
self.visit_expression(expr);
}
fn visit_match(&mut self, _expr1: &Expression, _expr2: &Expression, _span: Span) {}
fn visit_ident(&mut self, _ident: &Expression, _span: Span) {}
fn visit_sprintf(&mut self, _str: &Expression, args: &[Expression], _span: Span) {
for arg in args.iter() {
self.visit_expression(arg);
}
}
fn visit_def(&mut self, _tok: &Token, _span: Span) {}
fn visit_identifier(&mut self, _ident: &str, _span: Span) {}
fn visit_unnamed_label_reference(&mut self, _reference: &i8, _span: Span) {}
Expand Down
2 changes: 2 additions & 0 deletions parser/src/data/token_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ pub enum TokenType {
Bank,
SizeOf,
Match,
Ident,
Sprintf,
Def,
UnnamedLabelReference,
Extract,
Expand Down
28 changes: 28 additions & 0 deletions parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ pub enum ExpressionKind {
TokenList(Vec<Token>),
Call(String, Vec<Expression>),
WordOp(Token, Box<Expression>),
Ident(Box<Expression>),
Sprintf(Box<Expression>, Vec<Expression>),
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -1098,6 +1100,32 @@ impl<'a> Parser<'a> {
span: Span::new(start, end),
});
}
if match_token!(self.tokens, TokenType::Ident) {
self.consume_token(TokenType::LeftParen)?;
let expr = self.parse_expression()?;
self.consume_token(TokenType::RightParen)?;
let end = self.mark_end();

return Ok(Expression {
kind: ExpressionKind::Ident(Box::from(expr)),
span: Span::new(start, end),
});
}
if match_token!(self.tokens, TokenType::Sprintf) {
self.consume_token(TokenType::LeftParen)?;
let expr = self.parse_expression()?;
let mut args = vec![];
while match_token!(self.tokens, TokenType::Comma) {
args.push(self.parse_expression()?);
}
self.consume_token(TokenType::RightParen)?;
let end = self.mark_end();

return Ok(Expression {
kind: ExpressionKind::Sprintf(Box::from(expr), args),
span: Span::new(start, end),
});
}
if match_token!(self.tokens, TokenType::Extract) {
return self.parse_extract();
}
Expand Down
2 changes: 2 additions & 0 deletions parser/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ impl<'a> Tokenizer<'a> {
self.make_token(TokenType::WordOp)
}
".match" | ".xmatch" => self.make_token(TokenType::Match),
".ident" => self.make_token(TokenType::Ident),
".sprintf" => self.make_token(TokenType::Sprintf),
".def" | ".defined" => self.make_token(TokenType::Def),
".left" | ".mid" | ".right" => self.make_token(TokenType::Extract),
_ => self.make_token(TokenType::Macro),
Expand Down
Loading