OPA conformance (#71)

- Remove unnecessary memory allocations
- Add --non-strict flag
- Ensure that only empty modules (ones without rules) are initialzed prior to evaluating rules.
- Record rule as entry for each of its prefixes.
  For example, for a rule a.b.c =... in package test, record it in
  rules["data.test.a"], rules["data.test.a.b"] and rules["data.test.a.b.c"]

  This allows evaluating the correct list of rules based on expessions
  a.b.c, a.b, a, data.test.a.b.c, data.test.a.b, data.test.a

Closes #69
Closes #70

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2023-12-23 11:55:25 -08:00
committed by GitHub
parent ad3282caf4
commit e61b406547
11 changed files with 201 additions and 139 deletions
+4 -4
View File
@@ -186,8 +186,8 @@ pub struct Span {
}
impl Span {
pub fn text(&self) -> std::rc::Rc<&str> {
std::rc::Rc::new(&self.source.contents()[self.start as usize..self.end as usize])
pub fn text(&self) -> &str {
&self.source.contents()[self.start as usize..self.end as usize]
}
pub fn source_str(&self) -> SourceStr {
@@ -619,7 +619,7 @@ impl<'source> Lexer<'source> {
_ if chr.is_ascii_digit() => self.read_number(),
_ if chr.is_ascii_alphabetic() || chr == '_' => {
let mut ident = self.read_ident()?;
if *ident.1.text() == "set" && self.peek().1 == '(' {
if ident.1.text() == "set" && self.peek().1 == '(' {
// set immediately followed by ( is treated as set( if
// the next token is ).
let state = (self.iter.clone(), self.line, self.col);
@@ -627,7 +627,7 @@ impl<'source> Lexer<'source> {
// Check it next token is ).
let next_tok = self.next_token()?;
let is_setp = *next_tok.1.text() == ")";
let is_setp = next_tok.1.text() == ")";
// Restore state
(self.iter, self.line, self.col) = state;