Lines Matching refs:parser

1 /* Bison parser for Rust expressions, for GDB.
19 /* The Bison manual says that %pure-parser is deprecated, but we use
23 %pure-parser
24 %lex-param {struct rust_parser *parser}
25 %parse-param {struct rust_parser *parser}
40 #include "parser-defs.h"
118 static void rustyyerror (rust_parser *parser, const char *msg);
201 /* Return the parser's language. */
207 /* Return the parser's gdbarch. */
305 /* The parser state gdb gave us. */
443 if (parser->rust_ast == NULL)
444 parser->rust_ast = $1;
483 (parser->language (), parser->arch (),
486 $$ = parser->ast_literal (val);
495 { $$ = parser->ast_struct ($1, $3); }
522 sf.init = parser->ast_path ($1, NULL);
530 $$ = parser->new_set_vector ();
534 rust_set_vector *result = parser->new_set_vector ();
552 sf.init = parser->ast_path ($1, NULL);
560 { $$ = parser->ast_call_ish (OP_ARRAY, NULL, $3); }
562 { $$ = parser->ast_call_ish (OP_ARRAY, NULL, $2); }
564 { $$ = parser->ast_operation (OP_RUST_ARRAY, $3, $5); }
566 { $$ = parser->ast_operation (OP_RUST_ARRAY, $2, $4); }
571 { $$ = parser->ast_range ($1, NULL, false); }
573 { $$ = parser->ast_range ($1, $3, false); }
575 { $$ = parser->ast_range ($1, $3, true); }
577 { $$ = parser->ast_range (NULL, $2, false); }
579 { $$ = parser->ast_range (NULL, $2, true); }
581 { $$ = parser->ast_range (NULL, NULL, false); }
586 { $$ = parser->ast_literal ($1); }
588 { $$ = parser->ast_literal ($1); }
590 { $$ = parser->ast_dliteral ($1); }
597 rust_set_vector *fields = parser->new_set_vector ();
602 field.init = parser->ast_unary (UNOP_ADDR,
603 parser->ast_string ($1));
606 val.type = parser->get_type ("usize");
611 field.init = parser->ast_literal (val);
616 $$ = parser->ast_struct (parser->ast_path (token, NULL),
620 { $$ = parser->ast_string ($1); }
625 val.type = language_bool_type (parser->language (),
626 parser->arch ());
628 $$ = parser->ast_literal (val);
634 val.type = language_bool_type (parser->language (),
635 parser->arch ());
637 $$ = parser->ast_literal (val);
643 { $$ = parser->ast_structop ($1, $3.ptr, 0); }
646 $$ = parser->ast_structop ($1, $3.ptr, 1);
647 parser->rust_ast = $$;
650 { $$ = parser->ast_structop_anonymous ($1, $3); }
655 { $$ = parser->ast_operation (BINOP_SUBSCRIPT, $1, $3); }
660 { $$ = parser->ast_unary (UNOP_PLUS, $2); }
663 { $$ = parser->ast_unary (UNOP_NEG, $2); }
671 $$ = parser->ast_unary (UNOP_COMPLEMENT, $2);
675 { $$ = parser->ast_unary (UNOP_IND, $2); }
678 { $$ = parser->ast_unary (UNOP_ADDR, $2); }
681 { $$ = parser->ast_unary (UNOP_ADDR, $3); }
683 { $$ = parser->ast_unary (UNOP_SIZEOF, $3); }
695 { $$ = parser->ast_operation (BINOP_MUL, $1, $3); }
698 { $$ = parser->ast_operation (BINOP_REPEAT, $1, $3); }
701 { $$ = parser->ast_operation (BINOP_DIV, $1, $3); }
704 { $$ = parser->ast_operation (BINOP_REM, $1, $3); }
707 { $$ = parser->ast_operation (BINOP_LESS, $1, $3); }
710 { $$ = parser->ast_operation (BINOP_GTR, $1, $3); }
713 { $$ = parser->ast_operation (BINOP_BITWISE_AND, $1, $3); }
716 { $$ = parser->ast_operation (BINOP_BITWISE_IOR, $1, $3); }
719 { $$ = parser->ast_operation (BINOP_BITWISE_XOR, $1, $3); }
722 { $$ = parser->ast_operation (BINOP_ADD, $1, $3); }
725 { $$ = parser->ast_operation (BINOP_SUB, $1, $3); }
728 { $$ = parser->ast_operation (BINOP_LOGICAL_OR, $1, $3); }
731 { $$ = parser->ast_operation (BINOP_LOGICAL_AND, $1, $3); }
734 { $$ = parser->ast_operation (BINOP_EQUAL, $1, $3); }
737 { $$ = parser->ast_operation (BINOP_NOTEQUAL, $1, $3); }
740 { $$ = parser->ast_operation (BINOP_LEQ, $1, $3); }
743 { $$ = parser->ast_operation (BINOP_GEQ, $1, $3); }
746 { $$ = parser->ast_operation (BINOP_LSH, $1, $3); }
749 { $$ = parser->ast_operation (BINOP_RSH, $1, $3); }
754 { $$ = parser->ast_cast ($1, $3); }
759 { $$ = parser->ast_operation (BINOP_ASSIGN, $1, $3); }
764 { $$ = parser->ast_compound_assignment ($2, $1, $3); }
776 $$ = parser->new_op_vector ();
790 $$ = parser->new_op_vector ();
803 { $$ = parser->ast_call_ish (OP_FUNCALL, $1, $2); }
822 { $$ = parser->ast_path ($1, NULL); }
824 { $$ = parser->ast_path (make_stoken ("self"), NULL); }
830 { $$ = parser->super_name ($3, 0); }
832 { $$ = parser->super_name ($3, $2); }
834 { $$ = parser->crate_name ($2); }
841 $$ = parser->ast_path (parser->concat3 ("::",
850 { $$ = parser->ast_path ($1, NULL); }
853 $$ = parser->ast_path (parser->concat3 ($1->left.sval.ptr,
858 { $$ = parser->ast_path ($1->left.sval, $4); }
861 $$ = parser->ast_path ($1->left.sval, $4);
862 parser->push_back ('>');
869 { $$ = parser->super_name ($3, 0); }
871 { $$ = parser->super_name ($3, $2); }
873 { $$ = parser->crate_name ($2); }
880 $$ = parser->ast_path (parser->concat3 ("::",
889 { $$ = parser->ast_path ($1, NULL); }
892 $$ = parser->ast_path (parser->concat3 ($1->left.sval.ptr,
901 { $$ = parser->ast_path ($1->left.sval, $3); }
904 $$ = parser->ast_path ($1->left.sval, $3);
905 parser->push_back ('>');
912 { $$ = parser->ast_array_type ($2, $4); }
914 { $$ = parser->ast_array_type ($2, $4); }
916 { $$ = parser->ast_slice_type ($3); }
918 { $$ = parser->ast_reference_type ($2); }
920 { $$ = parser->ast_pointer_type ($3, 1); }
922 { $$ = parser->ast_pointer_type ($3, 0); }
924 { $$ = parser->ast_function_type ($6, $3); }
926 { $$ = parser->ast_tuple_type ($2); }
939 rust_op_vector *result = parser->new_op_vector ();
1635 rustyylex (YYSTYPE *lvalp, rust_parser *parser)
1637 struct parser_state *pstate = parser->pstate;
1663 return parser->lex_number (lvalp);
1665 return parser->lex_character (lvalp);
1667 return parser->lex_string (lvalp);
1669 return parser->lex_string (lvalp);
1671 return parser->lex_string (lvalp);
1673 return parser->lex_identifier (lvalp);
1675 return parser->lex_string (lvalp);
1677 return parser->lex_character (lvalp);
1681 --parser->paren_depth;
1686 ++parser->paren_depth;
1689 && parser->paren_depth == 0)
1692 return parser->lex_operator (lvalp);
2195 /* Lower a rust_op to a gdb expression. STATE is the parser state.
2537 /* The parser as exposed to gdb. */
2546 rust_parser parser (state);
2548 result = rustyyparse (&parser);
2550 if (!result || (state->parse_completion && parser.rust_ast != NULL))
2551 parser.convert_ast_to_expression (parser.rust_ast, parser.rust_ast);
2556 /* The parser error handler. */
2559 rustyyerror (rust_parser *parser, const char *msg)
2561 const char *where = (parser->pstate->prev_lexptr
2562 ? parser->pstate->prev_lexptr
2563 : parser->pstate->lexptr);
2575 rust_lex_test_init (rust_parser *parser, const char *input)
2577 parser->pstate->prev_lexptr = NULL;
2578 parser->pstate->lexptr = input;
2579 parser->paren_depth = 0;
2586 rust_lex_test_one (rust_parser *parser, const char *input, int expected)
2591 rust_lex_test_init (parser, input);
2593 token = rustyylex (&result, parser);
2599 token = rustyylex (&ignore, parser);
2609 rust_lex_int_test (rust_parser *parser, const char *input,
2612 RUSTSTYPE result = rust_lex_test_one (parser, input, kind);
2619 rust_lex_exception_test (rust_parser *parser, const char *input,
2625 rust_lex_test_one (parser, input, DECIMAL_INTEGER);
2638 rust_lex_stringish_test (rust_parser *parser, const char *input,
2641 RUSTSTYPE result = rust_lex_test_one (parser, input, kind);
2649 rust_lex_test_sequence (rust_parser *parser, const char *input, int len,
2654 parser->pstate->lexptr = input;
2655 parser->paren_depth = 0;
2660 int token = rustyylex (&ignore, parser);
2669 rust_lex_test_trailing_dot (rust_parser *parser)
2676 rust_lex_test_sequence (parser, "23.g()", ARRAY_SIZE (expected1), expected1);
2677 rust_lex_test_sequence (parser, "23_0.g()", ARRAY_SIZE (expected2),
2679 rust_lex_test_sequence (parser, "23.==()", ARRAY_SIZE (expected3),
2681 rust_lex_test_sequence (parser, "23..25", ARRAY_SIZE (expected4), expected4);
2687 rust_lex_test_completion (rust_parser *parser)
2691 parser->pstate->parse_completion = 1;
2693 rust_lex_test_sequence (parser, "something.wha", ARRAY_SIZE (expected),
2695 rust_lex_test_sequence (parser, "something.", ARRAY_SIZE (expected),
2698 parser->pstate->parse_completion = 0;
2704 rust_lex_test_push_back (rust_parser *parser)
2709 rust_lex_test_init (parser, ">>=");
2711 token = rustyylex (&lval, parser);
2715 parser->push_back ('=');
2717 token = rustyylex (&lval, parser);
2720 token = rustyylex (&lval, parser);
2731 /* Set up dummy "parser", so that rust_type works. */
2734 rust_parser parser (&ps);
2736 rust_lex_test_one (&parser, "", 0);
2737 rust_lex_test_one (&parser, " \t \n \r ", 0);
2738 rust_lex_test_one (&parser, "thread 23", 0);
2739 rust_lex_test_one (&parser, "task 23", 0);
2740 rust_lex_test_one (&parser, "th 104", 0);
2741 rust_lex_test_one (&parser, "ta 97", 0);
2743 rust_lex_int_test (&parser, "'z'", 'z', INTEGER);
2744 rust_lex_int_test (&parser, "'\\xff'", 0xff, INTEGER);
2745 rust_lex_int_test (&parser, "'\\u{1016f}'", 0x1016f, INTEGER);
2746 rust_lex_int_test (&parser, "b'z'", 'z', INTEGER);
2747 rust_lex_int_test (&parser, "b'\\xfe'", 0xfe, INTEGER);
2748 rust_lex_int_test (&parser, "b'\\xFE'", 0xfe, INTEGER);
2749 rust_lex_int_test (&parser, "b'\\xfE'", 0xfe, INTEGER);
2752 rust_lex_int_test (&parser, "'\\n'", '\n', INTEGER);
2753 rust_lex_int_test (&parser, "'\\r'", '\r', INTEGER);
2754 rust_lex_int_test (&parser, "'\\t'", '\t', INTEGER);
2755 rust_lex_int_test (&parser, "'\\\\'", '\\', INTEGER);
2756 rust_lex_int_test (&parser, "'\\0'", '\0', INTEGER);
2757 rust_lex_int_test (&parser, "'\\''", '\'', INTEGER);
2758 rust_lex_int_test (&parser, "'\\\"'", '"', INTEGER);
2760 rust_lex_int_test (&parser, "b'\\n'", '\n', INTEGER);
2761 rust_lex_int_test (&parser, "b'\\r'", '\r', INTEGER);
2762 rust_lex_int_test (&parser, "b'\\t'", '\t', INTEGER);
2763 rust_lex_int_test (&parser, "b'\\\\'", '\\', INTEGER);
2764 rust_lex_int_test (&parser, "b'\\0'", '\0', INTEGER);
2765 rust_lex_int_test (&parser, "b'\\''", '\'', INTEGER);
2766 rust_lex_int_test (&parser, "b'\\\"'", '"', INTEGER);
2768 rust_lex_exception_test (&parser, "'z", "Unterminated character literal");
2769 rust_lex_exception_test (&parser, "b'\\x0'", "Not enough hex digits seen");
2770 rust_lex_exception_test (&parser, "b'\\u{0}'",
2772 rust_lex_exception_test (&parser, "'\\x0'", "Not enough hex digits seen");
2773 rust_lex_exception_test (&parser, "'\\u0'", "Missing '{' in Unicode escape");
2774 rust_lex_exception_test (&parser, "'\\u{0", "Missing '}' in Unicode escape");
2775 rust_lex_exception_test (&parser, "'\\u{0000007}", "Overlong hex escape");
2776 rust_lex_exception_test (&parser, "'\\u{}", "Not enough hex digits seen");
2777 rust_lex_exception_test (&parser, "'\\Q'", "Invalid escape \\Q in literal");
2778 rust_lex_exception_test (&parser, "b'\\Q'", "Invalid escape \\Q in literal");
2780 rust_lex_int_test (&parser, "23", 23, DECIMAL_INTEGER);
2781 rust_lex_int_test (&parser, "2_344__29", 234429, INTEGER);
2782 rust_lex_int_test (&parser, "0x1f", 0x1f, INTEGER);
2783 rust_lex_int_test (&parser, "23usize", 23, INTEGER);
2784 rust_lex_int_test (&parser, "23i32", 23, INTEGER);
2785 rust_lex_int_test (&parser, "0x1_f", 0x1f, INTEGER);
2786 rust_lex_int_test (&parser, "0b1_101011__", 0x6b, INTEGER);
2787 rust_lex_int_test (&parser, "0o001177i64", 639, INTEGER);
2788 rust_lex_int_test (&parser, "0x123456789u64", 0x123456789ull, INTEGER);
2790 rust_lex_test_trailing_dot (&parser);
2792 rust_lex_test_one (&parser, "23.", FLOAT);
2793 rust_lex_test_one (&parser, "23.99f32", FLOAT);
2794 rust_lex_test_one (&parser, "23e7", FLOAT);
2795 rust_lex_test_one (&parser, "23E-7", FLOAT);
2796 rust_lex_test_one (&parser, "23e+7", FLOAT);
2797 rust_lex_test_one (&parser, "23.99e+7f64", FLOAT);
2798 rust_lex_test_one (&parser, "23.82f32", FLOAT);
2800 rust_lex_stringish_test (&parser, "hibob", "hibob", IDENT);
2801 rust_lex_stringish_test (&parser, "hibob__93", "hibob__93", IDENT);
2802 rust_lex_stringish_test (&parser, "thread", "thread", IDENT);
2804 rust_lex_stringish_test (&parser, "\"string\"", "string", STRING);
2805 rust_lex_stringish_test (&parser, "\"str\\ting\"", "str\ting", STRING);
2806 rust_lex_stringish_test (&parser, "\"str\\\"ing\"", "str\"ing", STRING);
2807 rust_lex_stringish_test (&parser, "r\"str\\ing\"", "str\\ing", STRING);
2808 rust_lex_stringish_test (&parser, "r#\"str\\ting\"#", "str\\ting", STRING);
2809 rust_lex_stringish_test (&parser, "r###\"str\\\"ing\"###", "str\\\"ing",
2812 rust_lex_stringish_test (&parser, "b\"string\"", "string", BYTESTRING);
2813 rust_lex_stringish_test (&parser, "b\"\x73tring\"", "string", BYTESTRING);
2814 rust_lex_stringish_test (&parser, "b\"str\\\"ing\"", "str\"ing", BYTESTRING);
2815 rust_lex_stringish_test (&parser, "br####\"\\x73tring\"####", "\\x73tring",
2819 rust_lex_test_one (&parser, identifier_tokens[i].name,
2823 rust_lex_test_one (&parser, operator_tokens[i].name,
2826 rust_lex_test_completion (&parser);
2827 rust_lex_test_push_back (&parser);