Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions typecheck/src/main/scala/incremental/Node.scala
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ object SyntaxChecking {

class SyntaxCheckOps(f: NodeKind => SyntaxChecker) {
def orElse(g: NodeKind => SyntaxChecker) = (k: NodeKind) => new AlternativeSyntax(k, f, g)
def andAlso(g: NodeKind => SyntaxChecker) = (k: NodeKind) => new ConjunctiveSyntax(k, f, g)
}

class IgnoreSyntax(k: NodeKind) extends SyntaxChecker(k) {
Expand Down Expand Up @@ -203,4 +204,26 @@ object SyntaxChecking {
}
}

case class ConjunctiveSyntax(k: NodeKind, f: NodeKind => SyntaxChecker, g: NodeKind => SyntaxChecker) extends SyntaxChecker(k) {
def check[T](lits: Seq[Lit], kids: Seq[Node_[T]]): Unit = {
try {
f(k).check(lits, kids)
} catch {
case e1: SyntaxError => {
try {
g(k).check(lits, kids)
} catch {
case e2: SyntaxError => error(s"Conjunctive syntax failed \n\t${e1.msg}\nand\n\t${e2.msg})")
}
error(s"Conjunctive syntax failed \n\t${e1.msg}")
}
}

try {
g(k).check(lits, kids)
} catch {
case e: SyntaxError => error(s"Conjunctive syntax failed \n\t${e.msg}")
}
}
}
}