Skip to content

Commit

Permalink
generalize ProgramAST lifetimes
Browse files Browse the repository at this point in the history
  • Loading branch information
matzemathics committed Jan 8, 2025
1 parent 1847c83 commit f1a04ce
Show file tree
Hide file tree
Showing 45 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion nemo/src/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use colored::Colorize;
/// Trait implemented by nodes in the abstract syntax tree
pub trait ProgramAST<'a>: Debug + Sync {
/// Return all children of this node.
fn children(&'a self) -> Vec<&'a dyn ProgramAST<'a>>;
fn children(&self) -> Vec<&dyn ProgramAST<'a>>;

/// Return the region of text this node originates from.
fn span(&self) -> Span<'a>;
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl<'a> Attribute<'a> {
const CONTEXT: ParserContext = ParserContext::Attribute;

impl<'a> ProgramAST<'a> for Attribute<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![self.content()]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/comment/closed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl ClosedComment<'_> {
}

impl<'a> ProgramAST<'a> for ClosedComment<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/comment/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl DocComment<'_> {
const CONTEXT: ParserContext = ParserContext::DocComment;

impl<'a> ProgramAST<'a> for DocComment<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/comment/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl LineComment<'_> {
}

impl<'a> ProgramAST<'a> for LineComment<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/comment/toplevel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl TopLevelComment<'_> {
}

impl<'a> ProgramAST<'a> for TopLevelComment<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/directive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Directive<'_> {
const CONTEXT: ParserContext = ParserContext::Directive;

