Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 52 additions & 49 deletions engine/src/ast/field_expr.rs

Large diffs are not rendered by default.

36 changes: 18 additions & 18 deletions engine/src/ast/function_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::functions::{
use crate::lex::{Lex, LexError, LexErrorKind, LexResult, LexWith, expect, skip_space, span};
use crate::lhs_types::Array;
use crate::scheme::Function;
use crate::types::{GetType, LhsValue, RhsValue, Type};
use crate::types::{GetType, LhsValue, LiteralValue, Type};
use serde::Serialize;
use std::hash::{Hash, Hasher};
use std::iter::once;
Expand All @@ -26,7 +26,7 @@ pub enum FunctionCallArgExpr {
/// A sub-expression which evaluates to a value.
IndexExpr(IndexExpr),
/// A literal value.
Literal(RhsValue),
Literal(LiteralValue),
/// A sub-expression which evaluates to either `true`/`false`
/// or a list of `true`/`false`. It compiles to a [`CompiledExpr`]
/// and is coerced into a [`CompiledValueExpr`]`.
Expand Down Expand Up @@ -141,7 +141,7 @@ impl<'i, 's> LexWith<'i, &FilterParser<'s>> for FunctionCallArgExpr {
let c2 = chars.next();
let c3 = chars.next();
if c == '"' || (c == 'r' && (c2 == Some('#') || c2 == Some('"'))) {
return RhsValue::lex_with(input, Type::Bytes)
return LiteralValue::lex_with(input, Type::Bytes)
.map(|(literal, input)| (FunctionCallArgExpr::Literal(literal), input));
} else if c == '('
|| UnaryOp::lex(input).is_ok()
Expand Down Expand Up @@ -187,16 +187,16 @@ impl<'i, 's> LexWith<'i, &FilterParser<'s>> for FunctionCallArgExpr {
}
}

RhsValue::lex_with(input, Type::Ip)
LiteralValue::lex_with(input, Type::Ip)
.map(|(literal, input)| (FunctionCallArgExpr::Literal(literal), input))
.or_else(|_| {
RhsValue::lex_with(input, Type::Int)
LiteralValue::lex_with(input, Type::Int)
.map(|(literal, input)| (FunctionCallArgExpr::Literal(literal), input))
})
// try to parse Bytes after Int because digit literals < 255 are wrongly
// interpreted as Bytes
.or_else(|_| {
RhsValue::lex_with(input, Type::Bytes)
LiteralValue::lex_with(input, Type::Bytes)
.map(|(literal, input)| (FunctionCallArgExpr::Literal(literal), input))
})
.map_err(|_| (LexErrorKind::EOF, _initial_input))
Expand Down Expand Up @@ -584,7 +584,7 @@ mod tests {
};
use crate::rhs_types::{BytesExpr, BytesFormat};
use crate::scheme::{FieldIndex, IndexAccessError, Scheme};
use crate::types::{RhsValues, Type, TypeMismatchError};
use crate::types::{LiteralSet, Type, TypeMismatchError};
use std::convert::TryFrom;
use std::sync::LazyLock;

Expand Down Expand Up @@ -756,8 +756,8 @@ mod tests {
),
indexes: vec![],
}),
FunctionCallArgExpr::Literal(RhsValue::Int(1)),
FunctionCallArgExpr::Literal(RhsValue::Int(2)),
FunctionCallArgExpr::Literal(LiteralValue::Int(1)),
FunctionCallArgExpr::Literal(LiteralValue::Int(2)),
],
context: None,
},
Expand Down Expand Up @@ -831,8 +831,8 @@ mod tests {
),
indexes: vec![],
}),
FunctionCallArgExpr::Literal(RhsValue::Int(1)),
FunctionCallArgExpr::Literal(RhsValue::Int(2)),
FunctionCallArgExpr::Literal(LiteralValue::Int(1)),
FunctionCallArgExpr::Literal(LiteralValue::Int(2)),
],
context: None,
},
Expand Down Expand Up @@ -1079,7 +1079,7 @@ mod tests {
},
op: ComparisonOpExpr::Ordering {
op: OrderingOp::Equal,
rhs: RhsValue::Bytes("test".to_owned().into())
rhs: LiteralValue::Bytes("test".to_owned().into())
}
})),
""
Expand Down Expand Up @@ -1193,7 +1193,7 @@ mod tests {
),
indexes: vec![FieldIndex::MapEach],
},
op: ComparisonOpExpr::OneOf(RhsValues::Bytes(vec![
op: ComparisonOpExpr::OneOf(LiteralSet::Bytes(vec![
"Cookie".to_owned().into(),
"Cookies".to_owned().into(),
])),
Expand Down Expand Up @@ -1250,7 +1250,7 @@ mod tests {
),
indexes: vec![FieldIndex::MapEach],
},
op: ComparisonOpExpr::OneOf(RhsValues::Bytes(vec![
op: ComparisonOpExpr::OneOf(LiteralSet::Bytes(vec![
"Cookie".to_owned().into(),
"Cookies".to_owned().into(),
])),
Expand Down Expand Up @@ -1301,8 +1301,8 @@ mod tests {
identifier: IdentifierExpr::Field(SCHEME.get_field("http.host").unwrap().to_owned()),
indexes: vec![],
}),
FunctionCallArgExpr::Literal(RhsValue::Bytes(BytesExpr::new("this is a r##raw## string".as_bytes(), BytesFormat::Raw(0)))),
FunctionCallArgExpr::Literal(RhsValue::Bytes(BytesExpr::new("this is a new r##raw## string".as_bytes(), BytesFormat::Raw(0))))
FunctionCallArgExpr::Literal(LiteralValue::Bytes(BytesExpr::new("this is a r##raw## string".as_bytes(), BytesFormat::Raw(0)))),
FunctionCallArgExpr::Literal(LiteralValue::Bytes(BytesExpr::new("this is a new r##raw## string".as_bytes(), BytesFormat::Raw(0))))
],
context: None,
},
Expand Down Expand Up @@ -1342,8 +1342,8 @@ mod tests {
identifier: IdentifierExpr::Field(SCHEME.get_field("http.host").unwrap().to_owned()),
indexes: vec![],
}),
FunctionCallArgExpr::Literal(RhsValue::Bytes(BytesExpr::new("this is a r##\"raw\"## string".as_bytes(), BytesFormat::Raw(3)))),
FunctionCallArgExpr::Literal(RhsValue::Bytes(BytesExpr::new("this is a new r##\"raw\"## string".as_bytes(), BytesFormat::Raw(3))))
FunctionCallArgExpr::Literal(LiteralValue::Bytes(BytesExpr::new("this is a r##\"raw\"## string".as_bytes(), BytesFormat::Raw(3)))),
FunctionCallArgExpr::Literal(LiteralValue::Bytes(BytesExpr::new("this is a new r##\"raw\"## string".as_bytes(), BytesFormat::Raw(3))))
],
context: None,
},
Expand Down
8 changes: 4 additions & 4 deletions engine/src/functions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pub use self::concat::ConcatFunction;
use crate::ParserSettings;
use crate::filter::CompiledValueResult;
use crate::types::{
ExpectedType, ExpectedTypeList, GetType, LhsValue, RhsValue, Type, TypeMismatchError,
ExpectedType, ExpectedTypeList, GetType, LhsValue, LiteralValue, Type, TypeMismatchError,
};
use std::any::Any;
use std::convert::TryFrom;
Expand Down Expand Up @@ -174,7 +174,7 @@ impl From<FunctionArgInvalidConstantError> for FunctionParamError {
#[derive(Clone, Debug)]
pub enum FunctionParam<'a> {
/// Contant function parameter (literal value)
Constant(&'a RhsValue),
Constant(&'a LiteralValue),
/// Variable function parameter (field, or complex expressions)
Variable(Type),
}
Expand All @@ -196,7 +196,7 @@ impl GetType for FunctionParam<'_> {

impl<'a> FunctionParam<'a> {
/// Returns the underlying value if the current parameter is a constant, otherwise an error.
pub fn as_constant(&self) -> Result<&'a RhsValue, FunctionArgKindMismatchError> {
pub fn as_constant(&self) -> Result<&'a LiteralValue, FunctionArgKindMismatchError> {
match self {
Self::Constant(value) => Ok(value),
Self::Variable(_) => Err(FunctionArgKindMismatchError {
Expand Down Expand Up @@ -255,7 +255,7 @@ impl<'a> FunctionParam<'a> {
/// Checks that the parameter is a constant of a certain type
/// and call the closure `op` to verify its value
pub fn expect_const_value<
U: TryFrom<&'a RhsValue, Error = TypeMismatchError>,
U: TryFrom<&'a LiteralValue, Error = TypeMismatchError>,
F: FnOnce(U) -> Result<(), String>,
>(
&self,
Expand Down
4 changes: 2 additions & 2 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ pub use self::scheme::{
SchemeBuilder, SchemeMismatchError, UnknownFieldError,
};
pub use self::types::{
CompoundType, ExpectedType, ExpectedTypeList, GetType, LhsValue, RhsValue, RhsValues, Type,
TypeMismatchError,
CompoundType, ExpectedType, ExpectedTypeList, GetType, LhsValue, LiteralSet, LiteralValue,
Type, TypeMismatchError,
};
2 changes: 1 addition & 1 deletion engine/src/rhs_types/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::borrow::Borrow;
use std::cmp::Ordering;

/// [Uninhabited / empty type](https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types)
/// for `array` with traits we need for RHS values.
/// for `array` with traits we need for literal values.
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize)]
pub enum UninhabitedArray {}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/rhs_types/bool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::borrow::Borrow;
use std::cmp::Ordering;

/// [Uninhabited / empty type](https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types)
/// for `bool` with traits we need for RHS values.
/// for `bool` with traits we need for literal values.
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize)]
pub enum UninhabitedBool {}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/rhs_types/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::borrow::Borrow;
use std::cmp::Ordering;

/// [Uninhabited / empty type](https://doc.rust-lang.org/nomicon/exotic-sizes.html#empty-types)
/// for `map` with traits we need for RHS values.
/// for `map` with traits we need for literal values.
#[derive(Debug, PartialEq, Eq, Clone, Hash, Serialize)]
pub enum UninhabitedMap {}

Expand Down
14 changes: 7 additions & 7 deletions engine/src/scheme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::ast::{FilterAst, FilterValueAst};
use crate::functions::FunctionDefinition;
use crate::lex::{Lex, LexErrorKind, LexResult, LexWith, expect, span, take_while};
use crate::list_matcher::ListDefinition;
use crate::types::{GetType, RhsValue, Type};
use crate::types::{GetType, LiteralValue, Type};
use fnv::FnvBuildHasher;
use serde::de::Visitor;
use serde::ser::SerializeMap;
Expand Down Expand Up @@ -56,9 +56,9 @@ impl<'i> Lex<'i> for FieldIndex {
// The token inside an [] can be either an integer index into an Array
// or a string key into a Map. The token is a key into a Map if it
// starts and ends with "\"", otherwise an integer index or an error.
let (rhs, rest) = match expect(input, "\"") {
Ok(_) => RhsValue::lex_with(input, Type::Bytes),
Err(_) => RhsValue::lex_with(input, Type::Int).map_err(|_| {
let (literal, rest) = match expect(input, "\"") {
Ok(_) => LiteralValue::lex_with(input, Type::Bytes),
Err(_) => LiteralValue::lex_with(input, Type::Int).map_err(|_| {
(
LexErrorKind::ExpectedLiteral(
"expected quoted utf8 string or positive integer",
Expand All @@ -68,15 +68,15 @@ impl<'i> Lex<'i> for FieldIndex {
}),
}?;

match rhs {
RhsValue::Int(i) => match u32::try_from(i) {
match literal {
LiteralValue::Int(i) => match u32::try_from(i) {
Ok(u) => Ok((FieldIndex::ArrayIndex(u), rest)),
Err(_) => Err((
LexErrorKind::ExpectedLiteral("expected positive integer as index"),
input,
)),
},
RhsValue::Bytes(b) => match String::from_utf8(b.into()) {
LiteralValue::Bytes(b) => match String::from_utf8(b.into()) {
Ok(s) => Ok((FieldIndex::MapKey(s), rest)),
Err(_) => Err((LexErrorKind::ExpectedLiteral("expected utf8 string"), input)),
},
Expand Down
Loading
Loading