Skip to content

Commit

Permalink
Remove '-' as valid characters for 'names' (#545)
Browse files Browse the repository at this point in the history
Removed `-` as a valid characters that can appear in "names" like
variable or prefix names. This lead to confusion with the infix operator
`-` for subtraction.

Closes #543
  • Loading branch information
aannleax authored Oct 29, 2024
2 parents 1f4f886 + 99e9283 commit 3a851d9
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 39 deletions.
4 changes: 2 additions & 2 deletions nemo-physical/src/columnar/column/rle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ where
}
}

impl<'a, T> Iterator for ColumnScanRle<'a, T>
impl<T> Iterator for ColumnScanRle<'_, T>
where
T: ColumnDataType,
{
Expand Down Expand Up @@ -255,7 +255,7 @@ where
}
}

impl<'a, T> ColumnScan for ColumnScanRle<'a, T>
impl<T> ColumnScan for ColumnScanRle<'_, T>
where
T: ColumnDataType,
{
Expand Down
2 changes: 1 addition & 1 deletion nemo-physical/src/columnar/columnscan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ where
}
}

impl<'a, T> From<ColumnScanConstant<T>> for ColumnScanEnum<'a, T>
impl<T> From<ColumnScanConstant<T>> for ColumnScanEnum<'_, T>
where
T: ColumnDataType,
{
Expand Down
6 changes: 3 additions & 3 deletions nemo-physical/src/tabular/operations/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'a> TrieScanPrune<'a> {
let input_trie_scan_arity = input_trie_scan.arity();

let mut output_column_scans =
Vec::<UnsafeCell<ColumnScanT<'a>>>::with_capacity(input_trie_scan.arity());
Vec::<UnsafeCell<ColumnScanT<'_>>>::with_capacity(input_trie_scan.arity());

// TODO: One could check if some of the entries are empty here
// and from that deduce that the result of this will be empty
Expand Down Expand Up @@ -563,7 +563,7 @@ impl<'a> TrieScanPruneState<'a> {
}
}

impl<'a> TrieScanPrune<'a> {
impl TrieScanPrune<'_> {
/// Moves to the next value on a given layer while ensuring that only materialized tuples are returned (see guarantees provided by [TrieScanPrune]).
///
/// It is assumed that the trie scan has been initialized by calling `down()` at least once.
Expand Down Expand Up @@ -639,7 +639,7 @@ impl<'a> PartialTrieScan<'a> for TrieScanPrune<'a> {
}
}