impl<'a> ProgramAST<'a> for Directive<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![match self {
Directive::Base(directive) => directive,
Directive::Declare(directive) => directive,
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/directive/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<'a> Base<'a> {
const CONTEXT: ParserContext = ParserContext::Base;

impl<'a> ProgramAST<'a> for Base<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&self.iri]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/directive/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ impl<'a> Declare<'a> {
const CONTEXT: ParserContext = ParserContext::Declare;

impl<'a> ProgramAST<'a> for Declare<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result = Vec::<&dyn ProgramAST>::new();
result.push(&self.predicate);

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/directive/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'a> Export<'a> {
const CONTEXT: ParserContext = ParserContext::Export;

impl<'a> ProgramAST<'a> for Export<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&self.predicate, &self.instructions]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/directive/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'a> Import<'a> {
const CONTEXT: ParserContext = ParserContext::Import;

impl<'a> ProgramAST<'a> for Import<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&self.predicate, &self.instructions]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/directive/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> Output<'a> {
const CONTEXT: ParserContext = ParserContext::Output;

impl<'a> ProgramAST<'a> for Output<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&self.predicate]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/directive/prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> Prefix<'a> {
const CONTEXT: ParserContext = ParserContext::Prefix;

impl<'a> ProgramAST<'a> for Prefix<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&self.iri]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/directive/unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl<'a> UnknownDirective<'a> {
const CONTEXT: ParserContext = ParserContext::UnknownDirective;

impl<'a> ProgramAST<'a> for UnknownDirective<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a> Expression<'a> {
const CONTEXT: ParserContext = ParserContext::Expression;

impl<'a> ProgramAST<'a> for Expression<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![match self {
Expression::Aggregation(expression) => expression,
Expression::Arithmetic(expression) => expression,
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/basic/blank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl<'a> Blank<'a> {
const CONTEXT: ParserContext = ParserContext::Blank;

impl<'a> ProgramAST<'a> for Blank<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/basic/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<'a> Boolean<'a> {
const CONTEXT: ParserContext = ParserContext::Boolean;

impl<'a> ProgramAST<'a> for Boolean<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/basic/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'a> Constant<'a> {
const CONTEXT: ParserContext = ParserContext::Constant;

impl<'a> ProgramAST<'a> for Constant<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/basic/iri.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Iri<'_> {
const CONTEXT: ParserContext = ParserContext::Iri;

impl<'a> ProgramAST<'a> for Iri<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/basic/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<'a> Number<'a> {
const CONTEXT: ParserContext = ParserContext::Number;

impl<'a> ProgramAST<'a> for Number<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/basic/rdf_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'a> RdfLiteral<'a> {
const CONTEXT: ParserContext = ParserContext::RdfLiteral;

impl<'a> ProgramAST<'a> for RdfLiteral<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/basic/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl<'a> StringLiteral<'a> {
const CONTEXT: ParserContext = ParserContext::String;

impl<'a> ProgramAST<'a> for StringLiteral<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/basic/variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<'a> Variable<'a> {
const CONTEXT: ParserContext = ParserContext::Variable;

impl<'a> ProgramAST<'a> for Variable<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl<'a> Aggregation<'a> {
const CONTEXT: ParserContext = ParserContext::Aggregation;

impl<'a> ProgramAST<'a> for Aggregation<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result: Vec<&dyn ProgramAST> = vec![];
result.push(&self.tag);
result.push(&*self.aggregate);
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'a> Arithmetic<'a> {
const CONTEXT: ParserContext = ParserContext::Arithmetic;

impl<'a> ProgramAST<'a> for Arithmetic<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&*self.left, &*self.right]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<'a> Atom<'a> {
const CONTEXT: ParserContext = ParserContext::Atom;

impl<'a> ProgramAST<'a> for Atom<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result = Vec::<&dyn ProgramAST>::new();
result.push(&self.tag);

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/fstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'a> FormatString<'a> {
const CONTEXT: ParserContext = ParserContext::FormatString;

impl<'a> ProgramAST<'a> for FormatString<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result = Vec::<&dyn ProgramAST>::new();

for element in &self.elements {
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/infix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> InfixExpression<'a> {
const CONTEXT: ParserContext = ParserContext::Infix;

impl<'a> ProgramAST<'a> for InfixExpression<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&*self.left, &*self.right]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'a> Map<'a> {
const CONTEXT: ParserContext = ParserContext::Map;

impl<'a> ProgramAST<'a> for Map<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result: Vec<&dyn ProgramAST> = vec![];

if let Some(tag) = &self.tag {
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/negation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<'a> Negation<'a> {
const CONTEXT: ParserContext = ParserContext::Negation;

impl<'a> ProgramAST<'a> for Negation<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&*self.expression]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'a> Operation<'a> {
const CONTEXT: ParserContext = ParserContext::Operation;

impl<'a> ProgramAST<'a> for Operation<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result = Vec::<&dyn ProgramAST>::new();
result.push(&self.tag);

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/parenthesized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl<'a> ParenthesizedExpression<'a> {
const CONTEXT: ParserContext = ParserContext::ParenthesizedExpression;

impl<'a> ProgramAST<'a> for ParenthesizedExpression<'a> {
fn children(&'a self) -> Vec<&'a dyn ProgramAST<'a>> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&*self.expression]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/expression/complex/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<'a> Tuple<'a> {
const CONTEXT: ParserContext = ParserContext::Tuple;

impl<'a> ProgramAST<'a> for Tuple<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result = Vec::<&dyn ProgramAST>::new();

for expression in &self.expressions {
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/guard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl Guard<'_> {
const CONTEXT: ParserContext = ParserContext::Guard;

impl<'a> ProgramAST<'a> for Guard<'a> {
fn children(&'a self) -> Vec<&'a dyn ProgramAST<'a>> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
match self {
Guard::Expression(expression) => expression.children(),
Guard::Infix(infix) => infix.children(),
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl<'a> Program<'a> {
const CONTEXT: ParserContext = ParserContext::Program;

impl<'a> ProgramAST<'a> for Program<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result = Vec::<&dyn ProgramAST>::new();

if let Some(comment) = self.comment() {
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl<'a> Rule<'a> {
const CONTEXT: ParserContext = ParserContext::Rule;

impl<'a> ProgramAST<'a> for Rule<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut result = Vec::<&dyn ProgramAST>::new();

for expression in self.head().chain(self.body()) {
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl<'a, T: ProgramAST<'a> + 'a> Sequence<'a, T> {
}

impl<'a, T: std::fmt::Debug + Sync + ProgramAST<'a>> ProgramAST<'a> for Sequence<'a, T> {
fn children(&'a self) -> Vec<&'a dyn ProgramAST<'a>> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
let mut vec: Vec<&dyn ProgramAST> = Vec::new();
for elem in &self.elements {
vec.push(elem);
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/sequence/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct NameTypePair<'a> {
}

impl<'a> ProgramAST<'a> for NameTypePair<'a> {
fn children(&'a self) -> Vec<&'a dyn ProgramAST<'a>> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
if let Some(datatype) = &self.datatype {
vec![&self.name, datatype]
} else {
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/sequence/key_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl<'a> KeyValuePair<'a> {
}

impl<'a> ProgramAST<'a> for KeyValuePair<'a> {
fn children(&'a self) -> Vec<&'a dyn ProgramAST<'a>> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
vec![&self.key, &self.value]
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a> Statement<'a> {
const CONTEXT: ParserContext = ParserContext::Statement;

impl<'a> ProgramAST<'a> for Statement<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
match &self.kind {
StatementKind::Fact(statement) => vec![statement],
StatementKind::Rule(statement) => vec![statement],
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/tag/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl AggregationTag<'_> {
const CONTEXT: ParserContext = ParserContext::AggregationTag;

impl<'a> ProgramAST<'a> for AggregationTag<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/tag/datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl DataTypeTag<'_> {
const CONTEXT: ParserContext = ParserContext::DataType;

impl<'a> ProgramAST<'a> for DataTypeTag<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/tag/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl OperationTag<'_> {
const CONTEXT: ParserContext = ParserContext::OperationTag;

impl<'a> ProgramAST<'a> for OperationTag<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/tag/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl ParameterName<'_> {
const CONTEXT: ParserContext = ParserContext::DataType;

impl<'a> ProgramAST<'a> for ParameterName<'a> {
fn children(&self) -> Vec<&dyn ProgramAST> {
fn children(&self) -> Vec<&dyn ProgramAST<'a>> {
Vec::default()
}

Expand Down
Loading

0 comments on commit f1a04ce

Please sign in to comment.