Skip to content

Commit

Permalink
Editing ASP grammar to permit _ in object constants and predicate sym…
Browse files Browse the repository at this point in the history
…bols
  • Loading branch information
ZachJHansen committed Feb 22, 2024
1 parent 9a71cda commit 3f0de69
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/parsing/asp/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WHITESPACE = _{ " " | NEWLINE }
precomputed_term = { infimum | integer | symbol | supremum }
infimum = @{ "#infimum" | "#inf" }
integer = @{ "0" | "-"? ~ ASCII_NONZERO_DIGIT ~ ASCII_DIGIT* }
symbol = @{ !negation ~ ASCII_ALPHA_LOWER ~ ASCII_ALPHANUMERIC* }
symbol = @{ !negation ~ ASCII_ALPHA_LOWER ~ (ASCII_ALPHANUMERIC | "_")* }
supremum = @{ "#supremum" | "#sup" }

variable = @{ ASCII_ALPHA_UPPER ~ ASCII_ALPHANUMERIC* }
Expand Down
30 changes: 23 additions & 7 deletions src/parsing/asp/pest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,22 @@ mod tests {
#[test]
fn parse_predicate() {
PredicateParser
.should_parse_into([(
"p/1",
Predicate {
symbol: "p".into(),
arity: 1,
},
)])
.should_parse_into([
(
"p/1",
Predicate {
symbol: "p".into(),
arity: 1,
},
),
(
"p_/1",
Predicate {
symbol: "p_".into(),
arity: 1,
},
),
])
.should_reject(["p", "1/1", "p/00", "p/01", "_/1", "p/p", "_p/1"]);
}

Expand Down Expand Up @@ -808,6 +817,13 @@ mod tests {
terms: vec![Term::PrecomputedTerm(PrecomputedTerm::Numeral(1))],
},
),
(
"sqrt_b(1)",
Atom {
predicate_symbol: "sqrt_b".into(),
terms: vec![Term::PrecomputedTerm(PrecomputedTerm::Numeral(1))],
},
),
(
"p(1, 2)",
Atom {
Expand Down

0 comments on commit 3f0de69

Please sign in to comment.