use logos::Logos;
#[derive(Logos, Debug, Clone, PartialEq)]
#[logos(skip r"[ \t\r\n]+")] #[logos(skip(r"--[^\n]*", allow_greedy = true))] pub enum Token {
#[token("\u{feff}")]
Bom,
#[token("matches", ignore(case))]
#[token("is_in", ignore(case))]
#[token("\u{2208}")]
SymMatches,
#[token("\u{2209}")]
SymNotMatches,
#[token("and", ignore(case))]
#[token("\u{2227}")]
SymAnd,
#[token("or", ignore(case))]
#[token("\u{2228}")]
SymOr,
#[token("xor", ignore(case))]
#[token("\u{22BB}")]
SymXor,
#[token("not", ignore(case))]
#[token("~")]
#[token("\u{223C}")]
#[token("\u{00AC}")]
#[token("!")]
SymNot,
#[token("implies", ignore(case))]
#[token("\u{00AE}")]
#[token("->")]
#[token("\u{21D2}")]
#[token("\u{2192}")]
SymImplies,
#[token("\u{21D4}")]
#[token("\u{2194}")]
SymIff,
#[token("for_all", ignore(case))]
#[token("\u{2200}")]
SymForAll,
#[token("exists", ignore(case))]
#[token("\u{25A1}")]
SymExists,
#[token("there_exists")]
#[token("\u{2203}")]
SymThereExists,
#[token("in")]
SymIn,
#[token("occurrences", ignore(case))]
SymOccurrences,
#[token("existence", ignore(case))]
SymExistence,
#[token("cardinality", ignore(case))]
SymCardinality,
#[token("ordered", ignore(case))]
SymOrdered,
#[token("unordered", ignore(case))]
SymUnordered,
#[token("unique", ignore(case))]
SymUnique,
#[token("infinity", ignore(case))]
SymInfinity,
#[token("use_node", ignore(case))]
SymUseNode,
#[token("use_archetype", ignore(case))]
SymUseArchetype,
#[token("allow_archetype", ignore(case))]
SymAllowArchetype,
#[token("include", ignore(case))]
SymInclude,
#[token("exclude", ignore(case))]
SymExclude,
#[token("after", ignore(case))]
SymAfter,
#[token("before", ignore(case))]
SymBefore,
#[token("closed", ignore(case))]
SymClosed,
#[token("then", ignore(case))]
SymThen,
SymSelf,
SymResult,
SymCase,
SymChoice,
SymAssert,
#[token("true", ignore(case))]
SymTrue,
#[token("false", ignore(case))]
SymFalse,
#[regex(r"id1(\.1)*", |lex| lex.slice().to_owned(), priority = 22)]
RootIdCode(String),
#[regex(r"id(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))*", |lex| lex.slice().to_owned(), priority = 20)]
IdCode(String),
#[regex(r"at[0-9]+(\.[0-9]+)*", |lex| lex.slice().to_owned(), priority = 20)]
AtCode(String),
#[regex(r"ac[0-9]+(\.[0-9]+)*", |lex| lex.slice().to_owned(), priority = 20)]
AcCode(String),
#[regex(
r"([a-zA-Z][a-zA-Z0-9_.\-]*::)?[a-zA-Z][a-zA-Z0-9_]*-[a-zA-Z][a-zA-Z0-9_]*-[a-zA-Z][a-zA-Z0-9_]*\.[a-zA-Z][a-zA-Z0-9_-]*\.v[0-9]+(\.[0-9]+)*((-rc|-alpha|-beta)(\.[0-9]+)?)?",
|lex| lex.slice().to_owned()
)]
ArchetypeId(String),
#[regex(r"[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)*((-rc|-alpha|-beta)(\.[0-9]+)?)?", |lex| lex.slice().to_owned())]
VersionId(String),
#[regex(r"[0-9a-fA-F]+-[0-9a-fA-F]+-[0-9a-fA-F]+-[0-9a-fA-F]+-[0-9a-fA-F]+", |lex| lex.slice().to_owned())]
Guid(String),
#[regex(
r"[0-9]{4}-[0-9]{2}-[0-9]{2}T([0-9]{2}(:[0-9]{2}(:([0-9]{2}([.,][0-9]+)?|\?\?))?|:\?\?:\?\?)?|\?\?:\?\?:\?\?)(Z|[+\-][0-9]{4})?",
|lex| lex.slice().to_owned(),
priority = 30
)]
#[regex(
r"[0-9]{4}-([0-9]{2}-\?\?|\?\?-\?\?)T\?\?:\?\?:\?\?(Z|[+\-][0-9]{4})?",
|lex| lex.slice().to_owned(),
priority = 30
)]
#[regex(
r"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}(:[0-9]{2}([.,][0-9]+)?)?(Z|[+\-][0-9]{4})?",
|lex| lex.slice().to_owned(),
priority = 30
)]
Iso8601DateTime(String),
#[regex(
r"[0-9]{4}-([0-9]{2}(-([0-9]{2}|\?\?))?|\?\?-\?\?)",
|lex| lex.slice().to_owned(),
priority = 30
)]
Iso8601Date(String),
#[regex(
r"[0-9]{2}:([0-9]{2}(:([0-9]{2}([.,][0-9]+)?|\?\?))?|\?\?:\?\?)(Z|[+\-][0-9]{4})?",
|lex| lex.slice().to_owned(),
priority = 30
)]
Iso8601Time(String),
#[regex(
r"-?P([0-9]+[YyMmWwDd])+(T([0-9]+[HhMm])*[0-9]+([.,][0-9]+)?[Ss]|T([0-9]+[Hh])?([0-9]+[Mm])?([0-9]+([.,][0-9]+)?[Ss])?)?|-?PT([0-9]+[HhMm])*[0-9]+([.,][0-9]+)?[Ss]|-?PT([0-9]+[Hh])([0-9]+[Mm])?|-?PT[0-9]+[Mm]",
|lex| lex.slice().to_owned()
)]
Iso8601Duration(String),
#[regex(
r"(yyyy|YYYY|yyy|YYY|[0-9]{4})-(mm|MM|\?\?|XX|xx|[0-9]{2})-(dd|DD|\?\?|XX|xx|[0-9]{2})[T ](hh|HH|\?\?|XX|xx|[0-9]{2}):(mm|MM|\?\?|XX|xx|[0-9]{2}):(ss|SS|\?\?|XX|xx|[0-9]{2})([+\-\u{00B1}](hh|HH)(:?(mm|MM))?|Z)?",
|lex| lex.slice().to_owned(),
priority = 3
)]
DateTimeConstraintPattern(String),
#[regex(
r"(yyyy|YYYY|yyy|YYY|[0-9]{4})-(mm|MM|\?\?|XX|xx|[0-9]{2})-(dd|DD|\?\?|XX|xx|[0-9]{2})",
|lex| lex.slice().to_owned(),
priority = 3
)]
DateConstraintPattern(String),
#[regex(
r"(hh|HH|\?\?|XX|xx|[0-9]{2}):(mm|MM|\?\?|XX|xx|[0-9]{2}):(ss|SS|\?\?|XX|xx|[0-9]{2})([+\-\u{00B1}](hh|HH)(:?(mm|MM))?|Z)?",
|lex| lex.slice().to_owned(),
priority = 3
)]
TimeConstraintPattern(String),
#[regex(
r"P([Yy][Mm]?[Ww]?[Dd]?|[Mm][Ww]?[Dd]?|[Ww][Dd]?|[Dd])(T([Hh][Mm]?[Ss]?|[Mm][Ss]?|[Ss]))?|PT([Hh][Mm]?[Ss]?|[Mm][Ss]?|[Ss])",
|lex| lex.slice().to_owned(),
priority = 20
)]
DurationConstraintPattern(String),
#[regex(
r#"\{[ \t\r]*(/([^/\r\n\\]|\\.)+/|\^([^\^\r\n\\]|\\.)+\^)[ \t\r]*(;[ \t\r]*"([^"\\]|\\.)*")?[ \t\r]*\}"#,
|lex| lex.slice().to_owned()
)]
ContainedRegexp(String),
#[regex(r"\[[a-zA-Z0-9._\-]+(\([a-zA-Z0-9._\-]+\))?::[a-zA-Z0-9._\-]+\]", |lex| lex.slice().to_owned())]
TermCodeRef(String),
#[regex(r"\[[a-zA-Z][a-zA-Z0-9._\-]*\]", |lex| lex.slice().to_owned())]
LocalTermCodeRef(String),
#[regex(r"<#([^#]|#[^>])*#*#>", |lex| lex.slice().to_owned())]
PlugInBlock(String),
#[regex(r"<[ \t\r\n]*[a-zA-Z][a-zA-Z0-9+.\-]*:[^>]*>", |lex| lex.slice().to_owned())]
EmbeddedUri(String),
#[regex(
r"(/[a-zA-Z][a-zA-Z0-9_]*(\[[^\]\r\n]*\])?)+|[a-zA-Z][a-zA-Z0-9_]*(\[[^\]\r\n]*\])?(/[a-zA-Z][a-zA-Z0-9_]*(\[[^\]\r\n]*\])?)+",
|lex| lex.slice().to_owned()
)]
#[regex(
r"//[a-z][a-zA-Z0-9_]*(\[[^\]\r\n]*\])?(/[a-z][a-zA-Z0-9_]*(\[[^\]\r\n]*\])?)*|[a-z][a-zA-Z0-9_]*\[[^\]\r\n]*\]",
|lex| lex.slice().to_owned()
)]
AdlPath(String),
#[regex(r"[0-9]+\.[0-9]+([eE][+\-]?[0-9]+)?", |lex| lex.slice().to_owned())]
Real(String),
#[regex(r"[0-9]+([eE][+\-]?[0-9]+)?", |lex| lex.slice().to_owned())]
Integer(String),
#[regex(r#""([^"\\]|\\.)*""#, validate_string)]
String(String),
#[regex(r"'([^'\\\r\n]|\\.)'", validate_char)]
Character(String),
#[regex(r"\$[a-z][a-zA-Z0-9_]*(/[a-zA-Z][a-zA-Z0-9_]*(\[[^\]\r\n]*\])?)+", |lex| lex.slice().to_owned())]
VariableWithPath(String),
#[regex(r"\$[a-z][a-zA-Z0-9_]*", |lex| lex.slice().to_owned())]
VariableId(String),
#[regex(r"[A-Z][a-zA-Z0-9_]*", |lex| lex.slice().to_owned())]
AlphaUcId(String),
#[regex(r"[a-z][a-zA-Z0-9_]*", |lex| lex.slice().to_owned())]
AlphaLcId(String),
#[regex(r"_[a-zA-Z0-9_]*", |lex| lex.slice().to_owned())]
AlphaUnderscoreId(String),
#[token("(")]
LParen,
#[token(")")]
RParen,
#[token("[")]
LBracket,
#[token("]")]
RBracket,
#[token("{")]
LCurly,
#[token("}")]
RCurly,
#[token(",")]
SymComma,
#[token(";")]
SymSemiColon,
#[token(":=")]
#[token("::=")]
SymAssignment,
#[token(":")]
SymColon,
#[token("/=")]
#[token("!=")]
#[token("<>")]
#[token("\u{2260}")]
SymNe,
#[token("=")]
SymEq,
#[token("<=")]
#[token("\u{2264}")]
SymLe,
#[token(">=")]
#[token("\u{2265}")]
SymGe,
#[token(">")]
SymGt,
#[token("<")]
SymLt,
#[token("...")]
SymListContinue,
#[token("..")]
SymIvlSep,
#[token(".")]
SymDot,
#[token("|")]
SymIvlDelim,
#[token("\u{00A6}")]
SymBrokenBar,
#[token("+/-")]
#[token("\u{00B1}")]
SymPlusOrMinus,
#[token("+")]
SymPlus,
#[token("-")]
SymMinus,
#[token("*")]
#[token("\u{2217}")]
SymStar,
#[token("/")]
SymSlash,
#[token("%")]
SymPercent,
#[token("^")]
SymCarat,
#[token("@")]
SymAt,
}
fn validate_char(lex: &logos::Lexer<Token>) -> Result<String, ()> {
let raw = lex.slice();
crate::v1_1::escape::validate(raw).map_err(|_defect| ())?;
Ok(raw.to_owned())
}
fn validate_string(lex: &logos::Lexer<Token>) -> Result<String, ()> {
let raw = lex.slice();
crate::v1_1::escape::validate(raw).map_err(|_defect| ())?;
Ok(raw.to_owned())
}