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

Fix some parser bugs #62

Merged
merged 16 commits into from
Dec 13, 2024
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
30 changes: 7 additions & 23 deletions crates/parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,14 @@ pub mod entry {
p.skip();
}

pragma::pragma(p);
while !p.eof() {
match p.current() {
TemplateKw => {
template::template(p);
}
IncludeKw => {
include::include(p);
}
Pragma => pragma::pragma(p),
TemplateKw => template::template(p),
IncludeKw => include::include(p),
ComponentKw => main_component::main_component(p),
FunctionKw => function::function_parse(p),
_ => {
p.advance_with_error("invalid token");
}
_ => p.advance_with_error("invalid token"),
}
}
p.close(m, CircomProgram);
Expand All @@ -63,20 +57,10 @@ pub mod entry {
impl Scope {
pub fn parse(self, p: &mut Parser) {
match self {
Self::Block => {
let m = p.open();
block::block(p);
p.close(m, ROOT);
}
Self::Block => block::block(p),
Self::CircomProgram => circom_program(p),
Self::Pragma => {
let m = p.open();
pragma::pragma(p);
p.close(m, ROOT);
}
Self::Template => {
template::template(p);
}
Self::Pragma => pragma::pragma(p),
Self::Template => template::template(p),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/parser/src/grammar/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

pub fn block(p: &mut Parser) {
p.inc_rcurly();

if !p.at(LCurly) {
p.advance_with_error("Miss {");
} else {
Expand Down
5 changes: 4 additions & 1 deletion crates/parser/src/grammar/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ use super::{
*,
};

// "signal" --> None
// "signal input" --> Some(true)
// "signal output" --> Some(false)
fn signal_header(p: &mut Parser) -> Option<bool> {
let mut res = None;
let m = p.open();
Expand Down Expand Up @@ -35,7 +38,7 @@ pub(super) fn var_declaration(p: &mut Parser) {

if p.at(LParen) {
tuple(p);
if p.at_any(&[Assign, RAssignSignal, RAssignConstraintSignal]) {
if p.at(Assign) {
tuple_init(p);
}
} else {
Expand Down
1 change: 1 addition & 0 deletions crates/parser/src/grammar/expression.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::parser::Marker;

use super::*;

pub(super) fn expression(p: &mut Parser) {
let m = p.open();
circom_expression(p);
Expand Down
15 changes: 6 additions & 9 deletions crates/parser/src/grammar/function.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
use crate::grammar::*;

// fucntion name()
pub fn function_parse(p: &mut Parser) {
let m = p.open();

p.expect(FunctionKw);
let fn_name_marker = p.open();

let fn_name_marker = p.open();
p.expect(Identifier);
p.close(fn_name_marker, FunctionName);

p.expect(LParen);
let arg_marker = p.open();
while !p.at(RParen) && !p.eof() {
p.expect(Identifier);
if p.at(Comma) {
p.expect(Comma);
}
}

list_identity::parse(p);
p.close(arg_marker, ParameterList);

p.expect(RParen);

block::block(p);

p.close(m, FunctionDef);
}
1 change: 1 addition & 0 deletions crates/parser/src/grammar/list_identity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use super::*;

// a, b, c, d
pub fn parse(p: &mut Parser) {
while p.at(Identifier) && !p.eof() {
p.expect(Identifier);
Expand Down
19 changes: 14 additions & 5 deletions crates/parser/src/grammar/main_component.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
use super::*;

/*
component main {public [signal_list]} = tempid(v1,...,vn);

{public [signal_list]} is optional
*/
pub fn main_component(p: &mut Parser) {
p.expect(ComponentKw);
p.expect(MainKw);
p.expect(LCurly);
p.expect(PublicKw);
p.expect(LBracket);
list_identity::parse(p);
p.expect(RBracket);

if p.at(LCurly) {
p.expect(LCurly);
p.expect(PublicKw);
p.expect(LBracket);
list_identity::parse(p);
p.expect(RBracket);
}

p.expect(Assign);
expression::expression(p);
}
14 changes: 6 additions & 8 deletions crates/parser/src/grammar/template.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
use crate::grammar::*;
/**
* template Identifier() {content}
*
* template Identifier( param_1, ... , param_n ) { content }
*/
pub fn template(p: &mut Parser) {
// assert!(p.at(TemplateKw));
let m = p.open();

p.expect(TemplateKw);

let name_marker = p.open();
p.expect(Identifier);
p.close(name_marker, TemplateName);

p.expect(LParen);
let arg_marker = p.open();
while !p.at(RParen) && !p.eof() {
p.expect(Identifier);
if p.at(Comma) {
p.expect(Comma);
}
}

list_identity::parse(p);
p.close(arg_marker, ParameterList);
p.expect(RParen);

block::block(p);

p.close(m, TemplateDef);
}

Expand Down
Loading
Loading