Skip to content

Commit

Permalink
Accept - as character
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBger committed Jun 25, 2024
1 parent f51b8fe commit 3129f82
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.5.20

- Accepts `-` character in expression's parsing while the `-` is not at the beginning of it. (Ex: `-test` is failing, `test-8` is not)

## 0.5.19

- The return of store type StoreSetSum<T> which allows both summing and setting a value in a store. This is useful for storing aggregated values in a store. Note: to read deltas from this store, you will need to use the Deltas<DeltaBytes> type. The delta values will come prefixed with "set:" or "sum:" depending on the operation, followed by the string representation of the value. It is up to the user to decode the values as necessary.
Expand Down
28 changes: 26 additions & 2 deletions substreams/src/expr_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn expression_to_string(parsing: Pair<Rule>) -> String {
mod tests {
use rstest::rstest;
use super::*;
static TEST_KEYS: &[&str] = &["test", "test1", "test2", "test3", "test4", "test5", "test 6", "test.7", "test:8", "test_9", "test*19z_|"];
static TEST_KEYS: &[&str] = &["test", "test1", "test2", "test3", "test4", "test5", "test 6", "test.7", "test:8", "test_9", "test*19z_|", "type:wasm-MarketUpdated"];

#[rstest]
#[case(TEST_KEYS, "test", true)]
Expand All @@ -129,6 +129,8 @@ mod tests {
#[case(TEST_KEYS, "\"test 6\" && test3", true)]

#[case(TEST_KEYS, "test.7", true)]
#[case(TEST_KEYS, "type:wasm-MarketUpdated", true)]
#[case(TEST_KEYS, "type:was-mMarketUpdated", false)]
#[case(TEST_KEYS, "test.8", false)]
#[case(TEST_KEYS, "test:8", true)]
#[case(TEST_KEYS, "test*19z_|", true)]
Expand Down Expand Up @@ -182,4 +184,26 @@ mod tests {

assert_eq!(result, expected, "This expression ast is {expr_as_string}");
}
}

#[rstest]

// In the current version of the parser, - should not be supported at the beginning of the expression.
#[case("-test", true)]
#[case("'-test'", true)]
#[case("'test-8'", false)]
#[case("test-8", false)]

#[case("'te't'", true)]
#[case("\"te\"st\"", true)]

fn test_parsing_error(#[case] input: &str, #[case] expected: bool) {
let pair = parsing(input);

if expected {
assert!(pair.is_err());
} else {
assert!(pair.is_ok());
}
}
}

8 changes: 4 additions & 4 deletions substreams/src/expr_parser_rule.pest
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ expression = { or ~ space? ~ EOI }
or = { (and ~ (space? ~ ("||") ~ space? ~ and )* ) }
and = { (value ~ ((space ~ value) | (space? ~ ("&&") ~ space? ~ value ~ space?))* ) }
value = { (space? ~ singleQuoteKeyTerm ~ space?) | (space? ~ doubleQuoteKeyTerm ~ space?) | keyterm | (space? ~ "(" ~ space? ~ or ~ space? ~ ")" ~ space?) }
keyterm = { (ctr_accepted)+ }
singleQuoteKeyTerm = { ("'") ~ (!"'" ~ ANY)+ ~ ("'")}
doubleQuoteKeyTerm = { ("\"") ~ (!"\"" ~ ANY)+ ~ ("\"")}
keyterm = { !("-") ~ (ctr_accepted)+ }
singleQuoteKeyTerm = { ("'") ~ !("-") ~ (!"'" ~ ANY)+ ~ ("'")}
doubleQuoteKeyTerm = { ("\"") ~ !("-") ~ (!"\"" ~ ANY)+ ~ ("\"")}

ctr_accepted = _{(!(space | "'" | "\"" | "(" | ")" | "-" | ("||") | ("&&")) ~ ANY)}
ctr_accepted = _{(!(space | "'" | "\"" | "(" | ")" | ("||") | ("&&")) ~ ANY)}
space = _{ (" " | "\t" | "\n" )+ }

0 comments on commit 3129f82

Please sign in to comment.