Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update tests and fix bugs in parser #64

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5f66905
skip trivial first tokens in parsing
NTTVy03 Nov 9, 2024
6913c55
remove comment in input test
NTTVy03 Nov 13, 2024
b2a750f
Merge branch 'master' of https://github.com/vuvoth/ccls
NTTVy03 Nov 18, 2024
caac481
manage out-of-bound case, update input test
NTTVy03 Nov 18, 2024
8efa4f7
update input test
NTTVy03 Nov 18, 2024
c78761e
update input test
NTTVy03 Dec 6, 2024
bfd1f15
make test programs private
NTTVy03 Dec 8, 2024
e054b57
remove comments in syntax tests
NTTVy03 Dec 8, 2024
15c9e5f
format
NTTVy03 Dec 8, 2024
c76246b
make Pragma optional, remove ROOT
NTTVy03 Dec 8, 2024
cd125ab
rename close() params, use advance() in eat(), fix typo scope
NTTVy03 Dec 8, 2024
15470b1
parse params using list_identity
NTTVy03 Dec 8, 2024
6dbb51a
return Option in token_value() and position_of()
NTTVy03 Dec 10, 2024
6d5f0c6
do not allow <--, <== in var declaration
NTTVy03 Dec 10, 2024
fbdc5b9
make public signal optional in main component
NTTVy03 Dec 10, 2024
07c4171
fix format before merge
NTTVy03 Dec 13, 2024
0bf3a04
remove empty test
NTTVy03 Dec 17, 2024
f1b0c39
replace expect by eat in block
NTTVy03 Dec 17, 2024
a10be25
add scope parsing test
NTTVy03 Dec 17, 2024
47df964
fix space in scope parsing test
NTTVy03 Dec 17, 2024
5c6cb56
update snapshot test for syntax
NTTVy03 Dec 19, 2024
372efd3
refactor syntax test
NTTVy03 Dec 19, 2024
46929c2
update input tests with snapshot
NTTVy03 Dec 20, 2024
d811037
change param type in find signal into str
NTTVy03 Dec 25, 2024
cafff02
add snapshot guild
NTTVy03 Dec 27, 2024
03da99a
add some combine arithmetic operators
NTTVy03 Dec 27, 2024
7792a96
error report in expect and expect_any
NTTVy03 Dec 27, 2024
6ac9ac9
update snapshot for combine operators
NTTVy03 Dec 27, 2024
ec73df8
update snapshot test
NTTVy03 Dec 28, 2024
5bdda2f
fix wrap trivial tokens before open a tree
NTTVy03 Dec 28, 2024
8e4853d
update template happy test
NTTVy03 Dec 28, 2024
bb95297
add operators into token kinds
NTTVy03 Dec 28, 2024
6949ca6
Merge branch 'fix-parser' into master
NTTVy03 Dec 30, 2024
7753149
Merge pull request #1 from vuvoth/master
NTTVy03 Dec 30, 2024
97bb689
add operators test
NTTVy03 Dec 30, 2024
179f6bc
re-priority token kinds
NTTVy03 Dec 30, 2024
40268bf
fix clippy check
NTTVy03 Dec 30, 2024
156b872
fix clippy check
NTTVy03 Dec 30, 2024
d18fba0
rebase add-token-kinds
NTTVy03 Dec 30, 2024
84e960b
fix clippy check
NTTVy03 Dec 30, 2024
d9f369e
Merge branch 'master' of https://github.com/NTTVy03/ccls
NTTVy03 Dec 30, 2024
a1bd25e
fix clippy
NTTVy03 Dec 30, 2024
3a08797
remove duplicate declaration in grammar tests
NTTVy03 Dec 30, 2024
db81682
remove duplicate else in comment
NTTVy03 Jan 1, 2025
e61edb2
replace eat by expect for curly in block
NTTVy03 Jan 1, 2025
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: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ node_modules
.vscode-test
/target
Cargo.lock
assets
assets
*.new
*.pending-snap
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ syntax = {path = './crates/syntax', version = "0.1.0"}
circom-lsp = {path = './crates/lsp', version = "*"}
common = { path = './crates/common', version = "*"}
database = {path = "./crates/database", version = "*"}

[workspace.package]
rust-version = "1.71"
11 changes: 11 additions & 0 deletions SNAPSHOT_TEST.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Snapshot Test

* Run all tests:
```
cargo test
```

* Review snapshot changes
```
cargo insta review
```
13 changes: 11 additions & 2 deletions crates/parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ lsp-types = {version = "0.94.1", features = ["proposed"]}
rowan = "0.15.15"
num-traits = "0.2"
num-derive = "0.2"

serde = "1.0.216"

[profile.dev]
debug = 2
debug = 2

[dev-dependencies]
# for snapshot testing, yaml format
insta = { version = "1.41.1", features = ["yaml"] }

[profile.dev.package]
# compile slightly slower once, but use less memory, have faster diffs
insta.opt-level = 3
similar.opt-level = 3
3 changes: 2 additions & 1 deletion crates/parser/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::token_kind::TokenKind;

#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone)]
pub enum Event {
Open { kind: TokenKind },
Close,
TokenPosition(usize),
ErrorReport(String),
}
10 changes: 9 additions & 1 deletion crates/parser/src/grammar/block.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
use super::*;

