pub const DEFAULT_MIN_STRING_SIZE: usize = 1;
pub const DEFAULT_MAX_STRING_SIZE: usize = 12;
pub const DEFAULT_CHARSET: CharacterSet = CharacterSet::AlphaNumeric;
pub const DEFAULT_QUANTIFIER_VALUE: u64 = 1;
pub const DEFAULT_RANGE_MIN_VALUE: i64 = i32::MIN as i64;
pub const DEFAULT_RANGE_MAX_VALUE: i64 = i32::MAX as i64;
pub const DEFAULT_POSITIVE_RANGE_MIN_VALUE: u64 = u32::MIN as u64;
pub const DEFAULT_POSITIVE_RANGE_MAX_VALUE: u64 = u32::MAX as u64;
use crate::clex_language::lexer::Span;
#[derive(Debug, Clone, PartialEq)]
pub struct ClexLanguageAST {
pub expression: Vec<UnitExpression>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Repetition {
Exact(PositiveReferenceType),
Range(PositiveReferenceType, PositiveReferenceType),
}
#[derive(Debug, Clone, PartialEq)]
pub enum UnitExpression {
Primitives {
data_type: DataType,
repetition: Repetition,
span: Span,
},
CapturingGroup {
group_number: u64,
range: (PositiveReferenceType, PositiveReferenceType),
span: Span,
},
NonCapturingGroup {
branches: Vec<Vec<UnitExpression>>,
repetition: Repetition,
span: Span,
},
Literal { text: String, span: Span },
GraphPrimitive { kind: GraphKind, span: Span },
Eof,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum GraphKind {
Tree(PositiveReferenceType),
Graph(PositiveReferenceType, PositiveReferenceType),
Dag(PositiveReferenceType, PositiveReferenceType),
Permutation(PositiveReferenceType),
}
impl UnitExpression {
pub fn span(&self) -> Span {
match self {
UnitExpression::Primitives { span, .. }
| UnitExpression::CapturingGroup { span, .. }
| UnitExpression::NonCapturingGroup { span, .. }
| UnitExpression::Literal { span, .. }
| UnitExpression::GraphPrimitive { span, .. } => *span,
UnitExpression::Eof => Span { start: 0, end: 0 },
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum DataType {
Integer(ReferenceType, ReferenceType),
Float(FloatReferenceType, FloatReferenceType),
String(PositiveReferenceType, PositiveReferenceType, CharacterSet),
}
#[derive(Debug, Clone, PartialEq)]
pub enum FloatReferenceType {
ByGroup { group_number: u64 },
ByLiteral(f64),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ReferenceType {
ByGroup { group_number: u64 },
ByLiteral(i64),
ByLoopIndex { offset: i64 },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PositiveReferenceType {
ByGroup { group_number: u64 },
ByLiteral(u64),
ByLoopIndex { offset: i64 },
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CharacterSet {
Alphabet,
Numeric,
Newline,
AlphaNumeric,
Uppercase,
LowerCase,
All,
Custom(String),
}
impl CharacterSet {
pub fn get_default_charset() -> CharacterSet {
DEFAULT_CHARSET
}
pub fn get_character_domain(&self) -> String {
match self {
CharacterSet::Alphabet => {
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".to_string()
}
CharacterSet::Numeric => "0123456789".to_string(),
CharacterSet::AlphaNumeric => {
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".to_string()
}
CharacterSet::Uppercase => "ABCDEFGHIJKLMNOPQRSTUVWXYZ".to_string(),
CharacterSet::LowerCase => "abcdefghijklmnopqrstuvwxyz".to_string(),
CharacterSet::All => {
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789)(*&^%$#@!~"
.to_string()
}
CharacterSet::Newline => "\n".to_string(),
CharacterSet::Custom(charset) => charset.to_owned(),
}
}
}