Skip to content

Commit

Permalink
Fix bug where print is not accepted without trailing semi or whitespace
Browse files Browse the repository at this point in the history
This should fix #73
  • Loading branch information
ezrosent committed Sep 16, 2021
1 parent 73fdd95 commit b26ba0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,13 @@ print w,z;
"1 1\n7 21\n"
);

test_program!(
print_no_space,
r#"{print}"#,
"test\n",
@input "test\n"
);

test_program!(
uncalled_function,
r#"function unused() { return 5; }
Expand Down
3 changes: 2 additions & 1 deletion src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ lazy_static! {
static ref WS_BRACE: Regex = Regex::new(r"^[\s{}]").unwrap();
static ref WS_SEMI: Regex = Regex::new(r"^[\s;]").unwrap();
static ref WS_SEMI_NL: Regex = Regex::new(r"^[\s;\n]").unwrap();
static ref WS_SEMI_NL_RB: Regex = Regex::new(r"^[\s;\n}]").unwrap();
static ref WS_SEMI_RPAREN: Regex = Regex::new(r"^[\s;)]").unwrap();
static ref WS_PAREN: Regex = Regex::new(r"^[\s()]").unwrap();
}
Expand All @@ -146,7 +147,7 @@ keyword_map!(
[b"for", Tok::For, WS_PAREN.clone()],
[b"if", Tok::If],
[b"else", Tok::Else],
[b"print", Tok::Print, WS_SEMI_NL.clone()],
[b"print", Tok::Print, WS_SEMI_NL_RB.clone()],
[b"printf", Tok::Printf, WS_SEMI_NL.clone()],
[b"print(", Tok::PrintLP],
[b"printf(", Tok::PrintfLP],
Expand Down

0 comments on commit b26ba0c

Please sign in to comment.