difftreelog
refactor deduplicate operator definitions
in: master
9 files changed
crates/jrsonnet-rowan-parser/jsonnet.ungramdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/jsonnet.ungram
+++ b/crates/jrsonnet-rowan-parser/jsonnet.ungram
@@ -136,6 +136,7 @@
| '<<' | '>>'
| '+' | '-'
| '*' | '/' | '%'
+| 'META_OBJECT_APPLY!'
| 'ERROR_NO_OPERATOR!'
UnaryOperator =
crates/jrsonnet-rowan-parser/src/binary.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/binary.rs
+++ /dev/null
@@ -1,48 +0,0 @@
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum BinaryOperator {
- Mul,
- Div,
- Mod,
- Plus,
- Minus,
- ShiftLeft,
- ShiftRight,
- LessThan,
- GreaterThan,
- LessThanOrEqual,
- GreaterThanOrEqual,
- Equal,
- NotEqual,
- BitAnd,
- BitXor,
- BitOr,
- And,
- Or,
- In,
- ObjectApply,
- #[allow(dead_code)]
- Invalid,
-}
-
-impl BinaryOperator {
- pub fn binding_power(&self) -> (u8, u8) {
- match self {
- Self::ObjectApply => (22, 23),
- Self::Mul | Self::Div | Self::Mod => (20, 21),
- Self::Plus | Self::Minus => (18, 19),
- Self::ShiftLeft | Self::ShiftRight => (16, 17),
- Self::LessThan
- | Self::GreaterThan
- | Self::LessThanOrEqual
- | Self::GreaterThanOrEqual
- | Self::In => (14, 15),
- Self::Equal | Self::NotEqual => (12, 13),
- Self::BitAnd => (10, 11),
- Self::BitXor => (8, 9),
- Self::BitOr => (6, 7),
- Self::And => (4, 5),
- Self::Or => (2, 3),
- Self::Invalid => (0, 1),
- }
- }
-}
crates/jrsonnet-rowan-parser/src/generated/nodes.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/generated/nodes.rs
+++ b/crates/jrsonnet-rowan-parser/src/generated/nodes.rs
@@ -1005,6 +1005,7 @@
Mul,
Div,
Modulo,
+ MetaObjectApply,
ErrorNoOperator,
}
@@ -2508,101 +2509,51 @@
}
impl AstToken for BinaryOperator {
fn can_cast(kind: SyntaxKind) -> bool {
+ BinaryOperatorKind::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = BinaryOperatorKind::cast(syntax.kind())?;
+ Some(BinaryOperator { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+}
+impl BinaryOperatorKind {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | IN_KW | LHS
- | RHS | PLUS | MINUS | MUL | DIV | MODULO | ERROR_NO_OPERATOR => true,
+ | RHS | PLUS | MINUS | MUL | DIV | MODULO | META_OBJECT_APPLY | ERROR_NO_OPERATOR => true,
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- OR => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Or,
- },
- AND => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::And,
- },
- BIT_OR => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::BitOr,
- },
- BIT_XOR => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::BitXor,
- },
- BIT_AND => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::BitAnd,
- },
- EQ => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Eq,
- },
- NE => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Ne,
- },
- LT => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Lt,
- },
- GT => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Gt,
- },
- LE => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Le,
- },
- GE => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Ge,
- },
- IN_KW => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::InKw,
- },
- LHS => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Lhs,
- },
- RHS => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Rhs,
- },
- PLUS => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Plus,
- },
- MINUS => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Minus,
- },
- MUL => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Mul,
- },
- DIV => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Div,
- },
- MODULO => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::Modulo,
- },
- ERROR_NO_OPERATOR => BinaryOperator {
- syntax,
- kind: BinaryOperatorKind::ErrorNoOperator,
- },
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ OR => Self::Or,
+ AND => Self::And,
+ BIT_OR => Self::BitOr,
+ BIT_XOR => Self::BitXor,
+ BIT_AND => Self::BitAnd,
+ EQ => Self::Eq,
+ NE => Self::Ne,
+ LT => Self::Lt,
+ GT => Self::Gt,
+ LE => Self::Le,
+ GE => Self::Ge,
+ IN_KW => Self::InKw,
+ LHS => Self::Lhs,
+ RHS => Self::Rhs,
+ PLUS => Self::Plus,
+ MINUS => Self::Minus,
+ MUL => Self::Mul,
+ DIV => Self::Div,
+ MODULO => Self::Modulo,
+ META_OBJECT_APPLY => Self::MetaObjectApply,
+ ERROR_NO_OPERATOR => Self::ErrorNoOperator,
_ => return None,
};
Some(res)
}
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
- }
}
impl BinaryOperator {
pub fn kind(&self) -> BinaryOperatorKind {
@@ -2616,31 +2567,31 @@
}
impl AstToken for UnaryOperator {
fn can_cast(kind: SyntaxKind) -> bool {
+ UnaryOperatorKind::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = UnaryOperatorKind::cast(syntax.kind())?;
+ Some(UnaryOperator { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+}
+impl UnaryOperatorKind {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
MINUS | NOT | BIT_NOT => true,
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- MINUS => UnaryOperator {
- syntax,
- kind: UnaryOperatorKind::Minus,
- },
- NOT => UnaryOperator {
- syntax,
- kind: UnaryOperatorKind::Not,
- },
- BIT_NOT => UnaryOperator {
- syntax,
- kind: UnaryOperatorKind::BitNot,
- },
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ MINUS => Self::Minus,
+ NOT => Self::Not,
+ BIT_NOT => Self::BitNot,
_ => return None,
};
Some(res)
- }
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
}
}
impl UnaryOperator {
@@ -2655,44 +2606,35 @@
}
impl AstToken for Literal {
fn can_cast(kind: SyntaxKind) -> bool {
+ LiteralKind::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = LiteralKind::cast(syntax.kind())?;
+ Some(Literal { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+}
+impl LiteralKind {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
NULL_KW | TRUE_KW | FALSE_KW | SELF_KW | DOLLAR | SUPER_KW => true,
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- NULL_KW => Literal {
- syntax,
- kind: LiteralKind::NullKw,
- },
- TRUE_KW => Literal {
- syntax,
- kind: LiteralKind::TrueKw,
- },
- FALSE_KW => Literal {
- syntax,
- kind: LiteralKind::FalseKw,
- },
- SELF_KW => Literal {
- syntax,
- kind: LiteralKind::SelfKw,
- },
- DOLLAR => Literal {
- syntax,
- kind: LiteralKind::Dollar,
- },
- SUPER_KW => Literal {
- syntax,
- kind: LiteralKind::SuperKw,
- },
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ NULL_KW => Self::NullKw,
+ TRUE_KW => Self::TrueKw,
+ FALSE_KW => Self::FalseKw,
+ SELF_KW => Self::SelfKw,
+ DOLLAR => Self::Dollar,
+ SUPER_KW => Self::SuperKw,
_ => return None,
};
Some(res)
}
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
- }
}
impl Literal {
pub fn kind(&self) -> LiteralKind {
@@ -2706,6 +2648,18 @@
}
impl AstToken for Text {
fn can_cast(kind: SyntaxKind) -> bool {
+ TextKind::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = TextKind::cast(syntax.kind())?;
+ Some(Text { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+}
+impl TextKind {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
STRING_DOUBLE
| ERROR_STRING_DOUBLE_UNTERMINATED
@@ -2724,71 +2678,30 @@
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- STRING_DOUBLE => Text {
- syntax,
- kind: TextKind::StringDouble,
- },
- ERROR_STRING_DOUBLE_UNTERMINATED => Text {
- syntax,
- kind: TextKind::ErrorStringDoubleUnterminated,
- },
- STRING_SINGLE => Text {
- syntax,
- kind: TextKind::StringSingle,
- },
- ERROR_STRING_SINGLE_UNTERMINATED => Text {
- syntax,
- kind: TextKind::ErrorStringSingleUnterminated,
- },
- STRING_DOUBLE_VERBATIM => Text {
- syntax,
- kind: TextKind::StringDoubleVerbatim,
- },
- ERROR_STRING_DOUBLE_VERBATIM_UNTERMINATED => Text {
- syntax,
- kind: TextKind::ErrorStringDoubleVerbatimUnterminated,
- },
- STRING_SINGLE_VERBATIM => Text {
- syntax,
- kind: TextKind::StringSingleVerbatim,
- },
- ERROR_STRING_SINGLE_VERBATIM_UNTERMINATED => Text {
- syntax,
- kind: TextKind::ErrorStringSingleVerbatimUnterminated,
- },
- ERROR_STRING_VERBATIM_MISSING_QUOTES => Text {
- syntax,
- kind: TextKind::ErrorStringVerbatimMissingQuotes,
- },
- STRING_BLOCK => Text {
- syntax,
- kind: TextKind::StringBlock,
- },
- ERROR_STRING_BLOCK_UNEXPECTED_END => Text {
- syntax,
- kind: TextKind::ErrorStringBlockUnexpectedEnd,
- },
- ERROR_STRING_BLOCK_MISSING_NEW_LINE => Text {
- syntax,
- kind: TextKind::ErrorStringBlockMissingNewLine,
- },
- ERROR_STRING_BLOCK_MISSING_TERMINATION => Text {
- syntax,
- kind: TextKind::ErrorStringBlockMissingTermination,
- },
- ERROR_STRING_BLOCK_MISSING_INDENT => Text {
- syntax,
- kind: TextKind::ErrorStringBlockMissingIndent,
- },
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ STRING_DOUBLE => Self::StringDouble,
+ ERROR_STRING_DOUBLE_UNTERMINATED => Self::ErrorStringDoubleUnterminated,
+ STRING_SINGLE => Self::StringSingle,
+ ERROR_STRING_SINGLE_UNTERMINATED => Self::ErrorStringSingleUnterminated,
+ STRING_DOUBLE_VERBATIM => Self::StringDoubleVerbatim,
+ ERROR_STRING_DOUBLE_VERBATIM_UNTERMINATED => {
+ Self::ErrorStringDoubleVerbatimUnterminated
+ }
+ STRING_SINGLE_VERBATIM => Self::StringSingleVerbatim,
+ ERROR_STRING_SINGLE_VERBATIM_UNTERMINATED => {
+ Self::ErrorStringSingleVerbatimUnterminated
+ }
+ ERROR_STRING_VERBATIM_MISSING_QUOTES => Self::ErrorStringVerbatimMissingQuotes,
+ STRING_BLOCK => Self::StringBlock,
+ ERROR_STRING_BLOCK_UNEXPECTED_END => Self::ErrorStringBlockUnexpectedEnd,
+ ERROR_STRING_BLOCK_MISSING_NEW_LINE => Self::ErrorStringBlockMissingNewLine,
+ ERROR_STRING_BLOCK_MISSING_TERMINATION => Self::ErrorStringBlockMissingTermination,
+ ERROR_STRING_BLOCK_MISSING_INDENT => Self::ErrorStringBlockMissingIndent,
_ => return None,
};
Some(res)
}
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
- }
}
impl Text {
pub fn kind(&self) -> TextKind {
@@ -2802,6 +2715,18 @@
}
impl AstToken for Number {
fn can_cast(kind: SyntaxKind) -> bool {
+ NumberKind::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = NumberKind::cast(syntax.kind())?;
+ Some(Number { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+}
+impl NumberKind {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
FLOAT
| ERROR_FLOAT_JUNK_AFTER_POINT
@@ -2810,31 +2735,16 @@
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- FLOAT => Number {
- syntax,
- kind: NumberKind::Float,
- },
- ERROR_FLOAT_JUNK_AFTER_POINT => Number {
- syntax,
- kind: NumberKind::ErrorFloatJunkAfterPoint,
- },
- ERROR_FLOAT_JUNK_AFTER_EXPONENT => Number {
- syntax,
- kind: NumberKind::ErrorFloatJunkAfterExponent,
- },
- ERROR_FLOAT_JUNK_AFTER_EXPONENT_SIGN => Number {
- syntax,
- kind: NumberKind::ErrorFloatJunkAfterExponentSign,
- },
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ FLOAT => Self::Float,
+ ERROR_FLOAT_JUNK_AFTER_POINT => Self::ErrorFloatJunkAfterPoint,
+ ERROR_FLOAT_JUNK_AFTER_EXPONENT => Self::ErrorFloatJunkAfterExponent,
+ ERROR_FLOAT_JUNK_AFTER_EXPONENT_SIGN => Self::ErrorFloatJunkAfterExponentSign,
_ => return None,
};
Some(res)
}
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
- }
}
impl Number {
pub fn kind(&self) -> NumberKind {
@@ -2848,32 +2758,32 @@
}
impl AstToken for ImportKind {
fn can_cast(kind: SyntaxKind) -> bool {
+ ImportKindKind::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = ImportKindKind::cast(syntax.kind())?;
+ Some(ImportKind { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+}
+impl ImportKindKind {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
IMPORTSTR_KW | IMPORTBIN_KW | IMPORT_KW => true,
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- IMPORTSTR_KW => ImportKind {
- syntax,
- kind: ImportKindKind::ImportstrKw,
- },
- IMPORTBIN_KW => ImportKind {
- syntax,
- kind: ImportKindKind::ImportbinKw,
- },
- IMPORT_KW => ImportKind {
- syntax,
- kind: ImportKindKind::ImportKw,
- },
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ IMPORTSTR_KW => Self::ImportstrKw,
+ IMPORTBIN_KW => Self::ImportbinKw,
+ IMPORT_KW => Self::ImportKw,
_ => return None,
};
Some(res)
}
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
- }
}
impl ImportKind {
pub fn kind(&self) -> ImportKindKind {
@@ -2887,31 +2797,31 @@
}
impl AstToken for Visibility {
fn can_cast(kind: SyntaxKind) -> bool {
+ VisibilityKind::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = VisibilityKind::cast(syntax.kind())?;
+ Some(Visibility { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+}
+impl VisibilityKind {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
COLONCOLONCOLON | COLONCOLON | COLON => true,
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- COLONCOLONCOLON => Visibility {
- syntax,
- kind: VisibilityKind::Coloncoloncolon,
- },
- COLONCOLON => Visibility {
- syntax,
- kind: VisibilityKind::Coloncolon,
- },
- COLON => Visibility {
- syntax,
- kind: VisibilityKind::Colon,
- },
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ COLONCOLONCOLON => Self::Coloncoloncolon,
+ COLONCOLON => Self::Coloncolon,
+ COLON => Self::Colon,
_ => return None,
};
Some(res)
- }
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
}
}
impl Visibility {
@@ -2926,6 +2836,18 @@
}
impl AstToken for Trivia {
fn can_cast(kind: SyntaxKind) -> bool {
+ TriviaKind::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = TriviaKind::cast(syntax.kind())?;
+ Some(Trivia { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+}
+impl TriviaKind {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
WHITESPACE
| MULTI_LINE_COMMENT
@@ -2936,38 +2858,17 @@
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- WHITESPACE => Trivia {
- syntax,
- kind: TriviaKind::Whitespace,
- },
- MULTI_LINE_COMMENT => Trivia {
- syntax,
- kind: TriviaKind::MultiLineComment,
- },
- ERROR_COMMENT_TOO_SHORT => Trivia {
- syntax,
- kind: TriviaKind::ErrorCommentTooShort,
- },
- ERROR_COMMENT_UNTERMINATED => Trivia {
- syntax,
- kind: TriviaKind::ErrorCommentUnterminated,
- },
- SINGLE_LINE_HASH_COMMENT => Trivia {
- syntax,
- kind: TriviaKind::SingleLineHashComment,
- },
- SINGLE_LINE_SLASH_COMMENT => Trivia {
- syntax,
- kind: TriviaKind::SingleLineSlashComment,
- },
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ WHITESPACE => Self::Whitespace,
+ MULTI_LINE_COMMENT => Self::MultiLineComment,
+ ERROR_COMMENT_TOO_SHORT => Self::ErrorCommentTooShort,
+ ERROR_COMMENT_UNTERMINATED => Self::ErrorCommentUnterminated,
+ SINGLE_LINE_HASH_COMMENT => Self::SingleLineHashComment,
+ SINGLE_LINE_SLASH_COMMENT => Self::SingleLineSlashComment,
_ => return None,
};
Some(res)
- }
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
}
}
impl Trivia {
crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rsdiffbeforeafterboth1//! This is a generated file, please do not edit manually. Changes can be2//! made in codegeneration that lives in `xtask` top-level dir.34#![allow(5 bad_style,6 missing_docs,7 unreachable_pub,8 clippy::manual_non_exhaustive,9 clippy::match_like_matches_macro10)]11use logos::Logos;12#[doc = r" The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT`."]13#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Logos)]14#[repr(u16)]15pub enum SyntaxKind {16 #[doc(hidden)]17 TOMBSTONE,18 #[doc(hidden)]19 EOF,20 #[token("||")]21 OR,22 #[token("&&")]23 AND,24 #[token("|")]25 BIT_OR,26 #[token("^")]27 BIT_XOR,28 #[token("&")]29 BIT_AND,30 #[token("==")]31 EQ,32 #[token("!=")]33 NE,34 #[token("<")]35 LT,36 #[token(">")]37 GT,38 #[token("<=")]39 LE,40 #[token(">=")]41 GE,42 #[token("<<")]43 LHS,44 #[token(">>")]45 RHS,46 #[token("+")]47 PLUS,48 #[token("-")]49 MINUS,50 #[token("*")]51 MUL,52 #[token("/")]53 DIV,54 #[token("%")]55 MODULO,56 #[token("!")]57 NOT,58 #[token("~")]59 BIT_NOT,60 #[token("[")]61 L_BRACK,62 #[token("]")]63 R_BRACK,64 #[token("(")]65 L_PAREN,66 #[token(")")]67 R_PAREN,68 #[token("{")]69 L_BRACE,70 #[token("}")]71 R_BRACE,72 #[token(":")]73 COLON,74 #[token("::")]75 COLONCOLON,76 #[token(":::")]77 COLONCOLONCOLON,78 #[token(";")]79 SEMI,80 #[token(".")]81 DOT,82 #[token("...")]83 DOTDOTDOT,84 #[token(",")]85 COMMA,86 #[token("$")]87 DOLLAR,88 #[token("=")]89 ASSIGN,90 #[token("?")]91 QUESTION_MARK,92 #[token("$intrinsicThisFile")]93 INTRINSIC_THIS_FILE,94 #[token("$intrinsicId")]95 INTRINSIC_ID,96 #[token("$intrinsic")]97 INTRINSIC,98 #[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?")]99 FLOAT,100 #[regex("(?:0|[1-9][0-9]*)\\.[^0-9]")]101 ERROR_FLOAT_JUNK_AFTER_POINT,102 #[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?[eE][^+\\-0-9]")]103 ERROR_FLOAT_JUNK_AFTER_EXPONENT,104 #[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?[eE][+-][^0-9]")]105 ERROR_FLOAT_JUNK_AFTER_EXPONENT_SIGN,106 #[regex("\"(?s:[^\"\\\\]|\\\\.)*\"")]107 STRING_DOUBLE,108 #[regex("\"(?s:[^\"\\\\]|\\\\.)*")]109 ERROR_STRING_DOUBLE_UNTERMINATED,110 #[regex("'(?s:[^'\\\\]|\\\\.)*'")]111 STRING_SINGLE,112 #[regex("'(?s:[^'\\\\]|\\\\.)*")]113 ERROR_STRING_SINGLE_UNTERMINATED,114 #[regex("@\"(?:[^\"]|\"\")*\"")]115 STRING_DOUBLE_VERBATIM,116 #[regex("@\"(?:[^\"]|\"\")*")]117 ERROR_STRING_DOUBLE_VERBATIM_UNTERMINATED,118 #[regex("@'(?:[^']|'')*'")]119 STRING_SINGLE_VERBATIM,120 #[regex("@'(?:[^']|'')*")]121 ERROR_STRING_SINGLE_VERBATIM_UNTERMINATED,122 #[regex("@[^\"'\\s]\\S+")]123 ERROR_STRING_VERBATIM_MISSING_QUOTES,124 #[regex("\\|\\|\\|", crate::string_block::lex_str_block_test)]125 STRING_BLOCK,126 ERROR_STRING_BLOCK_UNEXPECTED_END,127 ERROR_STRING_BLOCK_MISSING_NEW_LINE,128 ERROR_STRING_BLOCK_MISSING_TERMINATION,129 ERROR_STRING_BLOCK_MISSING_INDENT,130 #[regex("[_a-zA-Z][_a-zA-Z0-9]*")]131 IDENT,132 #[regex("[ \\t\\n\\r]+")]133 WHITESPACE,134 #[regex("//[^\\r\\n]*(\\r\\n|\\n)?")]135 SINGLE_LINE_SLASH_COMMENT,136 #[regex("#[^\\r\\n]*(\\r\\n|\\n)?")]137 SINGLE_LINE_HASH_COMMENT,138 #[regex("/\\*([^*]|\\*[^/])*\\*/")]139 MULTI_LINE_COMMENT,140 #[regex("/\\*/")]141 ERROR_COMMENT_TOO_SHORT,142 #[regex("/\\*([^*]|\\*[^/])+")]143 ERROR_COMMENT_UNTERMINATED,144 #[token("tailstrict")]145 TAILSTRICT_KW,146 #[token("importstr")]147 IMPORTSTR_KW,148 #[token("importbin")]149 IMPORTBIN_KW,150 #[token("import")]151 IMPORT_KW,152 #[token("local")]153 LOCAL_KW,154 #[token("if")]155 IF_KW,156 #[token("then")]157 THEN_KW,158 #[token("else")]159 ELSE_KW,160 #[token("function")]161 FUNCTION_KW,162 #[token("error")]163 ERROR_KW,164 #[token("in")]165 IN_KW,166 ERROR_NO_OPERATOR,167 #[token("null")]168 NULL_KW,169 #[token("true")]170 TRUE_KW,171 #[token("false")]172 FALSE_KW,173 #[token("self")]174 SELF_KW,175 #[token("super")]176 SUPER_KW,177 #[token("for")]178 FOR_KW,179 #[token("assert")]180 ASSERT_KW,181 #[error]182 ERROR,183 SOURCE_FILE,184 EXPR_BINARY,185 LHS_EXPR,186 EXPR_UNARY,187 EXPR_SLICE,188 SLICE_DESC,189 EXPR_INDEX,190 NAME,191 EXPR_INDEX_EXPR,192 EXPR_APPLY,193 ARGS_DESC,194 EXPR_OBJ_EXTEND,195 EXPR_PARENED,196 EXPR_LITERAL,197 EXPR_INTRINSIC_THIS_FILE,198 EXPR_INTRINSIC_ID,199 EXPR_INTRINSIC,200 EXPR_STRING,201 EXPR_NUMBER,202 EXPR_ARRAY,203 EXPR_OBJECT,204 EXPR_ARRAY_COMP,205 EXPR_IMPORT,206 EXPR_VAR,207 EXPR_LOCAL,208 EXPR_IF_THEN_ELSE,209 TRUE_EXPR,210 FALSE_EXPR,211 EXPR_FUNCTION,212 PARAMS_DESC,213 EXPR_ASSERT,214 ASSERTION,215 EXPR_ERROR,216 SLICE_DESC_END,217 SLICE_DESC_STEP,218 ARG,219 OBJ_BODY_COMP,220 OBJ_LOCAL_POST_COMMA,221 OBJ_LOCAL_PRE_COMMA,222 OBJ_BODY_MEMBER_LIST,223 OBJ_LOCAL,224 MEMBER_BIND_STMT,225 MEMBER_ASSERT_STMT,226 MEMBER_FIELD,227 FIELD_NORMAL,228 FIELD_METHOD,229 FIELD_NAME_FIXED,230 FIELD_NAME_DYNAMIC,231 FOR_SPEC,232 IF_SPEC,233 BIND_DESTRUCT,234 BIND_FUNCTION,235 PARAM,236 DESTRUCT_FULL,237 DESTRUCT_SKIP,238 DESTRUCT_ARRAY,239 DESTRUCT_OBJECT,240 DESTRUCT_OBJECT_FIELD,241 DESTRUCT_REST,242 DESTRUCT_ARRAY_ELEMENT,243 EXPR,244 OBJ_BODY,245 COMP_SPEC,246 BIND,247 MEMBER,248 FIELD,249 FIELD_NAME,250 DESTRUCT,251 DESTRUCT_ARRAY_PART,252 BINARY_OPERATOR,253 UNARY_OPERATOR,254 LITERAL,255 TEXT,256 NUMBER,257 IMPORT_KIND,258 VISIBILITY,259 TRIVIA,260 #[doc(hidden)]261 __LAST,262}263use self::SyntaxKind::*;264impl SyntaxKind {265 pub fn is_keyword(self) -> bool {266 match self {267 OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | LHS | RHS268 | PLUS | MINUS | MUL | DIV | MODULO | NOT | BIT_NOT | L_BRACK | R_BRACK | L_PAREN269 | R_PAREN | L_BRACE | R_BRACE | COLON | COLONCOLON | COLONCOLONCOLON | SEMI | DOT270 | DOTDOTDOT | COMMA | DOLLAR | ASSIGN | QUESTION_MARK | INTRINSIC_THIS_FILE271 | INTRINSIC_ID | INTRINSIC | TAILSTRICT_KW | IMPORTSTR_KW | IMPORTBIN_KW272 | IMPORT_KW | LOCAL_KW | IF_KW | THEN_KW | ELSE_KW | FUNCTION_KW | ERROR_KW | IN_KW273 | NULL_KW | TRUE_KW | FALSE_KW | SELF_KW | SUPER_KW | FOR_KW | ASSERT_KW => true,274 _ => false,275 }276 }277 pub fn is_enum(self) -> bool {278 match self {279 EXPR | OBJ_BODY | COMP_SPEC | BIND | MEMBER | FIELD | FIELD_NAME | DESTRUCT280 | DESTRUCT_ARRAY_PART | BINARY_OPERATOR | UNARY_OPERATOR | LITERAL | TEXT | NUMBER281 | IMPORT_KIND | VISIBILITY | TRIVIA => true,282 _ => false,283 }284 }285 pub fn from_raw(r: u16) -> Self {286 assert!(r < Self::__LAST as u16);287 unsafe { std::mem::transmute(r) }288 }289 pub fn into_raw(self) -> u16 {290 self as u16291 }292}293#[macro_export]294macro_rules ! T { [||] => { $ crate :: SyntaxKind :: OR } ; [&&] => { $ crate :: SyntaxKind :: AND } ; [|] => { $ crate :: SyntaxKind :: BIT_OR } ; [^] => { $ crate :: SyntaxKind :: BIT_XOR } ; [&] => { $ crate :: SyntaxKind :: BIT_AND } ; [==] => { $ crate :: SyntaxKind :: EQ } ; [!=] => { $ crate :: SyntaxKind :: NE } ; [<] => { $ crate :: SyntaxKind :: LT } ; [>] => { $ crate :: SyntaxKind :: GT } ; [<=] => { $ crate :: SyntaxKind :: LE } ; [>=] => { $ crate :: SyntaxKind :: GE } ; [<<] => { $ crate :: SyntaxKind :: LHS } ; [>>] => { $ crate :: SyntaxKind :: RHS } ; [+] => { $ crate :: SyntaxKind :: PLUS } ; [-] => { $ crate :: SyntaxKind :: MINUS } ; [*] => { $ crate :: SyntaxKind :: MUL } ; [/] => { $ crate :: SyntaxKind :: DIV } ; [%] => { $ crate :: SyntaxKind :: MODULO } ; [!] => { $ crate :: SyntaxKind :: NOT } ; [~] => { $ crate :: SyntaxKind :: BIT_NOT } ; ['['] => { $ crate :: SyntaxKind :: L_BRACK } ; [']'] => { $ crate :: SyntaxKind :: R_BRACK } ; ['('] => { $ crate :: SyntaxKind :: L_PAREN } ; [')'] => { $ crate :: SyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: SyntaxKind :: L_BRACE } ; ['}'] => { $ crate :: SyntaxKind :: R_BRACE } ; [:] => { $ crate :: SyntaxKind :: COLON } ; [::] => { $ crate :: SyntaxKind :: COLONCOLON } ; [:::] => { $ crate :: SyntaxKind :: COLONCOLONCOLON } ; [;] => { $ crate :: SyntaxKind :: SEMI } ; [.] => { $ crate :: SyntaxKind :: DOT } ; [...] => { $ crate :: SyntaxKind :: DOTDOTDOT } ; [,] => { $ crate :: SyntaxKind :: COMMA } ; ['$'] => { $ crate :: SyntaxKind :: DOLLAR } ; [=] => { $ crate :: SyntaxKind :: ASSIGN } ; [?] => { $ crate :: SyntaxKind :: QUESTION_MARK } ; ["$intrinsicThisFile"] => { $ crate :: SyntaxKind :: INTRINSIC_THIS_FILE } ; ["$intrinsicId"] => { $ crate :: SyntaxKind :: INTRINSIC_ID } ; ["$intrinsic"] => { $ crate :: SyntaxKind :: INTRINSIC } ; [tailstrict] => { $ crate :: SyntaxKind :: TAILSTRICT_KW } ; [importstr] => { $ crate :: SyntaxKind :: IMPORTSTR_KW } ; [importbin] => { $ crate :: SyntaxKind :: IMPORTBIN_KW } ; [import] => { $ crate :: SyntaxKind :: IMPORT_KW } ; [local] => { $ crate :: SyntaxKind :: LOCAL_KW } ; [if] => { $ crate :: SyntaxKind :: IF_KW } ; [then] => { $ crate :: SyntaxKind :: THEN_KW } ; [else] => { $ crate :: SyntaxKind :: ELSE_KW } ; [function] => { $ crate :: SyntaxKind :: FUNCTION_KW } ; [error] => { $ crate :: SyntaxKind :: ERROR_KW } ; [in] => { $ crate :: SyntaxKind :: IN_KW } ; [null] => { $ crate :: SyntaxKind :: NULL_KW } ; [true] => { $ crate :: SyntaxKind :: TRUE_KW } ; [false] => { $ crate :: SyntaxKind :: FALSE_KW } ; [self] => { $ crate :: SyntaxKind :: SELF_KW } ; [super] => { $ crate :: SyntaxKind :: SUPER_KW } ; [for] => { $ crate :: SyntaxKind :: FOR_KW } ; [assert] => { $ crate :: SyntaxKind :: ASSERT_KW } }295pub use T;1//! This is a generated file, please do not edit manually. Changes can be2//! made in codegeneration that lives in `xtask` top-level dir.34#![allow(5 bad_style,6 missing_docs,7 unreachable_pub,8 clippy::manual_non_exhaustive,9 clippy::match_like_matches_macro10)]11use logos::Logos;12#[doc = r" The kind of syntax node, e.g. `IDENT`, `USE_KW`, or `STRUCT`."]13#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Logos)]14#[repr(u16)]15pub enum SyntaxKind {16 #[doc(hidden)]17 TOMBSTONE,18 #[doc(hidden)]19 EOF,20 #[token("||")]21 OR,22 #[token("&&")]23 AND,24 #[token("|")]25 BIT_OR,26 #[token("^")]27 BIT_XOR,28 #[token("&")]29 BIT_AND,30 #[token("==")]31 EQ,32 #[token("!=")]33 NE,34 #[token("<")]35 LT,36 #[token(">")]37 GT,38 #[token("<=")]39 LE,40 #[token(">=")]41 GE,42 #[token("<<")]43 LHS,44 #[token(">>")]45 RHS,46 #[token("+")]47 PLUS,48 #[token("-")]49 MINUS,50 #[token("*")]51 MUL,52 #[token("/")]53 DIV,54 #[token("%")]55 MODULO,56 #[token("!")]57 NOT,58 #[token("~")]59 BIT_NOT,60 #[token("[")]61 L_BRACK,62 #[token("]")]63 R_BRACK,64 #[token("(")]65 L_PAREN,66 #[token(")")]67 R_PAREN,68 #[token("{")]69 L_BRACE,70 #[token("}")]71 R_BRACE,72 #[token(":")]73 COLON,74 #[token("::")]75 COLONCOLON,76 #[token(":::")]77 COLONCOLONCOLON,78 #[token(";")]79 SEMI,80 #[token(".")]81 DOT,82 #[token("...")]83 DOTDOTDOT,84 #[token(",")]85 COMMA,86 #[token("$")]87 DOLLAR,88 #[token("=")]89 ASSIGN,90 #[token("?")]91 QUESTION_MARK,92 #[token("$intrinsicThisFile")]93 INTRINSIC_THIS_FILE,94 #[token("$intrinsicId")]95 INTRINSIC_ID,96 #[token("$intrinsic")]97 INTRINSIC,98 #[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?(?:[eE][+-]?[0-9]+)?")]99 FLOAT,100 #[regex("(?:0|[1-9][0-9]*)\\.[^0-9]")]101 ERROR_FLOAT_JUNK_AFTER_POINT,102 #[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?[eE][^+\\-0-9]")]103 ERROR_FLOAT_JUNK_AFTER_EXPONENT,104 #[regex("(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?[eE][+-][^0-9]")]105 ERROR_FLOAT_JUNK_AFTER_EXPONENT_SIGN,106 #[regex("\"(?s:[^\"\\\\]|\\\\.)*\"")]107 STRING_DOUBLE,108 #[regex("\"(?s:[^\"\\\\]|\\\\.)*")]109 ERROR_STRING_DOUBLE_UNTERMINATED,110 #[regex("'(?s:[^'\\\\]|\\\\.)*'")]111 STRING_SINGLE,112 #[regex("'(?s:[^'\\\\]|\\\\.)*")]113 ERROR_STRING_SINGLE_UNTERMINATED,114 #[regex("@\"(?:[^\"]|\"\")*\"")]115 STRING_DOUBLE_VERBATIM,116 #[regex("@\"(?:[^\"]|\"\")*")]117 ERROR_STRING_DOUBLE_VERBATIM_UNTERMINATED,118 #[regex("@'(?:[^']|'')*'")]119 STRING_SINGLE_VERBATIM,120 #[regex("@'(?:[^']|'')*")]121 ERROR_STRING_SINGLE_VERBATIM_UNTERMINATED,122 #[regex("@[^\"'\\s]\\S+")]123 ERROR_STRING_VERBATIM_MISSING_QUOTES,124 #[regex("\\|\\|\\|", crate::string_block::lex_str_block_test)]125 STRING_BLOCK,126 ERROR_STRING_BLOCK_UNEXPECTED_END,127 ERROR_STRING_BLOCK_MISSING_NEW_LINE,128 ERROR_STRING_BLOCK_MISSING_TERMINATION,129 ERROR_STRING_BLOCK_MISSING_INDENT,130 #[regex("[_a-zA-Z][_a-zA-Z0-9]*")]131 IDENT,132 #[regex("[ \\t\\n\\r]+")]133 WHITESPACE,134 #[regex("//[^\\r\\n]*(\\r\\n|\\n)?")]135 SINGLE_LINE_SLASH_COMMENT,136 #[regex("#[^\\r\\n]*(\\r\\n|\\n)?")]137 SINGLE_LINE_HASH_COMMENT,138 #[regex("/\\*([^*]|\\*[^/])*\\*/")]139 MULTI_LINE_COMMENT,140 #[regex("/\\*/")]141 ERROR_COMMENT_TOO_SHORT,142 #[regex("/\\*([^*]|\\*[^/])+")]143 ERROR_COMMENT_UNTERMINATED,144 #[token("tailstrict")]145 TAILSTRICT_KW,146 #[token("importstr")]147 IMPORTSTR_KW,148 #[token("importbin")]149 IMPORTBIN_KW,150 #[token("import")]151 IMPORT_KW,152 #[token("local")]153 LOCAL_KW,154 #[token("if")]155 IF_KW,156 #[token("then")]157 THEN_KW,158 #[token("else")]159 ELSE_KW,160 #[token("function")]161 FUNCTION_KW,162 #[token("error")]163 ERROR_KW,164 #[token("in")]165 IN_KW,166 META_OBJECT_APPLY,167 ERROR_NO_OPERATOR,168 #[token("null")]169 NULL_KW,170 #[token("true")]171 TRUE_KW,172 #[token("false")]173 FALSE_KW,174 #[token("self")]175 SELF_KW,176 #[token("super")]177 SUPER_KW,178 #[token("for")]179 FOR_KW,180 #[token("assert")]181 ASSERT_KW,182 #[error]183 ERROR,184 SOURCE_FILE,185 EXPR_BINARY,186 LHS_EXPR,187 EXPR_UNARY,188 EXPR_SLICE,189 SLICE_DESC,190 EXPR_INDEX,191 NAME,192 EXPR_INDEX_EXPR,193 EXPR_APPLY,194 ARGS_DESC,195 EXPR_OBJ_EXTEND,196 EXPR_PARENED,197 EXPR_LITERAL,198 EXPR_INTRINSIC_THIS_FILE,199 EXPR_INTRINSIC_ID,200 EXPR_INTRINSIC,201 EXPR_STRING,202 EXPR_NUMBER,203 EXPR_ARRAY,204 EXPR_OBJECT,205 EXPR_ARRAY_COMP,206 EXPR_IMPORT,207 EXPR_VAR,208 EXPR_LOCAL,209 EXPR_IF_THEN_ELSE,210 TRUE_EXPR,211 FALSE_EXPR,212 EXPR_FUNCTION,213 PARAMS_DESC,214 EXPR_ASSERT,215 ASSERTION,216 EXPR_ERROR,217 SLICE_DESC_END,218 SLICE_DESC_STEP,219 ARG,220 OBJ_BODY_COMP,221 OBJ_LOCAL_POST_COMMA,222 OBJ_LOCAL_PRE_COMMA,223 OBJ_BODY_MEMBER_LIST,224 OBJ_LOCAL,225 MEMBER_BIND_STMT,226 MEMBER_ASSERT_STMT,227 MEMBER_FIELD,228 FIELD_NORMAL,229 FIELD_METHOD,230 FIELD_NAME_FIXED,231 FIELD_NAME_DYNAMIC,232 FOR_SPEC,233 IF_SPEC,234 BIND_DESTRUCT,235 BIND_FUNCTION,236 PARAM,237 DESTRUCT_FULL,238 DESTRUCT_SKIP,239 DESTRUCT_ARRAY,240 DESTRUCT_OBJECT,241 DESTRUCT_OBJECT_FIELD,242 DESTRUCT_REST,243 DESTRUCT_ARRAY_ELEMENT,244 EXPR,245 OBJ_BODY,246 COMP_SPEC,247 BIND,248 MEMBER,249 FIELD,250 FIELD_NAME,251 DESTRUCT,252 DESTRUCT_ARRAY_PART,253 BINARY_OPERATOR,254 UNARY_OPERATOR,255 LITERAL,256 TEXT,257 NUMBER,258 IMPORT_KIND,259 VISIBILITY,260 TRIVIA,261 #[doc(hidden)]262 __LAST,263}264use self::SyntaxKind::*;265impl SyntaxKind {266 pub fn is_keyword(self) -> bool {267 match self {268 OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | LHS | RHS269 | PLUS | MINUS | MUL | DIV | MODULO | NOT | BIT_NOT | L_BRACK | R_BRACK | L_PAREN270 | R_PAREN | L_BRACE | R_BRACE | COLON | COLONCOLON | COLONCOLONCOLON | SEMI | DOT271 | DOTDOTDOT | COMMA | DOLLAR | ASSIGN | QUESTION_MARK | INTRINSIC_THIS_FILE272 | INTRINSIC_ID | INTRINSIC | TAILSTRICT_KW | IMPORTSTR_KW | IMPORTBIN_KW273 | IMPORT_KW | LOCAL_KW | IF_KW | THEN_KW | ELSE_KW | FUNCTION_KW | ERROR_KW | IN_KW274 | NULL_KW | TRUE_KW | FALSE_KW | SELF_KW | SUPER_KW | FOR_KW | ASSERT_KW => true,275 _ => false,276 }277 }278 pub fn is_enum(self) -> bool {279 match self {280 EXPR | OBJ_BODY | COMP_SPEC | BIND | MEMBER | FIELD | FIELD_NAME | DESTRUCT281 | DESTRUCT_ARRAY_PART | BINARY_OPERATOR | UNARY_OPERATOR | LITERAL | TEXT | NUMBER282 | IMPORT_KIND | VISIBILITY | TRIVIA => true,283 _ => false,284 }285 }286 pub fn from_raw(r: u16) -> Self {287 assert!(r < Self::__LAST as u16);288 unsafe { std::mem::transmute(r) }289 }290 pub fn into_raw(self) -> u16 {291 self as u16292 }293}294#[macro_export]295macro_rules ! T { [||] => { $ crate :: SyntaxKind :: OR } ; [&&] => { $ crate :: SyntaxKind :: AND } ; [|] => { $ crate :: SyntaxKind :: BIT_OR } ; [^] => { $ crate :: SyntaxKind :: BIT_XOR } ; [&] => { $ crate :: SyntaxKind :: BIT_AND } ; [==] => { $ crate :: SyntaxKind :: EQ } ; [!=] => { $ crate :: SyntaxKind :: NE } ; [<] => { $ crate :: SyntaxKind :: LT } ; [>] => { $ crate :: SyntaxKind :: GT } ; [<=] => { $ crate :: SyntaxKind :: LE } ; [>=] => { $ crate :: SyntaxKind :: GE } ; [<<] => { $ crate :: SyntaxKind :: LHS } ; [>>] => { $ crate :: SyntaxKind :: RHS } ; [+] => { $ crate :: SyntaxKind :: PLUS } ; [-] => { $ crate :: SyntaxKind :: MINUS } ; [*] => { $ crate :: SyntaxKind :: MUL } ; [/] => { $ crate :: SyntaxKind :: DIV } ; [%] => { $ crate :: SyntaxKind :: MODULO } ; [!] => { $ crate :: SyntaxKind :: NOT } ; [~] => { $ crate :: SyntaxKind :: BIT_NOT } ; ['['] => { $ crate :: SyntaxKind :: L_BRACK } ; [']'] => { $ crate :: SyntaxKind :: R_BRACK } ; ['('] => { $ crate :: SyntaxKind :: L_PAREN } ; [')'] => { $ crate :: SyntaxKind :: R_PAREN } ; ['{'] => { $ crate :: SyntaxKind :: L_BRACE } ; ['}'] => { $ crate :: SyntaxKind :: R_BRACE } ; [:] => { $ crate :: SyntaxKind :: COLON } ; [::] => { $ crate :: SyntaxKind :: COLONCOLON } ; [:::] => { $ crate :: SyntaxKind :: COLONCOLONCOLON } ; [;] => { $ crate :: SyntaxKind :: SEMI } ; [.] => { $ crate :: SyntaxKind :: DOT } ; [...] => { $ crate :: SyntaxKind :: DOTDOTDOT } ; [,] => { $ crate :: SyntaxKind :: COMMA } ; ['$'] => { $ crate :: SyntaxKind :: DOLLAR } ; [=] => { $ crate :: SyntaxKind :: ASSIGN } ; [?] => { $ crate :: SyntaxKind :: QUESTION_MARK } ; ["$intrinsicThisFile"] => { $ crate :: SyntaxKind :: INTRINSIC_THIS_FILE } ; ["$intrinsicId"] => { $ crate :: SyntaxKind :: INTRINSIC_ID } ; ["$intrinsic"] => { $ crate :: SyntaxKind :: INTRINSIC } ; [tailstrict] => { $ crate :: SyntaxKind :: TAILSTRICT_KW } ; [importstr] => { $ crate :: SyntaxKind :: IMPORTSTR_KW } ; [importbin] => { $ crate :: SyntaxKind :: IMPORTBIN_KW } ; [import] => { $ crate :: SyntaxKind :: IMPORT_KW } ; [local] => { $ crate :: SyntaxKind :: LOCAL_KW } ; [if] => { $ crate :: SyntaxKind :: IF_KW } ; [then] => { $ crate :: SyntaxKind :: THEN_KW } ; [else] => { $ crate :: SyntaxKind :: ELSE_KW } ; [function] => { $ crate :: SyntaxKind :: FUNCTION_KW } ; [error] => { $ crate :: SyntaxKind :: ERROR_KW } ; [in] => { $ crate :: SyntaxKind :: IN_KW } ; [null] => { $ crate :: SyntaxKind :: NULL_KW } ; [true] => { $ crate :: SyntaxKind :: TRUE_KW } ; [false] => { $ crate :: SyntaxKind :: FALSE_KW } ; [self] => { $ crate :: SyntaxKind :: SELF_KW } ; [super] => { $ crate :: SyntaxKind :: SUPER_KW } ; [for] => { $ crate :: SyntaxKind :: FOR_KW } ; [assert] => { $ crate :: SyntaxKind :: ASSERT_KW } }296pub use T;crates/jrsonnet-rowan-parser/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/lib.rs
+++ b/crates/jrsonnet-rowan-parser/src/lib.rs
@@ -1,17 +1,16 @@
#![deny(unused_must_use)]
mod ast;
-mod binary;
mod event;
mod generated;
mod language;
mod lex;
mod marker;
mod parser;
+mod precedence;
mod string_block;
mod tests;
mod token_set;
-mod unary;
pub use ast::{AstChildren, AstNode, AstToken};
use event::Sink;
crates/jrsonnet-rowan-parser/src/parser.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/parser.rs
+++ b/crates/jrsonnet-rowan-parser/src/parser.rs
@@ -4,13 +4,11 @@
use rowan::{GreenNode, TextRange, TextSize};
use crate::{
- binary::BinaryOperator,
event::Event,
lex::Lexeme,
marker::{AsRange, CompletedMarker, Marker, Ranger},
- nodes::{Literal, Number, Text, Trivia},
+ nodes::{BinaryOperatorKind, Literal, Number, Text, Trivia, UnaryOperatorKind},
token_set::SyntaxKindSet,
- unary::UnaryOperator,
AstToken, SyntaxKind,
SyntaxKind::*,
SyntaxNode, T, TS,
@@ -397,18 +395,6 @@
enum ExpectedSyntaxTrackingState {
Named,
Unnamed,
-}
-macro_rules! at_match {
- ($p:ident {
- $($r:expr => $e:expr,)*
- _ => $else:expr $(,)?
- }) => {{
- $(
- if $p.at($r) {$e} else
- )* {
- $else
- }
- }}
}
fn expr(p: &mut Parser) -> Option<CompletedMarker> {
@@ -417,37 +403,16 @@
fn expr_binding_power(p: &mut Parser, minimum_binding_power: u8) -> Option<CompletedMarker> {
let mut lhs = lhs(p)?;
- loop {
- let op = at_match!(p {
- T![*] => BinaryOperator::Mul,
- T![/] => BinaryOperator::Div,
- T![%] => BinaryOperator::Mod,
- T![+] => BinaryOperator::Plus,
- T![-] => BinaryOperator::Minus,
- T![<<] => BinaryOperator::ShiftLeft,
- T![>>] => BinaryOperator::ShiftRight,
- T![<] => BinaryOperator::LessThan,
- T![>] => BinaryOperator::GreaterThan,
- T![<=] => BinaryOperator::LessThanOrEqual,
- T![>=] => BinaryOperator::GreaterThanOrEqual,
- T![==] => BinaryOperator::Equal,
- T![!=] => BinaryOperator::NotEqual,
- T![&] => BinaryOperator::BitAnd,
- T![^] => BinaryOperator::BitXor,
- T![|] => BinaryOperator::BitOr,
- T![&&] => BinaryOperator::And,
- T![||] => BinaryOperator::Or,
- T![in] => BinaryOperator::In,
- T!['{'] => BinaryOperator::ObjectApply,
- _ => break,
- });
+ while let Some(op) = BinaryOperatorKind::cast(p.current())
+ .or_else(|| p.at(T!['{']).then(|| BinaryOperatorKind::MetaObjectApply))
+ {
let (left_binding_power, right_binding_power) = op.binding_power();
if left_binding_power < minimum_binding_power {
break;
}
// Object apply is not a real operator, we dont have something to bump
- if op != BinaryOperator::ObjectApply {
+ if op != BinaryOperatorKind::MetaObjectApply {
p.bump();
}
@@ -455,7 +420,7 @@
let parsed_rhs = expr_binding_power(p, right_binding_power).is_some();
lhs = m.complete(
p,
- if op == BinaryOperator::ObjectApply {
+ if op == BinaryOperatorKind::MetaObjectApply {
EXPR_OBJ_EXTEND
} else {
EXPR_BINARY
@@ -998,13 +963,7 @@
p.bump();
text(p);
m.complete(p, EXPR_IMPORT)
- } else if p.at(T![-]) || p.at(T![!]) || p.at(T![~]) {
- let op = match p.current() {
- T![-] => UnaryOperator::Minus,
- T![!] => UnaryOperator::Not,
- T![~] => UnaryOperator::BitNegate,
- _ => unreachable!(),
- };
+ } else if let Some(op) = UnaryOperatorKind::cast(p.current()) {
let ((), right_binding_power) = op.binding_power();
let m = p.start();
crates/jrsonnet-rowan-parser/src/precedence.rsdiffbeforeafterboth--- /dev/null
+++ b/crates/jrsonnet-rowan-parser/src/precedence.rs
@@ -0,0 +1,30 @@
+use crate::nodes::{BinaryOperatorKind, UnaryOperatorKind};
+
+impl BinaryOperatorKind {
+ pub fn binding_power(&self) -> (u8, u8) {
+ match self {
+ Self::MetaObjectApply => (22, 23),
+ Self::Mul | Self::Div | Self::Modulo => (20, 21),
+ Self::Plus | Self::Minus => (18, 19),
+ Self::Lhs | Self::Rhs => (16, 17),
+ Self::Lt | Self::Gt | Self::Le | Self::Ge | Self::InKw => (14, 15),
+ Self::Eq | Self::Ne => (12, 13),
+ Self::BitAnd => (10, 11),
+ Self::BitXor => (8, 9),
+ Self::BitOr => (6, 7),
+ Self::And => (4, 5),
+ Self::Or => (2, 3),
+ Self::ErrorNoOperator => (0, 1),
+ }
+ }
+}
+
+impl UnaryOperatorKind {
+ pub fn binding_power(&self) -> ((), u8) {
+ match self {
+ Self::Minus => ((), 20),
+ Self::Not => ((), 20),
+ Self::BitNot => ((), 20),
+ }
+ }
+}
crates/jrsonnet-rowan-parser/src/unary.rsdiffbeforeafterboth--- a/crates/jrsonnet-rowan-parser/src/unary.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
-pub enum UnaryOperator {
- Minus,
- Not,
- BitNegate,
-}
-impl UnaryOperator {
- pub fn binding_power(&self) -> ((), u8) {
- match self {
- UnaryOperator::Minus => ((), 20),
- UnaryOperator::Not => ((), 20),
- UnaryOperator::BitNegate => ((), 20),
- }
- }
-}
xtask/src/sourcegen/mod.rsdiffbeforeafterboth--- a/xtask/src/sourcegen/mod.rs
+++ b/xtask/src/sourcegen/mod.rs
@@ -353,22 +353,30 @@
let ast_node = quote! {
impl AstToken for #name {
fn can_cast(kind: SyntaxKind) -> bool {
+ #kind_name::can_cast(kind)
+ }
+ fn cast(syntax: SyntaxToken) -> Option<Self> {
+ let kind = #kind_name::cast(syntax.kind())?;
+ Some(#name { syntax, kind })
+ }
+ fn syntax(&self) -> &SyntaxToken {
+ &self.syntax
+ }
+ }
+
+ impl #kind_name {
+ fn can_cast(kind: SyntaxKind) -> bool {
match kind {
#(#kinds)|* => true,
_ => false,
}
}
- fn cast(syntax: SyntaxToken) -> Option<Self> {
- let res = match syntax.kind() {
- #(
- #kinds => #name { syntax, kind: #kind_name::#variants },
- )*
+ pub fn cast(kind: SyntaxKind) -> Option<Self> {
+ let res = match kind {
+ #(#kinds => Self::#variants,)*
_ => return None,
};
Some(res)
- }
- fn syntax(&self) -> &SyntaxToken {
- &self.syntax
}
}
};