Comments: ignore everything after a semicolon (#30)

This commit is contained in:
folex 2020-11-24 12:40:54 +03:00 committed by GitHub
parent c2d81749fe
commit dde12e2a40
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 14 deletions

View File

@ -87,6 +87,10 @@ match {
"xor",
"fold",
"next",
// ignore patterns
// see: https://lalrpop.github.io/lalrpop/lexer_tutorial/001_lexer_gen.html#customizing-skipping-between-tokens
r"\s*" => { }, // The default whitespace skipping is disabled if an `ignore pattern` is specified
r";[^\n\r]*[\n\r]*" => { }, // Skip `; comments`
} else {
_
}

File diff suppressed because one or more lines are too long

View File

@ -403,7 +403,28 @@ fn no_output() {
#[test]
fn fold_json_path() {
let source_code = r#"
(fold members.$.["users"] m (null))
; comment
(fold members.$.["users"] m (null)) ;;; comment
;;; comment
"#;
let instruction = parse(&source_code.as_ref());
let expected = Instruction::Fold(Fold {
iterable: JsonPath {
variable: "members",
path: "$.[\"users\"]",
},
iterator: "m",
instruction: Rc::new(null()),
});
assert_eq!(instruction, expected);
}
#[test]
fn comments() {
let source_code = r#"
; comment
(fold members.$.["users"] m (null)) ;;; comment ;;?()()
;;; comme;?!.$. nt[][][][()()()null;$::!
"#;
let instruction = parse(&source_code.as_ref());
let expected = Instruction::Fold(Fold {