git.delta.rocks / jrsonnet / refs/commits / b1b8b4cf86ba

difftreelog

refactor deduplicate operator definitions

Yaroslav Bolyukin2023-09-04parent: #5ad3c06.patch.diff
in: master

9 files changed

modifiedcrates/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 =
deletedcrates/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),
-		}
-	}
-}
modifiedcrates/jrsonnet-rowan-parser/src/generated/nodes.rsdiffbeforeafterboth
1005 Mul,1005 Mul,
1006 Div,1006 Div,
1007 Modulo,1007 Modulo,
1008 MetaObjectApply,
1008 ErrorNoOperator,1009 ErrorNoOperator,
1009}1010}
10101011
2506 }2507 }
2507 }2508 }
2508}2509}
2509impl AstToken for BinaryOperator {2510impl AstToken for BinaryOperator {
2511 fn can_cast(kind: SyntaxKind) -> bool {
2512 BinaryOperatorKind::can_cast(kind)
2513 }
2514 fn cast(syntax: SyntaxToken) -> Option<Self> {
2515 let kind = BinaryOperatorKind::cast(syntax.kind())?;
2516 Some(BinaryOperator { syntax, kind })
2517 }
2518 fn syntax(&self) -> &SyntaxToken {
2519 &self.syntax
2520 }
2521}
2522impl BinaryOperatorKind {
2510 fn can_cast(kind: SyntaxKind) -> bool {2523 fn can_cast(kind: SyntaxKind) -> bool {
2511 match kind {2524 match kind {
2512 OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | IN_KW | LHS2525 OR | AND | BIT_OR | BIT_XOR | BIT_AND | EQ | NE | LT | GT | LE | GE | IN_KW | LHS
2513 | RHS | PLUS | MINUS | MUL | DIV | MODULO | ERROR_NO_OPERATOR => true,2526 | RHS | PLUS | MINUS | MUL | DIV | MODULO | META_OBJECT_APPLY | ERROR_NO_OPERATOR => true,
2514 _ => false,2527 _ => false,
2515 }2528 }
2516 }2529 }
2517 fn cast(syntax: SyntaxToken) -> Option<Self> {2530 pub fn cast(kind: SyntaxKind) -> Option<Self> {
2518 let res = match syntax.kind() {2531 let res = match kind {
2519 OR => BinaryOperator {2532 OR => Self::Or,
2520 syntax,
2521 kind: BinaryOperatorKind::Or,
2522 },
2523 AND => BinaryOperator {2533 AND => Self::And,
2524 syntax,
2525 kind: BinaryOperatorKind::And,
2526 },
2527 BIT_OR => BinaryOperator {2534 BIT_OR => Self::BitOr,
2528 syntax,
2529 kind: BinaryOperatorKind::BitOr,
2530 },
2531 BIT_XOR => BinaryOperator {2535 BIT_XOR => Self::BitXor,
2532 syntax,
2533 kind: BinaryOperatorKind::BitXor,
2534 },
2535 BIT_AND => BinaryOperator {2536 BIT_AND => Self::BitAnd,
2536 syntax,
2537 kind: BinaryOperatorKind::BitAnd,
2538 },
2539 EQ => BinaryOperator {2537 EQ => Self::Eq,
2540 syntax,
2541 kind: BinaryOperatorKind::Eq,
2542 },
2543 NE => BinaryOperator {2538 NE => Self::Ne,
2544 syntax,
2545 kind: BinaryOperatorKind::Ne,
2546 },
2547 LT => BinaryOperator {2539 LT => Self::Lt,
2548 syntax,
2549 kind: BinaryOperatorKind::Lt,
2550 },
2551 GT => BinaryOperator {2540 GT => Self::Gt,
2552 syntax,
2553 kind: BinaryOperatorKind::Gt,
2554 },
2555 LE => BinaryOperator {2541 LE => Self::Le,
2556 syntax,
2557 kind: BinaryOperatorKind::Le,
2558 },
2559 GE => BinaryOperator {2542 GE => Self::Ge,
2560 syntax,
2561 kind: BinaryOperatorKind::Ge,
2562 },
2563 IN_KW => BinaryOperator {2543 IN_KW => Self::InKw,
2564 syntax,
2565 kind: BinaryOperatorKind::InKw,
2566 },
2567 LHS => BinaryOperator {2544 LHS => Self::Lhs,
2568 syntax,
2569 kind: BinaryOperatorKind::Lhs,
2570 },
2571 RHS => BinaryOperator {2545 RHS => Self::Rhs,
2572 syntax,
2573 kind: BinaryOperatorKind::Rhs,
2574 },
2575 PLUS => BinaryOperator {2546 PLUS => Self::Plus,
2576 syntax,
2577 kind: BinaryOperatorKind::Plus,
2578 },
2579 MINUS => BinaryOperator {2547 MINUS => Self::Minus,
2580 syntax,
2581 kind: BinaryOperatorKind::Minus,
2582 },
2583 MUL => BinaryOperator {2548 MUL => Self::Mul,
2584 syntax,
2585 kind: BinaryOperatorKind::Mul,
2586 },
2587 DIV => BinaryOperator {2549 DIV => Self::Div,
2588 syntax,
2589 kind: BinaryOperatorKind::Div,
2590 },
2591 MODULO => BinaryOperator {2550 MODULO => Self::Modulo,
2592 syntax,2551 META_OBJECT_APPLY => Self::MetaObjectApply,
2593 kind: BinaryOperatorKind::Modulo,
2594 },
2595 ERROR_NO_OPERATOR => BinaryOperator {2552 ERROR_NO_OPERATOR => Self::ErrorNoOperator,
2596 syntax,
2597 kind: BinaryOperatorKind::ErrorNoOperator,
2598 },
2599 _ => return None,2553 _ => return None,
2600 };2554 };
2601 Some(res)2555 Some(res)
2602 }2556 }
2603 fn syntax(&self) -> &SyntaxToken {
2604 &self.syntax
2605 }
2606}2557}
2607impl BinaryOperator {2558impl BinaryOperator {
2608 pub fn kind(&self) -> BinaryOperatorKind {2559 pub fn kind(&self) -> BinaryOperatorKind {
2614 std::fmt::Display::fmt(self.syntax(), f)2565 std::fmt::Display::fmt(self.syntax(), f)
2615 }2566 }
2616}2567}
2617impl AstToken for UnaryOperator {2568impl AstToken for UnaryOperator {
2569 fn can_cast(kind: SyntaxKind) -> bool {
2570 UnaryOperatorKind::can_cast(kind)
2571 }
2572 fn cast(syntax: SyntaxToken) -> Option<Self> {
2573 let kind = UnaryOperatorKind::cast(syntax.kind())?;
2574 Some(UnaryOperator { syntax, kind })
2575 }
2576 fn syntax(&self) -> &SyntaxToken {
2577 &self.syntax
2578 }
2579}
2580impl UnaryOperatorKind {
2618 fn can_cast(kind: SyntaxKind) -> bool {2581 fn can_cast(kind: SyntaxKind) -> bool {
2619 match kind {2582 match kind {
2620 MINUS | NOT | BIT_NOT => true,2583 MINUS | NOT | BIT_NOT => true,
2621 _ => false,2584 _ => false,
2622 }2585 }
2623 }2586 }
2624 fn cast(syntax: SyntaxToken) -> Option<Self> {2587 pub fn cast(kind: SyntaxKind) -> Option<Self> {
2625 let res = match syntax.kind() {2588 let res = match kind {
2626 MINUS => UnaryOperator {2589 MINUS => Self::Minus,
2627 syntax,
2628 kind: UnaryOperatorKind::Minus,
2629 },
2630 NOT => UnaryOperator {2590 NOT => Self::Not,
2631 syntax,
2632 kind: UnaryOperatorKind::Not,
2633 },
2634 BIT_NOT => UnaryOperator {2591 BIT_NOT => Self::BitNot,
2635 syntax,
2636 kind: UnaryOperatorKind::BitNot,
2637 },
2638 _ => return None,2592 _ => return None,
2639 };2593 };
2640 Some(res)2594 Some(res)
2641 }2595 }
2642 fn syntax(&self) -> &SyntaxToken {
2643 &self.syntax
2644 }
2645}2596}
2646impl UnaryOperator {2597impl UnaryOperator {
2647 pub fn kind(&self) -> UnaryOperatorKind {2598 pub fn kind(&self) -> UnaryOperatorKind {
2653 std::fmt::Display::fmt(self.syntax(), f)2604 std::fmt::Display::fmt(self.syntax(), f)
2654 }2605 }
2655}2606}
2656impl AstToken for Literal {2607impl AstToken for Literal {
2608 fn can_cast(kind: SyntaxKind) -> bool {
2609 LiteralKind::can_cast(kind)
2610 }
2611 fn cast(syntax: SyntaxToken) -> Option<Self> {
2612 let kind = LiteralKind::cast(syntax.kind())?;
2613 Some(Literal { syntax, kind })
2614 }
2615 fn syntax(&self) -> &SyntaxToken {
2616 &self.syntax
2617 }
2618}
2619impl LiteralKind {
2657 fn can_cast(kind: SyntaxKind) -> bool {2620 fn can_cast(kind: SyntaxKind) -> bool {
2658 match kind {2621 match kind {
2659 NULL_KW | TRUE_KW | FALSE_KW | SELF_KW | DOLLAR | SUPER_KW => true,2622 NULL_KW | TRUE_KW | FALSE_KW | SELF_KW | DOLLAR | SUPER_KW => true,
2660 _ => false,2623 _ => false,
2661 }2624 }
2662 }2625 }
2663 fn cast(syntax: SyntaxToken) -> Option<Self> {2626 pub fn cast(kind: SyntaxKind) -> Option<Self> {
2664 let res = match syntax.kind() {2627 let res = match kind {
2665 NULL_KW => Literal {2628 NULL_KW => Self::NullKw,
2666 syntax,
2667 kind: LiteralKind::NullKw,
2668 },
2669 TRUE_KW => Literal {2629 TRUE_KW => Self::TrueKw,
2670 syntax,
2671 kind: LiteralKind::TrueKw,
2672 },
2673 FALSE_KW => Literal {2630 FALSE_KW => Self::FalseKw,
2674 syntax,
2675 kind: LiteralKind::FalseKw,
2676 },
2677 SELF_KW => Literal {2631 SELF_KW => Self::SelfKw,
2678 syntax,
2679 kind: LiteralKind::SelfKw,
2680 },
2681 DOLLAR => Literal {2632 DOLLAR => Self::Dollar,
2682 syntax,
2683 kind: LiteralKind::Dollar,
2684 },
2685 SUPER_KW => Literal {2633 SUPER_KW => Self::SuperKw,
2686 syntax,
2687 kind: LiteralKind::SuperKw,
2688 },
2689 _ => return None,2634 _ => return None,
2690 };2635 };
2691 Some(res)2636 Some(res)
2692 }2637 }
2693 fn syntax(&self) -> &SyntaxToken {
2694 &self.syntax
2695 }
2696}2638}
2697impl Literal {2639impl Literal {
2698 pub fn kind(&self) -> LiteralKind {2640 pub fn kind(&self) -> LiteralKind {
2704 std::fmt::Display::fmt(self.syntax(), f)2646 std::fmt::Display::fmt(self.syntax(), f)
2705 }2647 }
2706}2648}
2707impl AstToken for Text {2649impl AstToken for Text {
2650 fn can_cast(kind: SyntaxKind) -> bool {
2651 TextKind::can_cast(kind)
2652 }
2653 fn cast(syntax: SyntaxToken) -> Option<Self> {
2654 let kind = TextKind::cast(syntax.kind())?;
2655 Some(Text { syntax, kind })
2656 }
2657 fn syntax(&self) -> &SyntaxToken {
2658 &self.syntax
2659 }
2660}
2661impl TextKind {
2708 fn can_cast(kind: SyntaxKind) -> bool {2662 fn can_cast(kind: SyntaxKind) -> bool {
2709 match kind {2663 match kind {
2710 STRING_DOUBLE2664 STRING_DOUBLE
2724 _ => false,2678 _ => false,
2725 }2679 }
2726 }2680 }
2727 fn cast(syntax: SyntaxToken) -> Option<Self> {2681 pub fn cast(kind: SyntaxKind) -> Option<Self> {
2728 let res = match syntax.kind() {2682 let res = match kind {
2729 STRING_DOUBLE => Text {2683 STRING_DOUBLE => Self::StringDouble,
2730 syntax,
2731 kind: TextKind::StringDouble,
2732 },
2733 ERROR_STRING_DOUBLE_UNTERMINATED => Text {2684 ERROR_STRING_DOUBLE_UNTERMINATED => Self::ErrorStringDoubleUnterminated,
2734 syntax,
2735 kind: TextKind::ErrorStringDoubleUnterminated,
2736 },
2737 STRING_SINGLE => Text {2685 STRING_SINGLE => Self::StringSingle,
2738 syntax,
2739 kind: TextKind::StringSingle,
2740 },
2741 ERROR_STRING_SINGLE_UNTERMINATED => Text {2686 ERROR_STRING_SINGLE_UNTERMINATED => Self::ErrorStringSingleUnterminated,
2742 syntax,
2743 kind: TextKind::ErrorStringSingleUnterminated,
2744 },
2745 STRING_DOUBLE_VERBATIM => Text {2687 STRING_DOUBLE_VERBATIM => Self::StringDoubleVerbatim,
2746 syntax,
2747 kind: TextKind::StringDoubleVerbatim,
2748 },
2749 ERROR_STRING_DOUBLE_VERBATIM_UNTERMINATED => Text {2688 ERROR_STRING_DOUBLE_VERBATIM_UNTERMINATED => {
2750 syntax,
2751 kind: TextKind::ErrorStringDoubleVerbatimUnterminated,2689 Self::ErrorStringDoubleVerbatimUnterminated
2752 },2690 }
2753 STRING_SINGLE_VERBATIM => Text {2691 STRING_SINGLE_VERBATIM => Self::StringSingleVerbatim,
2754 syntax,
2755 kind: TextKind::StringSingleVerbatim,
2756 },
2757 ERROR_STRING_SINGLE_VERBATIM_UNTERMINATED => Text {2692 ERROR_STRING_SINGLE_VERBATIM_UNTERMINATED => {
2758 syntax,
2759 kind: TextKind::ErrorStringSingleVerbatimUnterminated,2693 Self::ErrorStringSingleVerbatimUnterminated
2760 },2694 }
2761 ERROR_STRING_VERBATIM_MISSING_QUOTES => Text {2695 ERROR_STRING_VERBATIM_MISSING_QUOTES => Self::ErrorStringVerbatimMissingQuotes,
2762 syntax,
2763 kind: TextKind::ErrorStringVerbatimMissingQuotes,
2764 },
2765 STRING_BLOCK => Text {2696 STRING_BLOCK => Self::StringBlock,
2766 syntax,
2767 kind: TextKind::StringBlock,
2768 },
2769 ERROR_STRING_BLOCK_UNEXPECTED_END => Text {2697 ERROR_STRING_BLOCK_UNEXPECTED_END => Self::ErrorStringBlockUnexpectedEnd,
2770 syntax,
2771 kind: TextKind::ErrorStringBlockUnexpectedEnd,
2772 },
2773 ERROR_STRING_BLOCK_MISSING_NEW_LINE => Text {2698 ERROR_STRING_BLOCK_MISSING_NEW_LINE => Self::ErrorStringBlockMissingNewLine,
2774 syntax,
2775 kind: TextKind::ErrorStringBlockMissingNewLine,
2776 },
2777 ERROR_STRING_BLOCK_MISSING_TERMINATION => Text {2699 ERROR_STRING_BLOCK_MISSING_TERMINATION => Self::ErrorStringBlockMissingTermination,
2778 syntax,
2779 kind: TextKind::ErrorStringBlockMissingTermination,
2780 },
2781 ERROR_STRING_BLOCK_MISSING_INDENT => Text {2700 ERROR_STRING_BLOCK_MISSING_INDENT => Self::ErrorStringBlockMissingIndent,
2782 syntax,
2783 kind: TextKind::ErrorStringBlockMissingIndent,
2784 },
2785 _ => return None,2701 _ => return None,
2786 };2702 };
2787 Some(res)2703 Some(res)
2788 }2704 }
2789 fn syntax(&self) -> &SyntaxToken {
2790 &self.syntax
2791 }
2792}2705}
2793impl Text {2706impl Text {
2794 pub fn kind(&self) -> TextKind {2707 pub fn kind(&self) -> TextKind {
2800 std::fmt::Display::fmt(self.syntax(), f)2713 std::fmt::Display::fmt(self.syntax(), f)
2801 }2714 }
2802}2715}
2803impl AstToken for Number {2716impl AstToken for Number {
2717 fn can_cast(kind: SyntaxKind) -> bool {
2718 NumberKind::can_cast(kind)
2719 }
2720 fn cast(syntax: SyntaxToken) -> Option<Self> {
2721 let kind = NumberKind::cast(syntax.kind())?;
2722 Some(Number { syntax, kind })
2723 }
2724 fn syntax(&self) -> &SyntaxToken {
2725 &self.syntax
2726 }
2727}
2728impl NumberKind {
2804 fn can_cast(kind: SyntaxKind) -> bool {2729 fn can_cast(kind: SyntaxKind) -> bool {
2805 match kind {2730 match kind {
2806 FLOAT2731 FLOAT
2810 _ => false,2735 _ => false,
2811 }2736 }
2812 }2737 }
2813 fn cast(syntax: SyntaxToken) -> Option<Self> {2738 pub fn cast(kind: SyntaxKind) -> Option<Self> {
2814 let res = match syntax.kind() {2739 let res = match kind {
2815 FLOAT => Number {2740 FLOAT => Self::Float,
2816 syntax,
2817 kind: NumberKind::Float,
2818 },
2819 ERROR_FLOAT_JUNK_AFTER_POINT => Number {2741 ERROR_FLOAT_JUNK_AFTER_POINT => Self::ErrorFloatJunkAfterPoint,
2820 syntax,
2821 kind: NumberKind::ErrorFloatJunkAfterPoint,
2822 },
2823 ERROR_FLOAT_JUNK_AFTER_EXPONENT => Number {2742 ERROR_FLOAT_JUNK_AFTER_EXPONENT => Self::ErrorFloatJunkAfterExponent,
2824 syntax,
2825 kind: NumberKind::ErrorFloatJunkAfterExponent,
2826 },
2827 ERROR_FLOAT_JUNK_AFTER_EXPONENT_SIGN => Number {2743 ERROR_FLOAT_JUNK_AFTER_EXPONENT_SIGN => Self::ErrorFloatJunkAfterExponentSign,
2828 syntax,
2829 kind: NumberKind::ErrorFloatJunkAfterExponentSign,
2830 },
2831 _ => return None,2744 _ => return None,
2832 };2745 };
2833 Some(res)2746 Some(res)
2834 }2747 }
2835 fn syntax(&self) -> &SyntaxToken {
2836 &self.syntax
2837 }
2838}2748}
2839impl Number {2749impl Number {
2840 pub fn kind(&self) -> NumberKind {2750 pub fn kind(&self) -> NumberKind {
2846 std::fmt::Display::fmt(self.syntax(), f)2756 std::fmt::Display::fmt(self.syntax(), f)
2847 }2757 }
2848}2758}
2849impl AstToken for ImportKind {2759impl AstToken for ImportKind {
2760 fn can_cast(kind: SyntaxKind) -> bool {
2761 ImportKindKind::can_cast(kind)
2762 }
2763 fn cast(syntax: SyntaxToken) -> Option<Self> {
2764 let kind = ImportKindKind::cast(syntax.kind())?;
2765 Some(ImportKind { syntax, kind })
2766 }
2767 fn syntax(&self) -> &SyntaxToken {
2768 &self.syntax
2769 }
2770}
2771impl ImportKindKind {
2850 fn can_cast(kind: SyntaxKind) -> bool {2772 fn can_cast(kind: SyntaxKind) -> bool {
2851 match kind {2773 match kind {
2852 IMPORTSTR_KW | IMPORTBIN_KW | IMPORT_KW => true,2774 IMPORTSTR_KW | IMPORTBIN_KW | IMPORT_KW => true,
2853 _ => false,2775 _ => false,
2854 }2776 }
2855 }2777 }
2856 fn cast(syntax: SyntaxToken) -> Option<Self> {2778 pub fn cast(kind: SyntaxKind) -> Option<Self> {
2857 let res = match syntax.kind() {2779 let res = match kind {
2858 IMPORTSTR_KW => ImportKind {2780 IMPORTSTR_KW => Self::ImportstrKw,
2859 syntax,
2860 kind: ImportKindKind::ImportstrKw,
2861 },
2862 IMPORTBIN_KW => ImportKind {2781 IMPORTBIN_KW => Self::ImportbinKw,
2863 syntax,
2864 kind: ImportKindKind::ImportbinKw,
2865 },
2866 IMPORT_KW => ImportKind {2782 IMPORT_KW => Self::ImportKw,
2867 syntax,
2868 kind: ImportKindKind::ImportKw,
2869 },
2870 _ => return None,2783 _ => return None,
2871 };2784 };
2872 Some(res)2785 Some(res)
2873 }2786 }
2874 fn syntax(&self) -> &SyntaxToken {
2875 &self.syntax
2876 }
2877}2787}
2878impl ImportKind {2788impl ImportKind {
2879 pub fn kind(&self) -> ImportKindKind {2789 pub fn kind(&self) -> ImportKindKind {
2885 std::fmt::Display::fmt(self.syntax(), f)2795 std::fmt::Display::fmt(self.syntax(), f)
2886 }2796 }
2887}2797}
2888impl AstToken for Visibility {2798impl AstToken for Visibility {
2799 fn can_cast(kind: SyntaxKind) -> bool {
2800 VisibilityKind::can_cast(kind)
2801 }
2802 fn cast(syntax: SyntaxToken) -> Option<Self> {
2803 let kind = VisibilityKind::cast(syntax.kind())?;
2804 Some(Visibility { syntax, kind })
2805 }
2806 fn syntax(&self) -> &SyntaxToken {
2807 &self.syntax
2808 }
2809}
2810impl VisibilityKind {
2889 fn can_cast(kind: SyntaxKind) -> bool {2811 fn can_cast(kind: SyntaxKind) -> bool {
2890 match kind {2812 match kind {
2891 COLONCOLONCOLON | COLONCOLON | COLON => true,2813 COLONCOLONCOLON | COLONCOLON | COLON => true,
2892 _ => false,2814 _ => false,
2893 }2815 }
2894 }2816 }
2895 fn cast(syntax: SyntaxToken) -> Option<Self> {2817 pub fn cast(kind: SyntaxKind) -> Option<Self> {
2896 let res = match syntax.kind() {2818 let res = match kind {
2897 COLONCOLONCOLON => Visibility {2819 COLONCOLONCOLON => Self::Coloncoloncolon,
2898 syntax,
2899 kind: VisibilityKind::Coloncoloncolon,
2900 },
2901 COLONCOLON => Visibility {2820 COLONCOLON => Self::Coloncolon,
2902 syntax,
2903 kind: VisibilityKind::Coloncolon,
2904 },
2905 COLON => Visibility {2821 COLON => Self::Colon,
2906 syntax,
2907 kind: VisibilityKind::Colon,
2908 },
2909 _ => return None,2822 _ => return None,
2910 };2823 };
2911 Some(res)2824 Some(res)
2912 }2825 }
2913 fn syntax(&self) -> &SyntaxToken {
2914 &self.syntax
2915 }
2916}2826}
2917impl Visibility {2827impl Visibility {
2918 pub fn kind(&self) -> VisibilityKind {2828 pub fn kind(&self) -> VisibilityKind {
2924 std::fmt::Display::fmt(self.syntax(), f)2834 std::fmt::Display::fmt(self.syntax(), f)
2925 }2835 }
2926}2836}
2927impl AstToken for Trivia {2837impl AstToken for Trivia {
2838 fn can_cast(kind: SyntaxKind) -> bool {
2839 TriviaKind::can_cast(kind)
2840 }
2841 fn cast(syntax: SyntaxToken) -> Option<Self> {
2842 let kind = TriviaKind::cast(syntax.kind())?;
2843 Some(Trivia { syntax, kind })
2844 }
2845 fn syntax(&self) -> &SyntaxToken {
2846 &self.syntax
2847 }
2848}
2849impl TriviaKind {
2928 fn can_cast(kind: SyntaxKind) -> bool {2850 fn can_cast(kind: SyntaxKind) -> bool {
2929 match kind {2851 match kind {
2930 WHITESPACE2852 WHITESPACE
2936 _ => false,2858 _ => false,
2937 }2859 }
2938 }2860 }
2939 fn cast(syntax: SyntaxToken) -> Option<Self> {2861 pub fn cast(kind: SyntaxKind) -> Option<Self> {
2940 let res = match syntax.kind() {2862 let res = match kind {
2941 WHITESPACE => Trivia {2863 WHITESPACE => Self::Whitespace,
2942 syntax,
2943 kind: TriviaKind::Whitespace,
2944 },
2945 MULTI_LINE_COMMENT => Trivia {2864 MULTI_LINE_COMMENT => Self::MultiLineComment,
2946 syntax,
2947 kind: TriviaKind::MultiLineComment,
2948 },
2949 ERROR_COMMENT_TOO_SHORT => Trivia {2865 ERROR_COMMENT_TOO_SHORT => Self::ErrorCommentTooShort,
2950 syntax,
2951 kind: TriviaKind::ErrorCommentTooShort,
2952 },
2953 ERROR_COMMENT_UNTERMINATED => Trivia {2866 ERROR_COMMENT_UNTERMINATED => Self::ErrorCommentUnterminated,
2954 syntax,
2955 kind: TriviaKind::ErrorCommentUnterminated,
2956 },
2957 SINGLE_LINE_HASH_COMMENT => Trivia {2867 SINGLE_LINE_HASH_COMMENT => Self::SingleLineHashComment,
2958 syntax,
2959 kind: TriviaKind::SingleLineHashComment,
2960 },
2961 SINGLE_LINE_SLASH_COMMENT => Trivia {2868 SINGLE_LINE_SLASH_COMMENT => Self::SingleLineSlashComment,
2962 syntax,
2963 kind: TriviaKind::SingleLineSlashComment,
2964 },
2965 _ => return None,2869 _ => return None,
2966 };2870 };
2967 Some(res)2871 Some(res)
2968 }2872 }
2969 fn syntax(&self) -> &SyntaxToken {
2970 &self.syntax
2971 }
2972}2873}
2973impl Trivia {2874impl Trivia {
2974 pub fn kind(&self) -> TriviaKind {2875 pub fn kind(&self) -> TriviaKind {
modifiedcrates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rsdiffbeforeafterboth
--- a/crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs
+++ b/crates/jrsonnet-rowan-parser/src/generated/syntax_kinds.rs
@@ -163,6 +163,7 @@
 	ERROR_KW,
 	#[token("in")]
 	IN_KW,
+	META_OBJECT_APPLY,
 	ERROR_NO_OPERATOR,
 	#[token("null")]
 	NULL_KW,
modifiedcrates/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;
modifiedcrates/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();
addedcrates/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),
+		}
+	}
+}
deletedcrates/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),
-		}
-	}
-}
modifiedxtask/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
 					}
 				}
 			};