Skip to content

Commit

Permalink
Merge pull request #18 from tomoyanonymous/fix-parser
Browse files Browse the repository at this point in the history
Fixed parser to ignore first line breaks and semicolons
  • Loading branch information
tomoyanonymous committed Aug 9, 2024
2 parents ec66683 + 5159807 commit 2c43568
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 4 additions & 3 deletions mimium-lang/src/compiler/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ fn expr_parser() -> impl Parser<Token, WithMeta<Expr>, Error = Simple<Token>> +
expr_group
}
fn comment_parser() -> impl Parser<Token, (), Error = Simple<Token>> + Clone {
select! {Token::Comment(Comment::SingleLine(_))=>(),
Token::Comment(Comment::MultiLine(_))=>()}
select! {Token::Comment(Comment::SingleLine(t))=>(),
Token::Comment(Comment::MultiLine(t))=>()}
}
fn func_parser() -> impl Parser<Token, WithMeta<Expr>, Error = Simple<Token>> + Clone {
let expr = expr_parser();
Expand Down Expand Up @@ -377,8 +377,9 @@ fn func_parser() -> impl Parser<Token, WithMeta<Expr>, Error = Simple<Token>> +
}

fn parser() -> impl Parser<Token, WithMeta<Expr>, Error = Simple<Token>> + Clone {
let ignored =comment_parser().or(just(Token::LineBreak).ignored()).or(just(Token::SemiColon).ignored());
func_parser()
.padded_by(comment_parser().repeated().ignored())
.padded_by(ignored.repeated())
.then_ignore(end())
}
pub(crate) fn add_global_context(ast: WithMeta<Expr>) -> WithMeta<Expr> {
Expand Down
7 changes: 7 additions & 0 deletions mimium-lang/tests/intergration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ fn run_file_test(path: &str, times: u64) -> Result<Vec<f64>, ()> {
}
}

#[test]
fn parser_firstbreak(){
let res = run_file_test("parser_firstbreak.mmm", 1).unwrap();
let ans = vec![0.0];
assert_eq!(res, ans);
}

#[test]
fn recursion() {
let res = run_file_test("recursion.mmm", 1).unwrap();
Expand Down
9 changes: 9 additions & 0 deletions mimium-lang/tests/mmm/parser_firstbreak.mmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@


;;;
;

//this file ensures the line break and semicolons before initial meaningful statements are ignored by the parser.
fn dsp(){
0.0
}

0 comments on commit 2c43568

Please sign in to comment.