/*
{
<declaration>/<statement>
<declaration>/<statement>
....
<declaration>/<statement>
}
*/
pub fn block(p: &mut Parser) {
p.inc_rcurly();

if !p.at(LCurly) {
p.advance_with_error("Miss {");
} else {
let m = p.open();
p.eat(LCurly);
p.expect(LCurly);
let stmt_marker = p.open();
while !p.at(RCurly) && !p.eof() {
let kind = p.current();
Expand Down
6 changes: 0 additions & 6 deletions crates/parser/src/grammar/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,3 @@ pub(super) fn declaration(p: &mut Parser) {
_ => unreachable!(),
}
}

#[cfg(test)]
mod declar_tests {
#[test]
fn signal_with_tag() {}
}
22 changes: 0 additions & 22 deletions crates/parser/src/grammar/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,25 +156,3 @@ fn circom_expression(p: &mut Parser) {
}
}
}
// #[cfg(test)]
// mod tests {

// use rowan::SyntaxNode;

// use crate::{syntax_node::CircomLang};

// use super::{entry::Scope, Parser};

// #[test]
// fn test_expression() {
// let source = r#"
// {
// a.tmp <== 100;
// b[1].c <== 10;
// }
// "#;
// let green = Parser::parse_scope(source, Scope::Block);
// let node = SyntaxNode::<CircomLang>::new_root(green);
// println!("{:#?}", node);
// }
// }
23 changes: 0 additions & 23 deletions crates/parser/src/grammar/pragma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,3 @@ pub fn pragma(p: &mut Parser) {
p.expect(Semicolon);
p.close(m, Pragma);
}

// #[cfg(test)]
// mod tests {
// #[test]
// fn pragam_test() {
// use crate::{
// ast::{AstNode, AstPragma},
// syntax_node::SyntaxNode,
// token_kind::TokenKind,
// };

// use super::{entry::Scope, Parser};

// let source: String = r#"pragma circom 2.0.1;"#.to_string();

// let green_node = Parser::parse_scope(&source, Scope::Pragma);
// let node = SyntaxNode::new_root(green_node);

// let pragma = AstPragma::cast(node.last_child().unwrap()).unwrap();

// assert!(pragma.version().unwrap().syntax().kind() == TokenKind::Version);
// }
// }
44 changes: 27 additions & 17 deletions crates/parser/src/grammar/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ pub(super) fn statement(p: &mut Parser) {
p.close(m, Statement);
}

/*
if (expr)
<statement>
else
<statement>
*/
fn if_statement(p: &mut Parser) {
let m = p.open();
p.expect(IfKw);
Expand All @@ -25,6 +31,7 @@ fn if_statement(p: &mut Parser) {

/**
* no if condition here.
* for/while/return/assert...
*/
fn statement_no_condition(p: &mut Parser) {
match p.current() {
Expand All @@ -50,6 +57,10 @@ fn statement_no_condition(p: &mut Parser) {
}
}

/*
for (<declaration>/<assignment>; <expression>; <assignment>)
<statement>
*/
fn for_statement(p: &mut Parser) {
let m = p.open();
p.expect(ForKw);
Expand All @@ -70,6 +81,10 @@ fn for_statement(p: &mut Parser) {
p.close(m, ForLoop);
}

/*
while (<expression>)
<statement>
*/
fn while_statement(p: &mut Parser) {
p.expect(WhileKw);
p.expect(LParen);
Expand All @@ -78,6 +93,9 @@ fn while_statement(p: &mut Parser) {
statement(p);
}

/*
assert(<expression>)
*/
fn assert_statement(p: &mut Parser) {
let m = p.open();
p.expect(AssertKw);
Expand All @@ -87,6 +105,9 @@ fn assert_statement(p: &mut Parser) {
p.close(m, AssertKw);
}

/*
log()
*/
fn log_statement(p: &mut Parser) {
let m = p.open();
p.expect(LogKw);
Expand All @@ -109,13 +130,19 @@ fn log_statement(p: &mut Parser) {
p.close(m, LogKw);
}

/*
return <expression>
*/
fn return_statement(p: &mut Parser) {
let m = p.open();
p.expect(ReturnKw);
expression(p);
p.close(m, ReturnKw);
}

/*

*/
fn assignment_statement(p: &mut Parser) {
let m = p.open();

Expand Down Expand Up @@ -155,20 +182,3 @@ fn assignment_statement(p: &mut Parser) {
p.close(m, Error);
}
}

#[cfg(test)]
mod tests {

#[test]
fn if_statement_test() {
let _source = r#"
assert(1 == 2);
"#;
// let mut parser = Parser::new(source);

// statement(&mut parser);
// let cst = parser.build_tree().ok().unwrap();

// println!("{:?}", cst);
}
}
39 changes: 0 additions & 39 deletions crates/parser/src/grammar/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,3 @@ pub fn template(p: &mut Parser) {

p.close(m, TemplateDef);
}

// #[cfg(test)]
// mod tests {
// use crate::ast::AstTemplateDef;

// #[test]
// fn template_parse_test() {
// use crate::{ast::AstNode, syntax_node::SyntaxNode};

// use super::{entry::Scope, Parser};

// let source: String = r#"
// template Multiplier2 (a, b, c) {

// // Declaration of signals.
// signal input a;
// signal input b;
// signal output c;

// // Constraints.
// c <== a * b;
// }

// "#
// .to_string();

// let green_node = ::parse_scope(&source, Scope::Template);
// let node = SyntaxNode::new_root(green_node);

// let ast_template = AstTemplateDef::cast(node);

// if let Some(ast_internal) = ast_template {
// println!(
// "name {:?}",
// ast_internal.template_name().unwrap().syntax().text()
// );
// }
// }
// }
Loading
Loading