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
4 changes: 2 additions & 2 deletions lsp/src/analysis/scope_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ impl ASTVisitor for ScopeAnalyzer {
_max: &Expression,
incr: &Option<Token>,
statements: &[Statement],
span: Span,
_span: Span,
) {
// TODO: figure out how to have "invisible scopes"
// self.push_scope("__repeat".to_owned(), span);
// self.push_scope("__repeat".to_owned(), _span);
if let Some(incr) = incr {
self.insert_symbol(incr, Symbol::Constant { name: incr.clone() });
}
Expand Down
13 changes: 3 additions & 10 deletions lsp/src/analysis/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,8 @@ pub trait ASTVisitor {
self.visit_term(tok, expr1, expr2, expression.span)
}
ExpressionKind::Bank(expr) => self.visit_bank(expr, expression.span),
ExpressionKind::SizeOf(expr) => self.visit_sizeof(expr, expression.span),
ExpressionKind::WordOp(tok, expr) => self.visit_word_op(tok, expr, expression.span),
ExpressionKind::Match(expr1, expr2) => self.visit_match(expr1, expr2, expression.span),
ExpressionKind::Def(tok) => self.visit_def(tok, expression.span),
ExpressionKind::Identifier(ident) => self.visit_identifier(ident, expression.span),
ExpressionKind::UnnamedLabelReference(reference) => {
self.visit_unnamed_label_reference(reference, expression.span)
Expand All @@ -219,8 +217,7 @@ pub trait ASTVisitor {
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),
ExpressionKind::PseudoFunction(name, args) => self.visit_pseudo_function(name, args, expression.span),
}
}

Expand Down Expand Up @@ -298,20 +295,16 @@ pub trait ASTVisitor {
fn visit_bank(&mut self, tok: &Expression, _span: Span) {
self.visit_expression(tok);
}
fn visit_sizeof(&mut self, expr: &Expression, _span: Span) {
self.visit_expression(expr);
}
fn visit_word_op(&mut self, _tok: &Token, expr: &Expression, _span: Span) {
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) {
fn visit_pseudo_function(&mut self, _name: &Token, 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) {}
fn visit_string(&mut self, _str: &str, _span: Span) {}
Expand Down
2 changes: 1 addition & 1 deletion lsp/src/data/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ impl Files {
let mut diagnostics = vec![];
let mut includes_changed = false;
let parse_result = {
let mut file = self.get_mut(file_id);
let file = self.get_mut(file_id);
file.parse()
};

Expand Down
4 changes: 0 additions & 4 deletions parser/src/data/token_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ pub enum TokenType {
LeftBrace,
RightBrace,
Bank,
SizeOf,
Match,
Ident,
Sprintf,
Def,
UnnamedLabelReference,
Extract,
WordOp,
Expand Down
98 changes: 37 additions & 61 deletions parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,14 @@ pub enum ExpressionKind {
SimpleExpression(Token, Box<Expression>, Box<Expression>),
Term(TokenType, Box<Expression>, Box<Expression>),
Bank(Box<Expression>),
SizeOf(Box<Expression>),
Identifier(String),
Match(Box<Expression>, Box<Expression>),
Def(Token),
String(String),
Extract(Token, Box<Expression>, Box<Expression>),
TokenList(Vec<Token>),
Call(String, Vec<Expression>),
WordOp(Token, Box<Expression>),
Ident(Box<Expression>),
Sprintf(Box<Expression>, Vec<Expression>),
PseudoFunction(Token, Vec<Expression>),
}

#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -1064,17 +1061,6 @@ impl<'a> Parser<'a> {
span: Span::new(start, end),
});
}
if match_token!(self.tokens, TokenType::SizeOf) {
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::SizeOf(Box::from(expr)),
span: Span::new(start, end),
});
}
if match_token!(self.tokens, TokenType::WordOp) {
let variant = self.last();
self.consume_token(TokenType::LeftParen)?;
Expand All @@ -1100,47 +1086,9 @@ 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();
}
if match_token!(self.tokens, TokenType::Def) {
self.consume_token(TokenType::LeftParen)?;
self.tokens.advance();
let tok = self.last();
self.consume_token(TokenType::RightParen)?;
let end = self.mark_end();

return Ok(Expression {
kind: ExpressionKind::Def(tok),
span: Span::new(start, end),
});
}
if match_token!(self.tokens, TokenType::Caret) {
let right = self.parse_factor()?;
let end = self.mark_end();
Expand Down Expand Up @@ -1223,20 +1171,48 @@ impl<'a> Parser<'a> {
});
}
if check_token!(self.tokens, TokenType::Macro) {
let start = self.mark_start();
let macro_name = self.consume_token(TokenType::Macro)?.lexeme;
let end = self.mark_end();
return match macro_name.as_str() {
".asize" | ".isize" => Ok(Expression {
kind: ExpressionKind::Literal(macro_name),
span: Span::new(start, end),
}),
let next = self.tokens.peek().unwrap();

return match next.lexeme.as_str() {
".addrsize" | ".bank" | ".bankbyte" | ".blank" | ".cap" | ".capability"
| ".concat" | ".const" | ".def" | ".defined" | ".definedmacro" | ".hibyte"
| ".hiword" | ".ident" | ".ismnem" | ".ismnemonic" | ".max" | ".min" | ".ref"
| ".referenced" | ".sizeof" | ".sprintf" | ".strat" | ".string" | ".strlen" | "tcount" => {
self.parse_pseudo_function()
}
".asize" | ".isize" => {
let start = self.mark_start();
let macro_name = self.consume_token(TokenType::Macro)?.lexeme;
let end = self.mark_end();
Ok(Expression {
kind: ExpressionKind::Literal(macro_name),
span: Span::new(start, end),
})
}
_ => Err(ParseError::UnexpectedToken(self.peek()?)),
};
}
Err(ParseError::UnexpectedToken(self.peek()?))
}

fn parse_pseudo_function(&mut self) -> Result<Expression> {
let start = self.mark_start();
let macro_name = self.consume_token(TokenType::Macro)?;
self.consume_token(TokenType::LeftParen)?;
let mut args = vec![];
args.push(self.parse_expression()?);
while match_token!(self.tokens, TokenType::Comma) {
args.push(self.parse_expression()?);
}
self.consume_token(TokenType::RightParen)?;
let end = self.mark_end();

Ok(Expression {
kind: ExpressionKind::PseudoFunction(macro_name, args),
span: Span::new(start, end),
})
}

fn parse_macro_parameters(&mut self) -> Result<Vec<MacroParameter>> {
let mut parameters = vec![];
if !check_token!(self.tokens, TokenType::EOL) {
Expand Down
4 changes: 0 additions & 4 deletions parser/src/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,10 @@ impl<'a> Tokenizer<'a> {
".xor" => self.make_token(TokenType::Xor),
".not" => self.make_token(TokenType::Not),
".bank" => self.make_token(TokenType::Bank),
".sizeof" => self.make_token(TokenType::SizeOf),
".loword" | ".hiword" | ".bankbyte" | ".lobyte" | ".hibyte" => {
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