Skip to content

Commit

Permalink
test: add list comprehension parser tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tohrnii committed Jan 30, 2023
1 parent 76079c7 commit 8db9bf4
Show file tree
Hide file tree
Showing 3 changed files with 523 additions and 9 deletions.
15 changes: 6 additions & 9 deletions parser/src/parser/grammar.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ BoundaryVariableType: VariableType = {
VariableType::Vector(vector_value),
"[" <matrix_value: CommaElems<Vector<BoundaryExpr>>> "]" =>
VariableType::Matrix(matrix_value),
<list_comprehension: ListComprehension<BoundaryExpr>> => VariableType::ListComprehension(list_comprehension),
"[" <list_comprehension: ListComprehension<BoundaryExpr>> "]" =>
VariableType::ListComprehension(list_comprehension),
}

Boundary: Boundary = {
Expand Down Expand Up @@ -233,7 +234,8 @@ IntegrityVariableType: VariableType = {
VariableType::Vector(vector_value),
"[" <matrix_value: CommaElems<Vector<IntegrityExpr>>> "]" =>
VariableType::Matrix(matrix_value),
<list_comprehension: ListComprehension<IntegrityExpr>> => VariableType::ListComprehension(list_comprehension),
"[" <list_comprehension: ListComprehension<IntegrityExpr>> "]" =>
VariableType::ListComprehension(list_comprehension),
}

// --- INTEGRITY CONSTRAINT EXPRESSIONS WITH PRECEDENCE (LOWEST TO HIGHEST) ----------------------
Expand Down Expand Up @@ -323,15 +325,10 @@ IndexedTraceAccess: IndexedTraceAccess = {
}

ListComprehension<T>: ListComprehension = {
"[" <expr: T> "for" <members: Members> "in" <iterables: Iterables> "]" =>?
<expr: T> "for" <members: Members> "in" <iterables: Iterables> =>?
match (members, iterables)
{
(Members::Single(..), Iterables::Double(..)) => Err(ParseError::User {
error: Error::ParseError(
InvalidListComprehension("For a single member, a single iterable is required".to_string())
)
}),
(Members::Single(..), Iterables::Range(..)) => Err(ParseError::User {
(Members::Single(..), Iterables::Double(..) | Iterables::Range(..)) => Err(ParseError::User {
error: Error::ParseError(
InvalidListComprehension("For a single member, a single iterable is required".to_string())
)
Expand Down
Loading

0 comments on commit 8db9bf4

Please sign in to comment.