impl<'a> TrieScan for TrieScanPrune<'a> {
impl TrieScan for TrieScanPrune<'_> {
fn advance_on_layer(&mut self, layer: usize) -> Option<usize> {
if !unsafe { (*self.state.get()).initialized } {
for current_layer in 0..=layer {
Expand Down
2 changes: 1 addition & 1 deletion nemo-physical/src/tabular/operations/trim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'a> TrieScanTrim<'a> {
}
}

impl<'a> TrieScan for TrieScanTrim<'a> {
impl TrieScan for TrieScanTrim<'_> {
fn num_columns(&self) -> usize {
self.trie_scan.arity()
}
Expand Down
4 changes: 2 additions & 2 deletions nemo/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> ParserErrorReport<'a> {
}
}

impl<'a> std::fmt::Debug for ParserErrorReport<'a> {
impl std::fmt::Debug for ParserErrorReport<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let reports = self.build_reports();

Expand All @@ -111,7 +111,7 @@ impl<'a> std::fmt::Debug for ParserErrorReport<'a> {
}
}

impl<'a> std::fmt::Display for ParserErrorReport<'a> {
impl std::fmt::Display for ParserErrorReport<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut buffer = Vec::new();
if self.write(&mut buffer).is_err() {
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 @@ -25,7 +25,7 @@ pub struct ClosedComment<'a> {

const CONTEXT: ParserContext = ParserContext::Comment;

impl<'a> ClosedComment<'a> {
impl ClosedComment<'_> {
// NOTE: Should this return a &str, so that the consumer can decide whether to turn it into an
// owned value or not?
/// Return the content of the comment
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 @@ -26,7 +26,7 @@ pub struct DocComment<'a> {
content: Vec<Span<'a>>,
}

impl<'a> DocComment<'a> {
impl DocComment<'_> {
/// Return the content of the comment
pub fn content(&self) -> Vec<String> {
self.content
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 @@ -27,7 +27,7 @@ pub struct LineComment<'a> {

const CONTEXT: ParserContext = ParserContext::Comment;

impl<'a> LineComment<'a> {
impl LineComment<'_> {
/// Return the content of the comment
pub fn content(&self) -> String {
self.content.fragment().to_string()
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 @@ -28,7 +28,7 @@ pub struct TopLevelComment<'a> {

const CONTEXT: ParserContext = ParserContext::TopLevelComment;

impl<'a> TopLevelComment<'a> {
impl TopLevelComment<'_> {
/// Return the content of the comment
pub fn content(&self) -> Vec<String> {
self.content
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 @@ -82,7 +82,7 @@ pub enum Directive<'a> {
Unknown(UnknownDirective<'a>),
}

impl<'a> Directive<'a> {
impl Directive<'_> {
/// Return the context of the underlying directive.
pub fn context_type(&self) -> ParserContext {
match self {
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 @@ -21,7 +21,7 @@ pub struct Iri<'a> {
content: Token<'a>,
}

impl<'a> Iri<'a> {
impl Iri<'_> {
/// Return the content of the iri.
pub fn content(&self) -> String {
self.content.to_string()
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 @@ -18,7 +18,7 @@ pub enum Guard<'a> {
Infix(InfixExpression<'a>),
}

impl<'a> Guard<'a> {
impl Guard<'_> {
/// Return the [ParserContext] of the underlying expression type.
pub fn context_type(&self) -> ParserContext {
match self {
Expand Down
6 changes: 3 additions & 3 deletions nemo/src/parser/ast/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Sequence<'a, T> {
elements: Vec<T>,
}

impl<'a, T> Sequence<'a, T> {
impl<T> Sequence<'_, T> {
/// Return an iterator over the elements.
pub fn iter(&self) -> impl Iterator<Item = &T> {
self.into_iter()
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<'a, T: std::fmt::Debug + Sync + ProgramAST<'a>> ProgramAST<'a> for Sequence
}
}

impl<'a, 'b, T> IntoIterator for &'b Sequence<'a, T> {
impl<'b, T> IntoIterator for &'b Sequence<'_, T> {
type Item = &'b T;
type IntoIter = std::slice::Iter<'b, T>;

Expand All @@ -145,7 +145,7 @@ impl<'a, 'b, T> IntoIterator for &'b Sequence<'a, T> {
}
}

impl<'a, T> IntoIterator for Sequence<'a, T> {
impl<T> IntoIterator for Sequence<'_, T> {
type Item = T;
type IntoIter = IntoIter<T>;

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 @@ -26,7 +26,7 @@ pub struct AggregationTag<'a> {
kind: Option<AggregateKind>,
}

impl<'a> AggregationTag<'a> {
impl AggregationTag<'_> {
/// Return the [AggregateKind] that was parsed, if it is known.
pub fn operation(&self) -> Option<AggregateKind> {
self.kind
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 @@ -26,7 +26,7 @@ pub struct DataTypeTag<'a> {
data_type: DataType,
}

impl<'a> DataTypeTag<'a> {
impl DataTypeTag<'_> {
/// Return the [DataType] that was parsed.
pub fn data_type(&self) -> DataType {
self.data_type
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 @@ -26,7 +26,7 @@ pub struct OperationTag<'a> {
kind: OperationKind,
}

impl<'a> OperationTag<'a> {
impl OperationTag<'_> {
/// Return the [OperationKind] that was parsed.
pub fn operation(&self) -> OperationKind {
self.kind
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 @@ -29,7 +29,7 @@ pub struct ParameterName<'a> {
parameter: Parameter,
}

impl<'a> ParameterName<'a> {
impl ParameterName<'_> {
/// Return the [Parameter] that was parsed.
pub fn parameter(&self) -> &Parameter {
&self.parameter
Expand Down
2 changes: 1 addition & 1 deletion nemo/src/parser/ast/tag/structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'a> StructureTag<'a> {
}
}

impl<'a> Display for StructureTag<'a> {
impl Display for StructureTag<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self.kind {
StructureTagKind::Plain(token) => token.fmt(f),
Expand Down
4 changes: 2 additions & 2 deletions nemo/src/parser/ast/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub struct Token<'a> {
kind: TokenKind,
}

impl<'a> Display for Token<'a> {
impl Display for Token<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.span.fmt(f)
}
Expand Down Expand Up @@ -316,7 +316,7 @@ impl<'a> Token<'a> {
ParserContext::token(TokenKind::Name),
recognize(pair(
alpha1,
many0(alt((alphanumeric1, tag("_"), tag("-"), tag("%")))),
many0(alt((alphanumeric1, tag("_"), tag("%")))),
)),
)(input)
.map(|(rest_input, result)| {
Expand Down
10 changes: 5 additions & 5 deletions nemo/src/parser/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'a> ParserInput<'a> {
}
}

impl<'a> AsBytes for ParserInput<'a> {
impl AsBytes for ParserInput<'_> {
fn as_bytes(&self) -> &[u8] {
self.span.fragment().as_bytes()
}
Expand All @@ -41,7 +41,7 @@ impl<'a> nom::Compare<ParserInput<'a>> for ParserInput<'a> {
}
}

impl<'a> nom::Compare<&str> for ParserInput<'a> {
impl nom::Compare<&str> for ParserInput<'_> {
fn compare(&self, t: &str) -> nom::CompareResult {
self.span.compare(t)
}
Expand All @@ -51,7 +51,7 @@ impl<'a> nom::Compare<&str> for ParserInput<'a> {
}
}

impl<'a> nom::ExtendInto for ParserInput<'a> {
impl nom::ExtendInto for ParserInput<'_> {
type Item = char;

type Extender = String;
Expand All @@ -65,13 +65,13 @@ impl<'a> nom::ExtendInto for ParserInput<'a> {
}
}

impl<'a> nom::FindSubstring<&str> for ParserInput<'a> {
impl nom::FindSubstring<&str> for ParserInput<'_> {
fn find_substring(&self, substr: &str) -> Option<usize> {
self.span.find_substring(substr)
}
}

impl<'a> InputLength for ParserInput<'a> {
impl InputLength for ParserInput<'_> {
fn input_len(&self) -> usize {
self.span.input_len()
}
Expand Down
4 changes: 2 additions & 2 deletions nemo/src/parser/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'a> Span<'a> {
}
}

impl<'a> std::fmt::Display for Span<'a> {
impl std::fmt::Display for Span<'_> {
fn fmt(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
self.fragment.fmt(formatter)
}
Expand Down Expand Up @@ -349,7 +349,7 @@ impl<'a> nom::Compare<Span<'a>> for Span<'a> {
}
}

impl<'a> nom::Compare<&str> for Span<'a> {
impl nom::Compare<&str> for Span<'_> {
fn compare(&self, t: &str) -> nom::CompareResult {
self.fragment.compare(t)
}
Expand Down
4 changes: 2 additions & 2 deletions nemo/src/rule_model/translation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl<'a> ProgramErrorReport<'a> {
}
}

impl<'a> std::fmt::Debug for ProgramErrorReport<'a> {
impl std::fmt::Debug for ProgramErrorReport<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let reports = self.build_reports();

Expand All @@ -170,7 +170,7 @@ impl<'a> std::fmt::Debug for ProgramErrorReport<'a> {
}
}

impl<'a> std::fmt::Display for ProgramErrorReport<'a> {
impl std::fmt::Display for ProgramErrorReport<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut buffer = Vec::new();
if self.write(&mut buffer).is_err() {
Expand Down
6 changes: 2 additions & 4 deletions nemo/src/rule_model/translation/directive/import_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ impl<'a> ASTProgramTranslation<'a> {

if let Some((extension, origin)) = extension {
for &rdf_format in FILE_FORMATS_RDF {
if extension.to_ascii_lowercase()
== rdf_format.extension().to_ascii_lowercase()
{
if extension.eq_ignore_ascii_case(rdf_format.extension()) {
return Ok(rdf_format);
}
}
Expand All @@ -81,7 +79,7 @@ impl<'a> ASTProgramTranslation<'a> {
}
} else {
for format in FileFormat::iter() {
if format_tag.to_ascii_lowercase() == format.name().to_ascii_lowercase() {
if format_tag.eq_ignore_ascii_case(format.name()) {
return Ok(format);
}
}
Expand Down
11 changes: 11 additions & 0 deletions resources/testcases/regression/parsing/variable-names/run.rls
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%%% Test related to
%%% https://github.com/knowsys/nemo/issues/543
%%%
%%% Varibale names were allowed to contain "-", which cannot be distinguished from an arithmetic operation

fact(1) .

result(?variable_name) :- fact(?variable_name) .
result(?arithmetic-1) :- fact(?arithmetic) .

@export result :- csv {} .
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0
1

0 comments on commit 3a851d9

Please sign in to comment.