More OPA conformant semantics (#62)

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-12-11 09:00:06 -08:00
committed by GitHub
parent 8a73b4bef9
commit 73ee18f002
32 changed files with 542 additions and 205 deletions

View File

@@ -209,7 +209,9 @@ impl<'source> Parser<'source> {
match self.tok.0 {
TokenKind::Ident
if self.is_keyword(*span.text())
|| self.is_imported_future_keyword(*span.text()) =>
|| (self.is_imported_future_keyword(*span.text())
// contains can be the name of a builtin even when a keyword
&& *span.text() != "contains") =>
{
Err(self.source.error(
self.tok.1.line,
@@ -1425,6 +1427,25 @@ impl<'source> Parser<'source> {
self.expect("default", "while parsing default rule")?;
let rule_ref = Ref::new(self.parse_rule_ref()?);
let mut args = vec![];
if *self.token_text() == "(" {
self.next_token()?;
if *self.token_text() != ")" {
loop {
let arg = self.parse_ident()?;
if *arg.text() != "_" && args.iter().any(|a: &Span| *a.text() == *arg.text()) {
bail!(arg.error("repeating parameter name"));
}
args.push(arg);
if *self.token_text() == ")" || self.tok.0 == TokenKind::Eof {
break;
}
self.expect(",", "while parsing default rule parameters")?;
}
}
self.expect(")", "while parsing default rule parameters")?;
}
let op = match *self.token_text() {
"=" => AssignOp::Eq,
":=" => AssignOp::ColEq,
@@ -1443,6 +1464,7 @@ impl<'source> Parser<'source> {
Ok(Rule::Default {
span,
refr: rule_ref,
args: args.into_iter().map(|a| Ref::new(Expr::Var(a))).collect(),
op,
value,
})