Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
NTTVy03 committed Jan 6, 2025
1 parent e5a8c45 commit b081735
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 41 deletions.
5 changes: 2 additions & 3 deletions crates/lsp/src/global_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ impl GlobalState {
return result;
}


// if can not find that token in current file,
// and if token in a component call / declaration
// continue looking up in libs
Expand Down Expand Up @@ -118,7 +117,7 @@ impl GlobalState {
// path to the element we want to get definition
// TODO eg: file/line/start column..end column
let uri = params.text_document_position_params.text_document.uri;

// abtract syntax tree for the element from that uri
// TODO eg:
let ast = self.ast_map.get(&uri.to_string()).unwrap();
Expand All @@ -129,7 +128,7 @@ impl GlobalState {
let mut locations = Vec::new();

// extract token from ast at position (file, params position)
// TODO eg:
// TODO eg:
if let Some(token) =
lookup_token_at_postion(&file, &ast, params.text_document_position_params.position)
{
Expand Down
6 changes: 3 additions & 3 deletions crates/lsp/src/handler/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn lookup_definition(
return jump_to_lib(file, token);
}

// signal from other template
// signal from other template
// eg: in1, in2 from component call mul(in1, in2)
let mut signal_outside = false;

Expand Down Expand Up @@ -141,7 +141,7 @@ pub fn lookup_definition(
}

if !signal_outside {
// look up token in template information
// look up token in template information
// (template name, signal/variable/component in template)
for template in template_list {
let template_name = template.name().unwrap();
Expand Down Expand Up @@ -173,7 +173,7 @@ pub fn lookup_definition(
}
}

// TODO: look up token in function information
// TODO: look up token in function information
// (function name, signal/variable/component in function)
}

Expand Down
5 changes: 4 additions & 1 deletion crates/parser/src/grammar/declaration.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::{expression::expression, list::{tuple_expression, tuple_identifier}};
use super::{
expression::expression,
list::{tuple_expression, tuple_identifier},
};
use crate::{parser::Parser, token_kind::TokenKind::*};

// [N][M-1]
Expand Down
21 changes: 9 additions & 12 deletions crates/parser/src/grammar/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ fn circom_expression(p: &mut Parser) {

/**
* grammar: <condition> ? <expression-1> : <expression-2>
* <condition> is also an expression,
* <condition> is also an expression,
* whose open and close events are already in the Parser event list
* lhs is that open event
*/
pub fn tenary_conditional_statement(p: &mut Parser, lhs: Marker) {
// <condition>
let open_marker = p.open_before(lhs);
p.close(open_marker, Condition);

// <condition> ?
p.expect(MarkQuestion);

// <condition> ? <expression-1>
let first_expression = p.open();
expression_rec(p, 0);
p.close(first_expression, Expression);

// <condition> ? <expression-1> :
p.expect(Colon);

// <condition> ? <expression-1> : <expression-2>
let last_expression = p.open();
expression_rec(p, 0);
Expand Down Expand Up @@ -102,7 +102,6 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option<Marker> {
expression_rec(p, lp);

lhs = p.close(open_marker, kind);

} else if let Some(pp) = kind.postfix() {
if pp <= pb {
return None;
Expand Down Expand Up @@ -143,8 +142,7 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option<Marker> {
break;
}
};
}
else {
} else {
break;
}
}
Expand All @@ -159,14 +157,14 @@ pub fn expression_rec(p: &mut Parser, pb: u16) -> Option<Marker> {
*/
fn expression_atom(p: &mut Parser) -> Option<Marker> {
let kind = p.current();

match kind {
Number | Identifier => {
let open_marker = p.open();
p.advance();
let m_close = p.close(open_marker, kind);
Some(m_close)
},
}
LParen => {
// (<expression>)
let open_marker = p.open();
Expand All @@ -175,11 +173,10 @@ fn expression_atom(p: &mut Parser) -> Option<Marker> {
p.expect(RParen);
let m_close = p.close(open_marker, Expression);
Some(m_close)
},
}
_ => {
p.advance_with_error("Invalid Token");
None
}
}
}

2 changes: 1 addition & 1 deletion crates/parser/src/grammar/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn function_parse(p: &mut Parser) {
let parameter_marker = p.open();
tuple_identifier(p);
p.close(parameter_marker, ParameterList);

block::block(p);

p.close(m, FunctionDef);
Expand Down
13 changes: 5 additions & 8 deletions crates/parser/src/grammar/list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::grammar::{
*,
expression::expression
};
use crate::grammar::{expression::expression, *};

/**
* grammar: "(expression-1, expression-2,..., expression-n)"
Expand All @@ -22,7 +19,7 @@ pub(super) fn tuple_expression(p: &mut Parser) {
}

p.expect(RParen);

// p.close(m, ExpressionList);
}

Expand All @@ -37,7 +34,7 @@ pub(super) fn tuple_identifier(p: &mut Parser) {
// iden1, iden2, iden3
while p.at(Identifier) && !p.eof() {
p.expect(Identifier);

if p.eat(Comma) == false {
break;
}
Expand All @@ -58,12 +55,12 @@ pub(super) fn list_identifier(p: &mut Parser) {
// iden1, iden2, iden3
while p.at(Identifier) && !p.eof() {
p.expect(Identifier);

if p.eat(Comma) == false {
break;
}
}

p.expect(RBracket);
// p.close(m, IdentifierList);
}
}
2 changes: 1 addition & 1 deletion crates/parser/src/grammar/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn for_statement(p: &mut Parser) {

// for (i = 1; i < N; i++) { <statements> }
statement(p);

p.close(open_marker, ForLoop);
}

Expand Down
18 changes: 8 additions & 10 deletions crates/parser/src/token_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ impl TokenKind {
| Self::GreaterThan
| Self::LessThanAndEqual
| Self::GreaterThanAndEqual => Some((79, 80)),
Self::Equal
| Self::NotEqual => Some((74, 75)),
Self::Equal | Self::NotEqual => Some((74, 75)),
// other bitwise operators
Self::BitAnd => Some((69, 70)),
Self::BitXor => Some((64, 65)), // exclusive or
Expand All @@ -298,10 +297,10 @@ impl TokenKind {
Self::BoolOr => Some((49, 50)),
// ----------
// TODO: how about conditional operation ( ? : )
// associativity: right to left [ a ? b : c --> ??? ]
// associativity: right to left [ a ? b : c --> ??? ]

// ----------
// associativity: right to left [ a = b = c --> a = (b = c) ]
// associativity: right to left [ a = b = c --> a = (b = c) ]
// DO NOT CONSIDER ASSIGMENT OPERATORS AS INFIX TOKENS
/*
// assignment operators
Expand Down Expand Up @@ -389,10 +388,9 @@ impl TokenKind {
| Self::DivAssign
| Self::IntDivAssign
| Self::ModAssign
| Self::PowerAssign
// unit inc/dec
// | Self::UnitInc
// | Self::UnitDec
| Self::PowerAssign // unit inc/dec
// | Self::UnitInc
// | Self::UnitDec
)
}

Expand All @@ -413,4 +411,4 @@ impl TokenKind {
Self::WhiteSpace | Self::EndLine | Self::CommentLine | Self::BlockComment | Self::Error
)
}
}
}
7 changes: 5 additions & 2 deletions crates/syntax/src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ mod tests {
mod grammar_tests {

use crate::{
abstract_syntax_tree::{AstBlock, AstCircomProgram, AstOutputSignalDecl, AstPragma, AstTemplateDef},
abstract_syntax_tree::{
AstBlock, AstCircomProgram, AstOutputSignalDecl, AstPragma, AstTemplateDef,
},
syntax::SyntaxTreeBuilder,
syntax_node::CircomLanguage,
};
Expand Down Expand Up @@ -533,7 +535,8 @@ mod grammar_tests {
let syntax = syntax_node_from_source(&source, Scope::CircomProgram);

// cast syntax node into ast node to retrieve more information
let ast_circom = AstCircomProgram::cast(syntax).expect("Can not cast syntax node into ast circom");
let ast_circom =
AstCircomProgram::cast(syntax).expect("Can not cast syntax node into ast circom");
let function = &ast_circom.function_list()[0];

let string_function = function.syntax().text().to_string();
Expand Down

0 comments on commit b081735

Please sign in to comment.