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
136| '<<' | '>>'136| '<<' | '>>'
137| '+' | '-'137| '+' | '-'
138| '*' | '/' | '%'138| '*' | '/' | '%'
139| 'META_OBJECT_APPLY!'
139| 'ERROR_NO_OPERATOR!'140| 'ERROR_NO_OPERATOR!'
140141
141UnaryOperator =142UnaryOperator =
deletedcrates/jrsonnet-rowan-parser/src/binary.rsdiffbeforeafterboth

no changes

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
163 ERROR_KW,163 ERROR_KW,
164 #[token("in")]164 #[token("in")]
165 IN_KW,165 IN_KW,
166 META_OBJECT_APPLY,
166 ERROR_NO_OPERATOR,167 ERROR_NO_OPERATOR,
167 #[token("null")]168 #[token("null")]
168 NULL_KW,169 NULL_KW,
modifiedcrates/jrsonnet-rowan-parser/src/lib.rsdiffbeforeafterboth
1#![deny(unused_must_use)]1#![deny(unused_must_use)]
22
3mod ast;3mod ast;
4mod binary;
5mod event;4mod event;
6mod generated;5mod generated;
7mod language;6mod language;
8mod lex;7mod lex;
9mod marker;8mod marker;
10mod parser;9mod parser;
10mod precedence;
11mod string_block;11mod string_block;
12mod tests;12mod tests;
13mod token_set;13mod token_set;
14mod unary;
1514
16pub use ast::{AstChildren, AstNode, AstToken};15pub use ast::{AstChildren, AstNode, AstToken};
17use event::Sink;16use event::Sink;
modifiedcrates/jrsonnet-rowan-parser/src/parser.rsdiffbeforeafterboth
4use rowan::{GreenNode, TextRange, TextSize};4use rowan::{GreenNode, TextRange, TextSize};
55
6use crate::{6use crate::{
7 binary::BinaryOperator,
8 event::Event,7 event::Event,
9 lex::Lexeme,8 lex::Lexeme,
10 marker::{AsRange, CompletedMarker, Marker, Ranger},9 marker::{AsRange, CompletedMarker, Marker, Ranger},
11 nodes::{Literal, Number, Text, Trivia},10 nodes::{BinaryOperatorKind, Literal, Number, Text, Trivia, UnaryOperatorKind},
12 token_set::SyntaxKindSet,11 token_set::SyntaxKindSet,
13 unary::UnaryOperator,
14 AstToken, SyntaxKind,12 AstToken, SyntaxKind,
15 SyntaxKind::*,13 SyntaxKind::*,
16 SyntaxNode, T, TS,14 SyntaxNode, T, TS,
398 Named,396 Named,
399 Unnamed,397 Unnamed,
400}398}
401macro_rules! at_match {
402 ($p:ident {
403 $($r:expr => $e:expr,)*
404 _ => $else:expr $(,)?
405 }) => {{
406 $(
407 if $p.at($r) {$e} else
408 )* {
409 $else
410 }
411 }}
412}
413399
414fn expr(p: &mut Parser) -> Option<CompletedMarker> {400fn expr(p: &mut Parser) -> Option<CompletedMarker> {
415 expr_binding_power(p, 0)401 expr_binding_power(p, 0)
416}402}
417fn expr_binding_power(p: &mut Parser, minimum_binding_power: u8) -> Option<CompletedMarker> {403fn expr_binding_power(p: &mut Parser, minimum_binding_power: u8) -> Option<CompletedMarker> {
418 let mut lhs = lhs(p)?;404 let mut lhs = lhs(p)?;
419405
420 loop {406 while let Some(op) = BinaryOperatorKind::cast(p.current())
421 let op = at_match!(p {
422 T![*] => BinaryOperator::Mul,407 .or_else(|| p.at(T!['{']).then(|| BinaryOperatorKind::MetaObjectApply))
423 T![/] => BinaryOperator::Div,
424 T![%] => BinaryOperator::Mod,
425 T![+] => BinaryOperator::Plus,
426 T![-] => BinaryOperator::Minus,
427 T![<<] => BinaryOperator::ShiftLeft,
428 T![>>] => BinaryOperator::ShiftRight,
429 T![<] => BinaryOperator::LessThan,
430 T![>] => BinaryOperator::GreaterThan,
431 T![<=] => BinaryOperator::LessThanOrEqual,
432 T![>=] => BinaryOperator::GreaterThanOrEqual,
433 T![==] => BinaryOperator::Equal,
434 T![!=] => BinaryOperator::NotEqual,
435 T![&] => BinaryOperator::BitAnd,
436 T![^] => BinaryOperator::BitXor,
437 T![|] => BinaryOperator::BitOr,
438 T![&&] => BinaryOperator::And,
439 T![||] => BinaryOperator::Or,
440 T![in] => BinaryOperator::In,
441 T!['{'] => BinaryOperator::ObjectApply,
442 _ => break,408 {
443 });
444 let (left_binding_power, right_binding_power) = op.binding_power();409 let (left_binding_power, right_binding_power) = op.binding_power();
445 if left_binding_power < minimum_binding_power {410 if left_binding_power < minimum_binding_power {
446 break;411 break;
447 }412 }
448413
449 // Object apply is not a real operator, we dont have something to bump414 // Object apply is not a real operator, we dont have something to bump
450 if op != BinaryOperator::ObjectApply {415 if op != BinaryOperatorKind::MetaObjectApply {
451 p.bump();416 p.bump();
452 }417 }
453418
454 let m = lhs.wrap(p, LHS_EXPR).precede(p);419 let m = lhs.wrap(p, LHS_EXPR).precede(p);
455 let parsed_rhs = expr_binding_power(p, right_binding_power).is_some();420 let parsed_rhs = expr_binding_power(p, right_binding_power).is_some();
456 lhs = m.complete(421 lhs = m.complete(
457 p,422 p,
458 if op == BinaryOperator::ObjectApply {423 if op == BinaryOperatorKind::MetaObjectApply {
459 EXPR_OBJ_EXTEND424 EXPR_OBJ_EXTEND
460 } else {425 } else {
461 EXPR_BINARY426 EXPR_BINARY
998 p.bump();963 p.bump();
999 text(p);964 text(p);
1000 m.complete(p, EXPR_IMPORT)965 m.complete(p, EXPR_IMPORT)
1001 } else if p.at(T![-]) || p.at(T![!]) || p.at(T![~]) {966 } else if let Some(op) = UnaryOperatorKind::cast(p.current()) {
1002 let op = match p.current() {
1003 T![-] => UnaryOperator::Minus,
1004 T![!] => UnaryOperator::Not,
1005 T![~] => UnaryOperator::BitNegate,
1006 _ => unreachable!(),
1007 };
1008 let ((), right_binding_power) = op.binding_power();967 let ((), right_binding_power) = op.binding_power();
1009968
1010 let m = p.start();969 let m = p.start();
addedcrates/jrsonnet-rowan-parser/src/precedence.rsdiffbeforeafterboth

no changes

deletedcrates/jrsonnet-rowan-parser/src/unary.rsdiffbeforeafterboth

no changes

modifiedxtask/src/sourcegen/mod.rsdiffbeforeafterboth
351 .collect();351 .collect();
352352
353 let ast_node = quote! {353 let ast_node = quote! {
354 impl AstToken for #name {354 impl AstToken for #name {
355 fn can_cast(kind: SyntaxKind) -> bool {
356 #kind_name::can_cast(kind)
357 }
358 fn cast(syntax: SyntaxToken) -> Option<Self> {
359 let kind = #kind_name::cast(syntax.kind())?;
360 Some(#name { syntax, kind })
361 }
362 fn syntax(&self) -> &SyntaxToken {
363 &self.syntax
364 }
365 }
366
367 impl #kind_name {
355 fn can_cast(kind: SyntaxKind) -> bool {368 fn can_cast(kind: SyntaxKind) -> bool {
356 match kind {369 match kind {
357 #(#kinds)|* => true,370 #(#kinds)|* => true,
358 _ => false,371 _ => false,
359 }372 }
360 }373 }
361 fn cast(syntax: SyntaxToken) -> Option<Self> {374 pub fn cast(kind: SyntaxKind) -> Option<Self> {
362 let res = match syntax.kind() {375 let res = match kind {
363 #(376 #(#kinds => Self::#variants,)*
364 #kinds => #name { syntax, kind: #kind_name::#variants },
365 )*
366 _ => return None,377 _ => return None,
367 };378 };
368 Some(res)379 Some(res)
369 }380 }
370 fn syntax(&self) -> &SyntaxToken {
371 &self.syntax
372 }
373 }381 }
374 };382 };
375383