From 2264075f8e3ba80c9a9f4944d2958504c5c7de30 Mon Sep 17 00:00:00 2001 From: Elliot Chance Date: Fri, 27 Dec 2024 01:13:54 -0500 Subject: [PATCH] WIP --- scripts/generate_grammar.py | 8 +- vsql/grammar.y | 2164 +------------ vsql/std_10_10_sort_specification_list.y | 22 + vsql/std_10_4_routine_invocation.y | 23 + vsql/std_10_9_aggregate_function.y | 26 + vsql/std_11_1_schema_definition.y | 11 + vsql/std_11_2_drop_schema_statement.y | 12 + vsql/std_11_31_drop_table_statement.y | 6 + vsql/std_11_3_table_definition.y | 24 + vsql/std_11_4_column_definition.y | 20 + vsql/std_11_6_table_constraint_definition.y | 11 + .../std_11_72_sequence_generator_definition.y | 98 + ...11_73_alter_sequence_generator_statement.y | 35 + ..._11_74_drop_sequence_generator_statement.y | 8 + vsql/std_11_7_unique_constraint_definition.y | 14 + vsql/std_13_4_sql_procedure_statement.y | 27 + vsql/std_14_11_insert_statement.y | 27 + vsql/std_14_14_update_statement_searched.y | 13 + vsql/std_14_15_set_clause_list.y | 32 + vsql/std_14_3_cursor_specification.y | 6 + vsql/std_14_8_delete_statement_positioned.y | 6 + vsql/std_14_9_delete_statement_searched.y | 14 + vsql/std_17_1_start_transaction_statement.y | 6 + vsql/std_17_7_commit_statement.y | 7 + vsql/std_17_8_rollback_statement.y | 7 + vsql/std_19_5_set_catalog_statement.y | 11 + vsql/std_19_6_set_schema_statement.y | 11 + vsql/std_20_7_prepare_statement.y | 27 + vsql/std_5_1_sql_terminal_character.y | 27 + vsql/std_5_2_token_and_separator.v | 315 -- vsql/std_5_2_token_and_separator.y | 304 ++ vsql/std_5_3_literal.y | 96 + vsql/std_5_4_names_and_identifiers.y | 71 + vsql/std_6_12_case_expression.y | 25 + vsql/std_6_13_cast_specification.y | 17 + vsql/std_6_14_next_value_expression.y | 10 + vsql/std_6_1_data_type.y | 121 + vsql/std_6_28_value_expression.y | 22 + vsql/std_6_29_numeric_value_expression.y | 37 + vsql/std_6_30_numeric_value_function.y | 160 + vsql/std_6_31_string_value_expression.y | 29 + vsql/std_6_32_string_value_function.y | 87 + vsql/std_6_35_datetime_value_expression.y | 14 + vsql/std_6_36_datetime_value_function.y | 47 + vsql/std_6_39_boolean_value_expression.y | 90 + vsql/std_6_3_value_expression_primary.y | 39 + ...e_specification_and_target_specification.y | 29 + ...5_contextually_typed_value_specification.y | 12 + vsql/std_6_6_identifier_chain.y | 14 + vsql/std_6_7_column_reference.y | 2 +- vsql/std_6_9_set_function_specification.y | 6 + vsql/std_7_10_joined_table.y | 21 + vsql/std_7_12_where_clause.y | 6 + vsql/std_7_13_group_by_clause.y | 21 + vsql/std_7_16_query_specification.y | 50 + vsql/std_7_17_query_expression.y | 89 + vsql/std_7_19_subquery.y | 16 + vsql/std_7_1_row_value_constructor.y | 75 + vsql/std_7_2_row_value_expression.y | 16 + vsql/std_7_3_table_value_constructor.y | 30 + vsql/std_7_4_table_expression.y | 25 + vsql/std_7_5_from_clause.y | 9 + vsql/std_7_6_table_reference.y | 84 + vsql/std_8_1_predicate.y | 10 + vsql/std_8_21_search_condition.y | 6 + vsql/std_8_2_comparison_predicate.y | 29 + vsql/std_8_3_between_predicate.y | 42 + vsql/std_8_5_like_predicate.y | 27 + vsql/std_8_6_similar_predicate.y | 20 + vsql/std_8_8_null_predicate.y | 12 + vsql/y.y | 2719 +++++++++-------- 71 files changed, 3777 insertions(+), 3780 deletions(-) create mode 100644 vsql/std_10_10_sort_specification_list.y create mode 100644 vsql/std_10_4_routine_invocation.y create mode 100644 vsql/std_10_9_aggregate_function.y create mode 100644 vsql/std_11_1_schema_definition.y create mode 100644 vsql/std_11_2_drop_schema_statement.y create mode 100644 vsql/std_11_31_drop_table_statement.y create mode 100644 vsql/std_11_3_table_definition.y create mode 100644 vsql/std_11_4_column_definition.y create mode 100644 vsql/std_11_6_table_constraint_definition.y create mode 100644 vsql/std_11_72_sequence_generator_definition.y create mode 100644 vsql/std_11_73_alter_sequence_generator_statement.y create mode 100644 vsql/std_11_74_drop_sequence_generator_statement.y create mode 100644 vsql/std_11_7_unique_constraint_definition.y create mode 100644 vsql/std_13_4_sql_procedure_statement.y create mode 100644 vsql/std_14_11_insert_statement.y create mode 100644 vsql/std_14_14_update_statement_searched.y create mode 100644 vsql/std_14_15_set_clause_list.y create mode 100644 vsql/std_14_3_cursor_specification.y create mode 100644 vsql/std_14_8_delete_statement_positioned.y create mode 100644 vsql/std_14_9_delete_statement_searched.y create mode 100644 vsql/std_17_1_start_transaction_statement.y create mode 100644 vsql/std_17_7_commit_statement.y create mode 100644 vsql/std_17_8_rollback_statement.y create mode 100644 vsql/std_19_5_set_catalog_statement.y create mode 100644 vsql/std_19_6_set_schema_statement.y create mode 100644 vsql/std_20_7_prepare_statement.y create mode 100644 vsql/std_5_1_sql_terminal_character.y delete mode 100644 vsql/std_5_2_token_and_separator.v create mode 100644 vsql/std_5_2_token_and_separator.y create mode 100644 vsql/std_5_3_literal.y create mode 100644 vsql/std_5_4_names_and_identifiers.y create mode 100644 vsql/std_6_12_case_expression.y create mode 100644 vsql/std_6_13_cast_specification.y create mode 100644 vsql/std_6_14_next_value_expression.y create mode 100644 vsql/std_6_1_data_type.y create mode 100644 vsql/std_6_28_value_expression.y create mode 100644 vsql/std_6_29_numeric_value_expression.y create mode 100644 vsql/std_6_30_numeric_value_function.y create mode 100644 vsql/std_6_31_string_value_expression.y create mode 100644 vsql/std_6_32_string_value_function.y create mode 100644 vsql/std_6_35_datetime_value_expression.y create mode 100644 vsql/std_6_36_datetime_value_function.y create mode 100644 vsql/std_6_39_boolean_value_expression.y create mode 100644 vsql/std_6_3_value_expression_primary.y create mode 100644 vsql/std_6_4_value_specification_and_target_specification.y create mode 100644 vsql/std_6_5_contextually_typed_value_specification.y create mode 100644 vsql/std_6_6_identifier_chain.y create mode 100644 vsql/std_6_9_set_function_specification.y create mode 100644 vsql/std_7_10_joined_table.y create mode 100644 vsql/std_7_12_where_clause.y create mode 100644 vsql/std_7_13_group_by_clause.y create mode 100644 vsql/std_7_16_query_specification.y create mode 100644 vsql/std_7_17_query_expression.y create mode 100644 vsql/std_7_19_subquery.y create mode 100644 vsql/std_7_1_row_value_constructor.y create mode 100644 vsql/std_7_2_row_value_expression.y create mode 100644 vsql/std_7_3_table_value_constructor.y create mode 100644 vsql/std_7_4_table_expression.y create mode 100644 vsql/std_7_5_from_clause.y create mode 100644 vsql/std_7_6_table_reference.y create mode 100644 vsql/std_8_1_predicate.y create mode 100644 vsql/std_8_21_search_condition.y create mode 100644 vsql/std_8_2_comparison_predicate.y create mode 100644 vsql/std_8_3_between_predicate.y create mode 100644 vsql/std_8_5_like_predicate.y create mode 100644 vsql/std_8_6_similar_predicate.y create mode 100644 vsql/std_8_8_null_predicate.y diff --git a/scripts/generate_grammar.py b/scripts/generate_grammar.py index ba2309e..b4a8fab 100644 --- a/scripts/generate_grammar.py +++ b/scripts/generate_grammar.py @@ -9,7 +9,7 @@ middle = "" bottom = "" -for file_path in files: +for file_path in sorted(files): with open(file_path) as f: parts = f.read().split('%%') if len(parts) != 3: @@ -19,8 +19,8 @@ bottom += parts[2] with open(path + '/' + 'y.y', 'w') as f: - f.write(top) + f.write(top.strip()) f.write('\n%%\n') - f.write(middle) + f.write(middle.strip()) f.write('\n%%\n') - f.write(bottom) + f.write(bottom.strip()) diff --git a/vsql/grammar.y b/vsql/grammar.y index 1f65fe4..f6a4ba5 100644 --- a/vsql/grammar.y +++ b/vsql/grammar.y @@ -667,7 +667,7 @@ import math // literals %token LITERAL_IDENTIFIER LITERAL_STRING LITERAL_NUMBER; -%token E +%token E; // pseudo keywords %token IS_TRUE IS_FALSE IS_UNKNOWN IS_NOT_TRUE IS_NOT_FALSE IS_NOT_UNKNOWN; @@ -681,246 +681,9 @@ import math start: preparable_statement { yyrcvr.lval.v = $1.v as Stmt } -// 7.3 - -table_value_constructor: - VALUES row_value_expression_list { - $$.v = SimpleTable($2.v as []RowValueConstructor) - } - -row_value_expression_list: - table_row_value_expression { $$.v = [$1.v as RowValueConstructor] } -| row_value_expression_list comma table_row_value_expression { - $$.v = append_list($1.v as []RowValueConstructor, - $3.v as RowValueConstructor) - } - -contextually_typed_table_value_constructor: - VALUES contextually_typed_row_value_expression_list { - $$.v = $2.v as []ContextuallyTypedRowValueConstructor - } - -contextually_typed_row_value_expression_list: - contextually_typed_row_value_expression { - $$.v = [$1.v as ContextuallyTypedRowValueConstructor] - } -| contextually_typed_row_value_expression_list comma - contextually_typed_row_value_expression { - $$.v = append_list($1.v as []ContextuallyTypedRowValueConstructor, - $3.v as ContextuallyTypedRowValueConstructor) - } - -// 11.74 - -drop_sequence_generator_statement: - DROP SEQUENCE sequence_generator_name { - $$.v = Stmt(DropSequenceGeneratorStatement{$3.v as Identifier}) - } - -// 14.8 - -target_table: - table_name { $$.v = $1.v as Identifier } - -// 20.7 - -preparable_statement: - preparable_sql_data_statement { $$.v = $1.v as Stmt } -| preparable_sql_schema_statement { $$.v = $1.v as Stmt } -| preparable_sql_transaction_statement { $$.v = $1.v as Stmt } -| preparable_sql_session_statement { $$.v = $1.v as Stmt } - -preparable_sql_data_statement: - delete_statement_searched { $$.v = $1.v as Stmt } -| insert_statement { $$.v = $1.v as Stmt } -| dynamic_select_statement { $$.v = $1.v as Stmt } -| update_statement_searched { $$.v = $1.v as Stmt } - -preparable_sql_schema_statement: - sql_schema_statement { $$.v = $1.v as Stmt } - -preparable_sql_transaction_statement: - sql_transaction_statement { $$.v = $1.v as Stmt } - -preparable_sql_session_statement: - sql_session_statement { $$.v = $1.v as Stmt } - -// 6.12 - -case_expression: - case_abbreviation { $$.v = $1.v as CaseExpression } - -case_abbreviation: - NULLIF left_paren value_expression comma value_expression right_paren { - $$.v = CaseExpression(CaseExpressionNullIf{ - $3.v as ValueExpression - $5.v as ValueExpression - }) - } -| COALESCE left_paren value_expression_list right_paren { - $$.v = CaseExpression(CaseExpressionCoalesce{$3.v as []ValueExpression}) - } - -value_expression_list: - value_expression { $$.v = [$1.v as ValueExpression] } -| value_expression_list comma value_expression { - $$.v = append_list($1.v as []ValueExpression, $3.v as ValueExpression) - } - -// 11.73 - -alter_sequence_generator_statement: - ALTER SEQUENCE sequence_generator_name alter_sequence_generator_options { - $$.v = AlterSequenceGeneratorStatement{ - name: $3.v as Identifier - options: $4.v as []SequenceGeneratorOption - } - } - -alter_sequence_generator_options: - alter_sequence_generator_option { $$.v = [$1.v as SequenceGeneratorOption] } -| alter_sequence_generator_options alter_sequence_generator_option { - $$.v = append_list($1.v as []SequenceGeneratorOption, - $2.v as SequenceGeneratorOption) - } - -alter_sequence_generator_option: - alter_sequence_generator_restart_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorRestartOption) - } -| basic_sequence_generator_option { $$.v = $1.v as SequenceGeneratorOption } - -alter_sequence_generator_restart_option: - RESTART { $$.v = SequenceGeneratorRestartOption{} } -| RESTART WITH sequence_generator_restart_value { - $$.v = SequenceGeneratorRestartOption{ - restart_value: $3.v as Value - } - } - -sequence_generator_restart_value: - signed_numeric_literal { $$.v = $1.v as Value } - -commit_statement: - COMMIT { $$.v = Stmt(CommitStatement{}) } -| COMMIT WORK { $$.v = Stmt(CommitStatement{}) } - -sort_specification_list: - sort_specification { $$.v = [$1.v as SortSpecification] } -| sort_specification_list comma sort_specification { - $$.v = append_list($1.v as []SortSpecification, $3.v as SortSpecification) - } - -sort_specification: - sort_key { $$.v = SortSpecification{$1.v as ValueExpression, true} } -| sort_key ordering_specification { - $$.v = SortSpecification{$1.v as ValueExpression, $2.v as bool} - } - -sort_key: - value_expression { $$.v = $1.v as ValueExpression } - -ordering_specification: - ASC { $$.v = true } -| DESC { $$.v = false } - -row_subquery: - subquery { $$.v = $1.v as QueryExpression } - -table_subquery: - subquery { $$.v = $1.v as TablePrimary } - -subquery: - left_paren query_expression right_paren { - $$.v = TablePrimary{ - body: $2.v as QueryExpression - } - } - -set_clause_list: - set_clause { $$.v = $1.v as map[string]UpdateSource } -| set_clause_list comma set_clause { - $$.v = merge_maps($1.v as map[string]UpdateSource, - $3.v as map[string]UpdateSource) - } - -set_clause: - set_target equals_operator update_source { - $$.v = { - ($1.v as Identifier).str(): $3.v as UpdateSource - } - } - -set_target: - update_target { $$.v = $1.v as Identifier } - -update_target: - object_column { $$.v = $1.v as Identifier } - -update_source: - value_expression { $$.v = UpdateSource($1.v as ValueExpression) } -| contextually_typed_value_specification { - $$.v = UpdateSource($1.v as NullSpecification) - } - -object_column: - column_name { $$.v = $1.v as Identifier } - -delete_statement_searched: - DELETE FROM target_table { - $$.v = Stmt(DeleteStatementSearched{$3.v as Identifier, none}) - } -| DELETE FROM target_table WHERE search_condition { - $$.v = Stmt(DeleteStatementSearched{ - $3.v as Identifier - $5.v as BooleanValueExpression - }) - } - -table_definition: - CREATE TABLE table_name table_contents_source { - $$.v = Stmt(TableDefinition{$3.v as Identifier, $4.v as []TableElement}) - } - -table_contents_source: - table_element_list { $$.v = $1.v as []TableElement } - -table_element_list: - left_paren table_elements right_paren { $$.v = $2.v as []TableElement } - -table_element: - column_definition { $$.v = $1.v as TableElement } -| table_constraint_definition { $$.v = $1.v as TableElement } - -table_elements: - table_element { $$.v = [$1.v as TableElement] } -| table_elements comma table_element { - $$.v = append_list($1.v as []TableElement, $3.v as TableElement) - } - -dynamic_select_statement: - cursor_specification { $$.v = $1.v as Stmt } - -schema_definition: - CREATE SCHEMA schema_name_clause { - $$.v = Stmt(SchemaDefinition{$3.v as Identifier}) - } - -schema_name_clause: - schema_name { $$.v = $1.v as Identifier } - -cursor_specification: - query_expression { $$.v = Stmt($1.v as QueryExpression) } - -datetime_value_expression: - datetime_term { $$.v = $1.v as DatetimePrimary } - -datetime_term: - datetime_factor { $$.v = $1.v as DatetimePrimary } - -datetime_factor: - datetime_primary { $$.v = $1.v as DatetimePrimary } - +// This is from 6.35. I have no idea why this needs to be placed higher than +// other rules, but without doing this it will report that "datetime_primary" +// cannot be reduced. datetime_primary: value_expression_primary { $$.v = DatetimePrimary($1.v as ValueExpressionPrimary) @@ -929,1923 +692,4 @@ datetime_primary: $$.v = DatetimePrimary($1.v as DatetimeValueFunction) } -update_statement_searched: - UPDATE target_table SET set_clause_list { - $$.v = Stmt(UpdateStatementSearched{$2.v as Identifier, - $4.v as map[string]UpdateSource, none}) - } -| UPDATE target_table SET set_clause_list WHERE search_condition { - $$.v = Stmt(UpdateStatementSearched{$2.v as Identifier, - $4.v as map[string]UpdateSource, $6.v as BooleanValueExpression}) - } - -identifier_chain: - identifier { $$.v = $1.v as IdentifierChain } -| identifier period identifier { - $$.v = IdentifierChain{ - ($1.v as IdentifierChain).identifier + '.' + ($3.v as IdentifierChain).identifier - } - } - -basic_identifier_chain: - identifier_chain { $$.v = $1.v as IdentifierChain } - -cast_specification: - CAST left_paren cast_operand AS cast_target right_paren { - $$.v = CastSpecification{$3.v as CastOperand, $5.v as Type} - } - -cast_operand: - value_expression { $$.v = CastOperand($1.v as ValueExpression) } -| implicitly_typed_value_specification { - $$.v = CastOperand($1.v as NullSpecification) - } - -cast_target: - data_type { $$.v = $1.v as Type } - -rollback_statement: - ROLLBACK { $$.v = Stmt(RollbackStatement{}) } -| ROLLBACK WORK { $$.v = Stmt(RollbackStatement{}) } - -next_value_expression: - NEXT VALUE FOR sequence_generator_name { - $$.v = NextValueExpression{ - name: $4.v as Identifier - } - } - -where_clause: - WHERE search_condition { $$.v = $2.v as BooleanValueExpression } - -literal: - signed_numeric_literal { $$.v = $1.v as Value } -| general_literal { $$.v = $1.v as Value } - -unsigned_literal: - unsigned_numeric_literal { $$.v = $1.v as Value } -| general_literal { $$.v = $1.v as Value } - -general_literal: - character_string_literal { $$.v = $1.v as Value } -| datetime_literal { $$.v = $1.v as Value } -| boolean_literal { $$.v = $1.v as Value } - -character_string_literal: - LITERAL_STRING { $$.v = $1.v as Value } - -signed_numeric_literal: - unsigned_numeric_literal { $$.v = $1.v as Value } -| sign unsigned_numeric_literal { - $$.v = numeric_literal($1.v as string + ($2.v as Value).str())! - } - -unsigned_numeric_literal: - exact_numeric_literal { $$.v = $1.v as Value } -| approximate_numeric_literal { $$.v = $1.v as Value } - -exact_numeric_literal: - unsigned_integer { $$.v = numeric_literal($1.v as string)! } -| unsigned_integer period { $$.v = numeric_literal(($1.v as string) + '.')! } -| unsigned_integer period unsigned_integer { - $$.v = numeric_literal(($1.v as string) + '.' + ($3.v as string))! - } -| period unsigned_integer { $$.v = numeric_literal('0.' + ($2.v as string))! } - -sign: - plus_sign { $$.v = $1.v as string } -| minus_sign { $$.v = $1.v as string } - -approximate_numeric_literal: - mantissa E exponent { - $$.v = new_double_precision_value( - ($1.v as Value).as_f64()! * math.pow(10, ($3.v as Value).as_f64()!)) - } - -mantissa: - exact_numeric_literal { $$.v = $1.v as Value } - -exponent: - signed_integer { $$.v = $1.v as Value } - -signed_integer: - unsigned_integer { $$.v = new_numeric_value($1.v as string) } -| sign unsigned_integer { - $$.v = if $1.v as string == '-' { - new_numeric_value('-' + ($2.v as string)) - } else { - new_numeric_value($2.v as string) - } - } - -unsigned_integer: - LITERAL_NUMBER { $$.v = $1.v as string } - -datetime_literal: - date_literal { $$.v = $1.v as Value } -| time_literal { $$.v = $1.v as Value } -| timestamp_literal { $$.v = $1.v as Value } - -date_literal: - DATE date_string { $$.v = new_date_value(($2.v as Value).string_value())! } - -time_literal: - TIME time_string { $$.v = new_time_value(($2.v as Value).string_value())! } - -timestamp_literal: - TIMESTAMP timestamp_string { - $$.v = new_timestamp_value(($2.v as Value).string_value())! - } - -date_string: - LITERAL_STRING { $$.v = $1.v as Value } - -time_string: - LITERAL_STRING { $$.v = $1.v as Value } - -timestamp_string: - LITERAL_STRING { $$.v = $1.v as Value } - -boolean_literal: - TRUE { $$.v = new_boolean_value(true) } -| FALSE { $$.v = new_boolean_value(false) } -| UNKNOWN { $$.v = new_unknown_value() } - -contextually_typed_value_specification: - implicitly_typed_value_specification { $$.v = $1.v as NullSpecification } - -implicitly_typed_value_specification: - null_specification { $$.v = $1.v as NullSpecification } - -null_specification: - NULL { $$.v = NullSpecification{} } - -from_clause: - FROM table_reference_list { $$.v = $2.v as TableReference } - -table_reference_list: - table_reference { $$.v = $1.v as TableReference } - -between_predicate: - row_value_predicand between_predicate_part_2 { - between := $2.v as BetweenPredicate - $$.v = BetweenPredicate{ - not: between.not - symmetric: between.symmetric - expr: $1.v as RowValueConstructorPredicand - left: between.left - right: between.right - } - } - -between_predicate_part_2: - between_predicate_part_1 row_value_predicand AND row_value_predicand { - $$.v = BetweenPredicate{ - not: !($1.v as bool) - symmetric: false - left: $2.v as RowValueConstructorPredicand - right: $4.v as RowValueConstructorPredicand - } - } -| between_predicate_part_1 is_symmetric row_value_predicand AND - row_value_predicand { - $$.v = BetweenPredicate{ - not: !($1.v as bool) - symmetric: $2.v as bool - left: $3.v as RowValueConstructorPredicand - right: $5.v as RowValueConstructorPredicand - } - } - -between_predicate_part_1: - BETWEEN { $$.v = true } -| NOT BETWEEN { $$.v = false } - -is_symmetric: - SYMMETRIC { $$.v = true } -| ASYMMETRIC { $$.v = false } - -identifier: - actual_identifier { $$.v = $1.v as IdentifierChain } - -actual_identifier: - regular_identifier { $$.v = $1.v as IdentifierChain } - -table_name: - local_or_schema_qualified_name { - $$.v = new_table_identifier(($1.v as IdentifierChain).identifier)! - } - -schema_name: - catalog_name period unqualified_schema_name { - $$.v = new_schema_identifier(($1.v as IdentifierChain).str() + '.' + - ($3.v as Identifier).str())! - } -| unqualified_schema_name { $$.v = $1.v as Identifier } - -unqualified_schema_name: - identifier { - $$.v = new_schema_identifier(($1.v as IdentifierChain).identifier)! - } - -catalog_name: - identifier { $$.v = $1.v as IdentifierChain } - -schema_qualified_name: - qualified_identifier { $$.v = $1.v as IdentifierChain } -| schema_name period qualified_identifier { - $$.v = IdentifierChain{($1.v as Identifier).schema_name + '.' + - ($3.v as IdentifierChain).str()} - } - -local_or_schema_qualified_name: - qualified_identifier { $$.v = $1.v as IdentifierChain } -| local_or_schema_qualifier period qualified_identifier { - $$.v = IdentifierChain{($1.v as Identifier).str() + '.' + - ($3.v as IdentifierChain).str()} - } - -local_or_schema_qualifier: - schema_name { $$.v = $1.v as Identifier } - -qualified_identifier: - identifier { $$.v = $1.v as IdentifierChain } - -column_name: - identifier { - $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! - } - -host_parameter_name: - colon identifier { - $$.v = GeneralValueSpecification(HostParameterName{ - ($2.v as IdentifierChain).identifier} - ) - } - -correlation_name: - identifier { - $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! - } - -sequence_generator_name: - schema_qualified_name { - $$.v = new_table_identifier(($1.v as IdentifierChain).identifier)! - } - -drop_schema_statement: - DROP SCHEMA schema_name drop_behavior { - $$.v = Stmt(DropSchemaStatement{$3.v as Identifier, $4.v as string}) - } - -drop_behavior: - CASCADE { $$.v = $1.v as string } -| RESTRICT { $$.v = $1.v as string } - -numeric_value_function: - position_expression { $$.v = $1.v as RoutineInvocation } -| length_expression { $$.v = $1.v as RoutineInvocation } -| absolute_value_expression { $$.v = $1.v as RoutineInvocation } -| modulus_expression { $$.v = $1.v as RoutineInvocation } -| trigonometric_function { $$.v = $1.v as RoutineInvocation } -| common_logarithm { $$.v = $1.v as RoutineInvocation } -| natural_logarithm { $$.v = $1.v as RoutineInvocation } -| exponential_function { $$.v = $1.v as RoutineInvocation } -| power_function { $$.v = $1.v as RoutineInvocation } -| square_root { $$.v = $1.v as RoutineInvocation } -| floor_function { $$.v = $1.v as RoutineInvocation } -| ceiling_function { $$.v = $1.v as RoutineInvocation } - -position_expression: - character_position_expression { $$.v = $1.v as RoutineInvocation } - -character_position_expression: - POSITION left_paren character_value_expression_1 IN - character_value_expression_2 right_paren { - $$.v = RoutineInvocation{'POSITION', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), - ValueExpression(CommonValueExpression($5.v as CharacterValueExpression)), - ]} - } - -character_value_expression_1: - character_value_expression { $$.v = $1.v as CharacterValueExpression } - -character_value_expression_2: - character_value_expression { $$.v = $1.v as CharacterValueExpression } - -length_expression: - char_length_expression { $$.v = $1.v as RoutineInvocation } -| octet_length_expression { $$.v = $1.v as RoutineInvocation } - -char_length_expression: - CHAR_LENGTH left_paren character_value_expression right_paren { - $$.v = RoutineInvocation{'CHAR_LENGTH', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), - ]} - } -| CHARACTER_LENGTH left_paren character_value_expression right_paren { - $$.v = RoutineInvocation{'CHAR_LENGTH', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), - ]} - } - -octet_length_expression: - OCTET_LENGTH left_paren string_value_expression right_paren { - $$.v = RoutineInvocation{'OCTET_LENGTH', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), - ]} - } - -absolute_value_expression: - ABS left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'ABS', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } - -modulus_expression: - MOD left_paren numeric_value_expression_dividend comma - numeric_value_expression_divisor right_paren { - $$.v = RoutineInvocation{'MOD', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ValueExpression(CommonValueExpression($5.v as NumericValueExpression)) - ]} - } - -numeric_value_expression_dividend: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } - -numeric_value_expression_divisor: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } - -trigonometric_function: - trigonometric_function_name left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{$1.v as string, [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)), - ]} - } - -trigonometric_function_name: - SIN { $$.v = $1.v as string } -| COS { $$.v = $1.v as string } -| TAN { $$.v = $1.v as string } -| SINH { $$.v = $1.v as string } -| COSH { $$.v = $1.v as string } -| TANH { $$.v = $1.v as string } -| ASIN { $$.v = $1.v as string } -| ACOS { $$.v = $1.v as string } -| ATAN { $$.v = $1.v as string } - -common_logarithm: - LOG10 left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'LOG10', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } - -natural_logarithm: - LN left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'LN', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } - -exponential_function: - EXP left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'EXP', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } - -power_function: - POWER left_paren numeric_value_expression_base comma - numeric_value_expression_exponent right_paren { - $$.v = RoutineInvocation{'POWER', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)), - ValueExpression(CommonValueExpression($5.v as NumericValueExpression)) - ]} - } - -numeric_value_expression_base: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } - -numeric_value_expression_exponent: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } - -square_root: - SQRT left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'SQRT', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } - -floor_function: - FLOOR left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'FLOOR', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } - -ceiling_function: - CEIL left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'CEILING', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } -| CEILING left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'CEILING', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } - -concatenation_operator: - OPERATOR_DOUBLE_PIPE - -regular_identifier: - identifier_body { $$.v = $1.v as IdentifierChain } -| non_reserved_word { $$.v = IdentifierChain{$1.v as string} } - -identifier_body: - identifier_start { $$.v = $1.v as IdentifierChain } - -identifier_start: - LITERAL_IDENTIFIER { $$.v = $1.v as IdentifierChain } - -not_equals_operator: OPERATOR_NOT_EQUALS - -greater_than_or_equals_operator: OPERATOR_GREATER_EQUALS - -less_than_or_equals_operator: OPERATOR_LESS_EQUALS - -non_reserved_word: - A -| ABSOLUTE -| ACTION -| ADA -| ADD -| ADMIN -| AFTER -| ALWAYS -| ASC -| ASSERTION -| ASSIGNMENT -| ATTRIBUTE -| ATTRIBUTES -| BEFORE -| BERNOULLI -| BREADTH -| C -| CASCADE -| CATALOG -| CATALOG_NAME -| CHAIN -| CHAINING -| CHARACTER_SET_CATALOG -| CHARACTER_SET_NAME -| CHARACTER_SET_SCHEMA -| CHARACTERISTICS -| CHARACTERS -| CLASS_ORIGIN -| COBOL -| COLLATION -| COLLATION_CATALOG -| COLLATION_NAME -| COLLATION_SCHEMA -| COLUMNS -| COLUMN_NAME -| COMMAND_FUNCTION -| COMMAND_FUNCTION_CODE -| COMMITTED -| CONDITIONAL -| CONDITION_NUMBER -| CONNECTION -| CONNECTION_NAME -| CONSTRAINT_CATALOG -| CONSTRAINT_NAME -| CONSTRAINT_SCHEMA -| CONSTRAINTS -| CONSTRUCTOR -| CONTINUE -| CURSOR_NAME -| DATA -| DATETIME_INTERVAL_CODE -| DATETIME_INTERVAL_PRECISION -| DEFAULTS -| DEFERRABLE -| DEFERRED -| DEFINED -| DEFINER -| DEGREE -| DEPTH -| DERIVED -| DESC -| DESCRIBE_CATALOG -| DESCRIBE_NAME -| DESCRIBE_PROCEDURE_SPECIFIC_CATALOG -| DESCRIBE_PROCEDURE_SPECIFIC_NAME -| DESCRIBE_PROCEDURE_SPECIFIC_SCHEMA -| DESCRIBE_SCHEMA -| DESCRIPTOR -| DIAGNOSTICS -| DISPATCH -| DOMAIN -| DYNAMIC_FUNCTION -| DYNAMIC_FUNCTION_CODE -| ENCODING -| ENFORCED -| ERROR -| EXCLUDE -| EXCLUDING -| EXPRESSION -| FINAL -| FINISH -| FINISH_CATALOG -| FINISH_NAME -| FINISH_PROCEDURE_SPECIFIC_CATALOG -| FINISH_PROCEDURE_SPECIFIC_NAME -| FINISH_PROCEDURE_SPECIFIC_SCHEMA -| FINISH_SCHEMA -| FIRST -| FLAG -| FOLLOWING -| FORMAT -| FORTRAN -| FOUND -| FULFILL -| FULFILL_CATALOG -| FULFILL_NAME -| FULFILL_PROCEDURE_SPECIFIC_CATALOG -| FULFILL_PROCEDURE_SPECIFIC_NAME -| FULFILL_PROCEDURE_SPECIFIC_SCHEMA -| FULFILL_SCHEMA -| G -| GENERAL -| GENERATED -| GO -| GOTO -| GRANTED -| HAS_PASS_THROUGH_COLUMNS -| HAS_PASS_THRU_COLS -| HIERARCHY -| IGNORE -| IMMEDIATE -| IMMEDIATELY -| IMPLEMENTATION -| INCLUDING -| INCREMENT -| INITIALLY -| INPUT -| INSTANCE -| INSTANTIABLE -| INSTEAD -| INVOKER -| ISOLATION -| IS_PRUNABLE -| JSON -| K -| KEEP -| KEY -| KEYS -| KEY_MEMBER -| KEY_TYPE -| LAST -| LENGTH -| LEVEL -| LOCATOR -| M -| MAP -| MATCHED -| MAXVALUE -| MESSAGE_LENGTH -| MESSAGE_OCTET_LENGTH -| MESSAGE_TEXT -| MINVALUE -| MORE -| MUMPS -| NAME -| NAMES -| NESTED -| NESTING -| NEXT -| NFC -| NFD -| NFKC -| NFKD -| NORMALIZED -| NULLABLE -| NULLS -| NUMBER -| OBJECT -| OCTETS -| OPTION -| OPTIONS -| ORDERING -| ORDINALITY -| OTHERS -| OUTPUT -| OVERFLOW -| OVERRIDING -| P -| PAD -| PARAMETER_MODE -| PARAMETER_NAME -| PARAMETER_ORDINAL_POSITION -| PARAMETER_SPECIFIC_CATALOG -| PARAMETER_SPECIFIC_NAME -| PARAMETER_SPECIFIC_SCHEMA -| PARTIAL -| PASCAL -| PASS -| PASSING -| PAST -| PATH -| PLACING -| PLAN -| PLI -| PRECEDING -| PRESERVE -| PRIOR -| PRIVATE -| PRIVATE_PARAMETERS -| PRIVATE_PARAMS_S -| PRIVILEGES -| PRUNE -| PUBLIC -| QUOTES -| READ -| RELATIVE -| REPEATABLE -| RESPECT -| RESTART -| RESTRICT -| RETURNED_CARDINALITY -| RETURNED_LENGTH -| RETURNED_OCTET_LENGTH -| RETURNED_SQLSTATE -| RETURNING -| RETURNS_ONLY_PASS_THROUGH -| RET_ONLY_PASS_THRU -| ROLE -| ROUTINE -| ROUTINE_CATALOG -| ROUTINE_NAME -| ROUTINE_SCHEMA -| ROW_COUNT -| SCALAR -| SCALE -| SCHEMA -| SCHEMA_NAME -| SCOPE_CATALOG -| SCOPE_NAME -| SCOPE_SCHEMA -| SECTION -| SECURITY -| SELF -| SEQUENCE -| SERIALIZABLE -| SERVER_NAME -| SESSION -| SETS -| SIMPLE -| SIZE -| SOURCE -| SPACE -| SPECIFIC_NAME -| START_CATALOG -| START_NAME -| START_PROCEDURE_SPECIFIC_CATALOG -| START_PROCEDURE_SPECIFIC_NAME -| START_PROCEDURE_SPECIFIC_SCHEMA -| START_SCHEMA -| STATE -| STATEMENT -| STRING -| STRUCTURE -| STYLE -| SUBCLASS_ORIGIN -| T -| TABLE_NAME -| TABLE_SEMANTICS -| TEMPORARY -| THROUGH -| TIES -| TOP_LEVEL_COUNT -| TRANSACTION -| TRANSACTION_ACTIVE -| TRANSACTIONS_COMMITTED -| TRANSACTIONS_ROLLED_BACK -| TRANSFORM -| TRANSFORMS -| TRIGGER_CATALOG -| TRIGGER_NAME -| TRIGGER_SCHEMA -| TYPE -| UNBOUNDED -| UNCOMMITTED -| UNCONDITIONAL -| UNDER -| UNNAMED -| USAGE -| USER_DEFINED_TYPE_CATALOG -| USER_DEFINED_TYPE_CODE -| USER_DEFINED_TYPE_NAME -| USER_DEFINED_TYPE_SCHEMA -| UTF16 -| UTF32 -| UTF8 -| VIEW -| WORK -| WRAPPER -| WRITE -| ZONE - -data_type: - predefined_type { $$.v = $1.v as Type } - -predefined_type: - character_string_type { $$.v = $1.v as Type } -| numeric_type { $$.v = $1.v as Type } -| boolean_type { $$.v = $1.v as Type } -| datetime_type { $$.v = $1.v as Type } - -character_string_type: - CHARACTER { $$.v = new_type('CHARACTER', 1, 0) } -| CHARACTER left_paren character_length right_paren { - $$.v = new_type('CHARACTER', ($3.v as string).int(), 0) - } -| CHAR { $$.v = new_type('CHARACTER', 1, 0) } -| CHAR left_paren character_length right_paren { - $$.v = new_type('CHARACTER', ($3.v as string).int(), 0) - } -| CHARACTER VARYING left_paren character_length right_paren { - $$.v = new_type('CHARACTER VARYING', ($4.v as string).int(), 0) - } -| CHAR VARYING left_paren character_length right_paren { - $$.v = new_type('CHARACTER VARYING', ($4.v as string).int(), 0) - } -| VARCHAR left_paren character_length right_paren { - $$.v = new_type('CHARACTER VARYING', ($3.v as string).int(), 0) - } - -numeric_type: - exact_numeric_type { $$.v = $1.v as Type } -| approximate_numeric_type { $$.v = $1.v as Type } - -exact_numeric_type: - NUMERIC { $$.v = new_type('NUMERIC', 0, 0) } -| NUMERIC left_paren precision right_paren { - $$.v = new_type('NUMERIC', ($3.v as string).int(), 0) - } -| NUMERIC left_paren precision comma scale right_paren { - $$.v = new_type('NUMERIC', ($3.v as string).int(), ($5.v as string).i16()) - } -| DECIMAL { $$.v = new_type('DECIMAL', 0, 0) } -| DECIMAL left_paren precision right_paren { - $$.v = new_type('DECIMAL', ($3.v as string).int(), 0) - } -| DECIMAL left_paren precision comma scale right_paren { - $$.v = new_type('DECIMAL', ($3.v as string).int(), ($5.v as string).i16()) - } -| SMALLINT { $$.v = new_type('SMALLINT', 0, 0) } -| INTEGER { $$.v = new_type('INTEGER', 0, 0) } -| INT { $$.v = new_type('INTEGER', 0, 0) } -| BIGINT { $$.v = new_type('BIGINT', 0, 0) } - -approximate_numeric_type: - FLOAT { $$.v = new_type('FLOAT', 0, 0) } -| FLOAT left_paren precision right_paren { - $$.v = new_type('FLOAT', ($3.v as string).int(), 0) - } -| REAL { $$.v = new_type('REAL', 0, 0) } -| DOUBLE PRECISION { $$.v = new_type('DOUBLE PRECISION', 0, 0) } - -length: - unsigned_integer { $$.v = $1.v as string } - -character_length: - length { $$.v = $1.v as string } - -char_length_units: - CHARACTERS { $$.v = $1.v as string } -| OCTETS { $$.v = $1.v as string } - -precision: - unsigned_integer { $$.v = $1.v as string } - -scale: - unsigned_integer { $$.v = $1.v as string } - -boolean_type: - BOOLEAN { $$.v = new_type('BOOLEAN', 0, 0) } - -datetime_type: - DATE { $$.v = new_type('DATE', 0, 0) } -| TIME { $$.v = parse_time_prec_tz_type('0', false)! } -| TIME left_paren time_precision right_paren { - $$.v = parse_time_prec_tz_type($3.v as string, false)! - } -| TIME with_or_without_time_zone { - $$.v = parse_time_prec_tz_type('0', $2.v as bool)! - } -| TIME left_paren time_precision right_paren with_or_without_time_zone { - $$.v = parse_time_prec_tz_type($3.v as string, $5.v as bool)! - } -| TIMESTAMP { $$.v = parse_timestamp_prec_tz_type('0', false)! } -| TIMESTAMP left_paren timestamp_precision right_paren { - $$.v = parse_timestamp_prec_tz_type($3.v as string, false)! - } -| TIMESTAMP with_or_without_time_zone { - // ISO/IEC 9075-2:2016(E), 6.1, 36) If is not - // specified, then 6 is implicit. - $$.v = parse_timestamp_prec_tz_type('6', $2.v as bool)! -} -| TIMESTAMP left_paren timestamp_precision right_paren - with_or_without_time_zone { - $$.v = parse_timestamp_prec_tz_type($3.v as string, $5.v as bool)! - } - -with_or_without_time_zone: - WITH TIME ZONE { $$.v = true } -| WITHOUT TIME ZONE { $$.v = false } - -time_precision: - time_fractional_seconds_precision { $$.v = $1.v as string } - -timestamp_precision: - time_fractional_seconds_precision { $$.v = $1.v as string } - -time_fractional_seconds_precision: - unsigned_integer { $$.v = $1.v as string } - -like_predicate: - character_like_predicate { $$.v = $1.v as CharacterLikePredicate } - -character_like_predicate: - row_value_predicand character_like_predicate_part_2 { - like := $2.v as CharacterLikePredicate - $$.v = CharacterLikePredicate{ - $1.v as RowValueConstructorPredicand - like.right - like.not - } - } - -character_like_predicate_part_2: - LIKE character_pattern { - $$.v = CharacterLikePredicate{none, $2.v as CharacterValueExpression, false} - } -| NOT LIKE character_pattern { - $$.v = CharacterLikePredicate{none, $3.v as CharacterValueExpression, true} - } - -character_pattern: - character_value_expression { $$.v = $1.v as CharacterValueExpression } - -comparison_predicate: - row_value_predicand comparison_predicate_part_2 { - comp := $2.v as ComparisonPredicatePart2 - $$.v = ComparisonPredicate{ - $1.v as RowValueConstructorPredicand - comp.op - comp.expr - } - } - -comparison_predicate_part_2: - comp_op row_value_predicand { - $$.v = ComparisonPredicatePart2{ - $1.v as string - $2.v as RowValueConstructorPredicand - } - } - -comp_op: - equals_operator { $$.v = $1.v as string } -| not_equals_operator { $$.v = $1.v as string } -| less_than_operator { $$.v = $1.v as string } -| greater_than_operator { $$.v = $1.v as string } -| less_than_or_equals_operator { $$.v = $1.v as string } -| greater_than_or_equals_operator { $$.v = $1.v as string } - -row_value_constructor: - common_value_expression { - $$.v = RowValueConstructor($1.v as CommonValueExpression) - } -| boolean_value_expression { - $$.v = RowValueConstructor($1.v as BooleanValueExpression) - } -| explicit_row_value_constructor { - $$.v = RowValueConstructor($1.v as ExplicitRowValueConstructor) - } - -explicit_row_value_constructor: - ROW left_paren row_value_constructor_element_list right_paren { - $$.v = ExplicitRowValueConstructor(ExplicitRowValueConstructorRow{$3.v as []ValueExpression}) - } -| row_subquery { $$.v = ExplicitRowValueConstructor($1.v as QueryExpression) } - -row_value_constructor_element_list: - row_value_constructor_element { $$.v = [$1.v as ValueExpression] } -| row_value_constructor_element_list comma row_value_constructor_element { - $$.v = append_list($1.v as []ValueExpression, $3.v as ValueExpression) - } - -row_value_constructor_element: - value_expression { $$.v = $1.v as ValueExpression } - -contextually_typed_row_value_constructor: - common_value_expression { - $$.v = ContextuallyTypedRowValueConstructor($1.v as CommonValueExpression) - } -| boolean_value_expression { - $$.v = ContextuallyTypedRowValueConstructor($1.v as BooleanValueExpression) - } -| contextually_typed_value_specification { - $$.v = ContextuallyTypedRowValueConstructor($1.v as NullSpecification) - } -| left_paren contextually_typed_value_specification right_paren { - $$.v = ContextuallyTypedRowValueConstructor($2.v as NullSpecification) - } -| left_paren contextually_typed_row_value_constructor_element comma - contextually_typed_row_value_constructor_element_list right_paren { - $$.v = ContextuallyTypedRowValueConstructor(push_list( - $2.v as ContextuallyTypedRowValueConstructorElement, - $4.v as []ContextuallyTypedRowValueConstructorElement)) - } - -contextually_typed_row_value_constructor_element_list: - contextually_typed_row_value_constructor_element { - $$.v = [$1.v as ContextuallyTypedRowValueConstructorElement] - } -| contextually_typed_row_value_constructor_element_list comma - contextually_typed_row_value_constructor_element { - $$.v = append_list($1.v as []ContextuallyTypedRowValueConstructorElement, - $3.v as ContextuallyTypedRowValueConstructorElement) - } - -contextually_typed_row_value_constructor_element: - value_expression { - $$.v = ContextuallyTypedRowValueConstructorElement($1.v as ValueExpression) - } -| contextually_typed_value_specification { - $$.v = ContextuallyTypedRowValueConstructorElement($1.v as NullSpecification) - } - -row_value_constructor_predicand: - common_value_expression { - $$.v = RowValueConstructorPredicand($1.v as CommonValueExpression) - } -| boolean_predicand { - $$.v = RowValueConstructorPredicand($1.v as BooleanPredicand) - } - -query_specification: - SELECT select_list table_expression { - $$.v = QuerySpecification{ - exprs: $2.v as SelectList - table_expression: $3.v as TableExpression - } - } - -select_list: - asterisk { $$.v = SelectList(AsteriskExpr(true)) } -| select_sublist { $$.v = $1.v as SelectList } -| select_list comma select_sublist { - mut new_select_list := (($1.v as SelectList) as []DerivedColumn).clone() - new_select_list << (($3.v as SelectList) as []DerivedColumn)[0] - $$.v = SelectList(new_select_list) - } - -select_sublist: - derived_column { $$.v = SelectList([$1.v as DerivedColumn]) } -| qualified_asterisk { $$.v = SelectList($1.v as QualifiedAsteriskExpr) } - -// was: asterisked_identifier_chain period asterisk -qualified_asterisk: - asterisked_identifier_chain OPERATOR_PERIOD_ASTERISK { - $$.v = QualifiedAsteriskExpr{ - new_column_identifier(($1.v as IdentifierChain).identifier)! - } - } - -asterisked_identifier_chain: - asterisked_identifier { $$.v = $1.v as IdentifierChain } - -asterisked_identifier: - identifier { $$.v = $1.v as IdentifierChain } - -derived_column: - value_expression { - $$.v = DerivedColumn{$1.v as ValueExpression, Identifier{}} - } -| value_expression as_clause { - $$.v = DerivedColumn{$1.v as ValueExpression, $2.v as Identifier} - } - -as_clause: - AS column_name { $$.v = $2.v as Identifier } -| column_name { $$.v = $1.v as Identifier } - -string_value_expression: - character_value_expression { $$.v = $1.v as CharacterValueExpression } - -character_value_expression: - concatenation { $$.v = CharacterValueExpression($1.v as Concatenation) } -| character_factor { $$.v = CharacterValueExpression($1.v as CharacterPrimary) } - -concatenation: - character_value_expression concatenation_operator character_factor { - $$.v = Concatenation{ - $1.v as CharacterValueExpression - $3.v as CharacterPrimary - } - } - -character_factor: - character_primary { $$.v = $1.v as CharacterPrimary } - -character_primary: - value_expression_primary { - $$.v = CharacterPrimary($1.v as ValueExpressionPrimary) - } -| string_value_function { - $$.v = CharacterPrimary($1.v as CharacterValueFunction) - } - -set_function_specification: - aggregate_function { $$.v = $1.v as AggregateFunction } - -table_reference: - table_factor { $$.v = TableReference($1.v as TablePrimary) } -| joined_table { $$.v = TableReference($1.v as QualifiedJoin) } - -qualified_join: - table_reference JOIN table_reference join_specification { - $$.v = QualifiedJoin{ - $1.v as TableReference - 'INNER' - $3.v as TableReference - $4.v as BooleanValueExpression - } - } -| table_reference join_type JOIN table_reference join_specification { - $$.v = QualifiedJoin{ - $1.v as TableReference - $2.v as string - $4.v as TableReference - $5.v as BooleanValueExpression - } - } - -table_factor: - table_primary { $$.v = $1.v as TablePrimary } - -table_primary: - table_or_query_name { - $$.v = TablePrimary{ - body: $1.v as Identifier - } - } -| derived_table { $$.v = $1.v as TablePrimary } -| derived_table correlation_or_recognition { - $$.v = TablePrimary{ - body: ($1.v as TablePrimary).body - correlation: $2.v as Correlation - } - } - -correlation_or_recognition: - correlation_name { - $$.v = Correlation{ - name: $1.v as Identifier - } - } -| AS correlation_name { - $$.v = Correlation{ - name: $2.v as Identifier - } - } -| correlation_name parenthesized_derived_column_list { - $$.v = Correlation{ - name: $1.v as Identifier - columns: $2.v as []Identifier - } - } -| AS correlation_name parenthesized_derived_column_list { - $$.v = Correlation{ - name: $2.v as Identifier - columns: $3.v as []Identifier - } - } - -derived_table: - table_subquery { $$.v = $1.v as TablePrimary } - -table_or_query_name: - table_name { $$.v = $1.v as Identifier } - -derived_column_list: - column_name_list { $$.v = $1.v as []Identifier } - -column_name_list: - column_name { $$.v = [$1.v as Identifier] } -| column_name_list comma column_name { - $$.v = append_list($1.v as []Identifier, $3.v as Identifier) - } - -parenthesized_derived_column_list: - left_paren derived_column_list right_paren { $$.v = $2.v } - -sequence_generator_definition: - CREATE SEQUENCE sequence_generator_name { - $$.v = SequenceGeneratorDefinition{ - name: $3.v as Identifier - } - } -| CREATE SEQUENCE sequence_generator_name sequence_generator_options { - $$.v = SequenceGeneratorDefinition{ - name: $3.v as Identifier - options: $4.v as []SequenceGeneratorOption - } - } - -sequence_generator_options: - sequence_generator_option { $$.v = $1.v as []SequenceGeneratorOption } -| sequence_generator_options sequence_generator_option { - $$.v = $1.v as []SequenceGeneratorOption - } - -sequence_generator_option: - common_sequence_generator_options { $$.v = $1.v as []SequenceGeneratorOption } - -common_sequence_generator_options: - common_sequence_generator_option { $$.v = [$1.v as SequenceGeneratorOption] } -| common_sequence_generator_options common_sequence_generator_option { - $$.v = append_list($1.v as []SequenceGeneratorOption, - $2.v as SequenceGeneratorOption) - } - -common_sequence_generator_option: - sequence_generator_start_with_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorStartWithOption) - } -| basic_sequence_generator_option { $$.v = $1.v as SequenceGeneratorOption } - -basic_sequence_generator_option: - sequence_generator_increment_by_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorIncrementByOption) - } -| sequence_generator_maxvalue_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorMaxvalueOption) - } -| sequence_generator_minvalue_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorMinvalueOption) - } -| sequence_generator_cycle_option { - $$.v = SequenceGeneratorOption(SequenceGeneratorCycleOption{$1.v as bool}) - } - -sequence_generator_start_with_option: - START WITH sequence_generator_start_value { - $$.v = SequenceGeneratorStartWithOption{ - start_value: $3.v as Value - } - } - -sequence_generator_start_value: - signed_numeric_literal { $$.v = $1.v as Value } - -sequence_generator_increment_by_option: - INCREMENT BY sequence_generator_increment { - $$.v = SequenceGeneratorIncrementByOption{ - increment_by: $3.v as Value - } - } - -sequence_generator_increment: - signed_numeric_literal { $$.v = $1.v as Value } - -sequence_generator_maxvalue_option: - MAXVALUE sequence_generator_max_value { - $$.v = SequenceGeneratorMaxvalueOption{ - max_value: $2.v as Value - } - } -| NO MAXVALUE { $$.v = SequenceGeneratorMaxvalueOption{} } - -sequence_generator_max_value: - signed_numeric_literal { $$.v = $1.v as Value } - -sequence_generator_minvalue_option: - MINVALUE sequence_generator_min_value { - $$.v = SequenceGeneratorMinvalueOption{ - min_value: $2.v as Value - } - } -| NO MINVALUE { $$.v = SequenceGeneratorMinvalueOption{} } - -sequence_generator_min_value: - signed_numeric_literal { $$.v = $1.v as Value } - -sequence_generator_cycle_option: - CYCLE { $$.v = true } -| NO CYCLE { $$.v = false } - -search_condition: - boolean_value_expression { $$.v = $1.v as BooleanValueExpression } - -value_expression: - common_value_expression { - $$.v = ValueExpression($1.v as CommonValueExpression) - } -| boolean_value_expression { - $$.v = ValueExpression($1.v as BooleanValueExpression) - } - -common_value_expression: - numeric_value_expression { - $$.v = CommonValueExpression($1.v as NumericValueExpression) - } -| string_value_expression { - $$.v = CommonValueExpression($1.v as CharacterValueExpression) - } -| datetime_value_expression { - $$.v = CommonValueExpression($1.v as DatetimePrimary) - } - -table_expression: - from_clause { - $$.v = TableExpression{$1.v as TableReference, none, []Identifier{}} - } -| from_clause where_clause { - $$.v = TableExpression{ - $1.v as TableReference - $2.v as BooleanValueExpression - []Identifier{} - } - } -| from_clause group_by_clause { - $$.v = TableExpression{$1.v as TableReference, none, $2.v as []Identifier} - } -| from_clause where_clause group_by_clause { - $$.v = TableExpression{ - $1.v as TableReference - $2.v as BooleanValueExpression - $3.v as []Identifier - } - } - -group_by_clause: - GROUP BY grouping_element_list { $$.v = $3.v } - -grouping_element_list: - grouping_element { $$.v = [$1.v as Identifier] } -| grouping_element_list comma grouping_element { - $$.v = append_list($1.v as []Identifier, $3.v as Identifier) - } - -grouping_element: - ordinary_grouping_set { $$.v = $1.v as Identifier } - -ordinary_grouping_set: - grouping_column_reference { $$.v = $1.v as Identifier } - -grouping_column_reference: - column_reference { $$.v = $1.v as Identifier } - -boolean_value_expression: - boolean_term { $$.v = BooleanValueExpression{term: $1.v as BooleanTerm} } -| boolean_value_expression OR boolean_term { - expr := $1.v as BooleanValueExpression - $$.v = BooleanValueExpression{&expr, $3.v as BooleanTerm} - } - -boolean_term: - boolean_factor { $$.v = BooleanTerm{factor: $1.v as BooleanTest} } -| boolean_term AND boolean_factor { - term := $1.v as BooleanTerm - $$.v = BooleanTerm{&term, $3.v as BooleanTest} - } - -boolean_factor: - boolean_test { $$.v = $1.v as BooleanTest } -| NOT boolean_test { - b := $2.v as BooleanTest - $$.v = BooleanTest{b.expr, b.not, b.value, !b.inverse} - } - -boolean_test: - boolean_primary { $$.v = BooleanTest{expr: $1.v as BooleanPrimary} } -| boolean_primary IS_TRUE { - $$.v = BooleanTest{ - $1.v as BooleanPrimary - false - new_boolean_value(true) - false - } - } -| boolean_primary IS_FALSE { - $$.v = BooleanTest{ - $1.v as BooleanPrimary - false - new_boolean_value(false) - false - } - } -| boolean_primary IS_UNKNOWN { - $$.v = BooleanTest{ - $1.v as BooleanPrimary - false - new_unknown_value() - false - } - } -| boolean_primary IS_NOT_TRUE { - $$.v = BooleanTest{ - $1.v as BooleanPrimary - true - new_boolean_value(true) - false - } - } -| boolean_primary IS_NOT_FALSE { - $$.v = BooleanTest{ - $1.v as BooleanPrimary - true - new_boolean_value(false) - false - } - } -| boolean_primary IS_NOT_UNKNOWN { - $$.v = BooleanTest{ - $1.v as BooleanPrimary - true - new_unknown_value() - false - } - } - -boolean_primary: - predicate { $$.v = BooleanPrimary($1.v as Predicate) } -| boolean_predicand { $$.v = BooleanPrimary($1.v as BooleanPredicand) } - -boolean_predicand: - parenthesized_boolean_value_expression { - $$.v = BooleanPredicand($1.v as BooleanValueExpression) - } -| nonparenthesized_value_expression_primary { - $$.v = BooleanPredicand($1.v as NonparenthesizedValueExpressionPrimary) - } - -parenthesized_boolean_value_expression: - left_paren boolean_value_expression right_paren { $$.v = $2.v } - -unique_constraint_definition: - unique_specification left_paren unique_column_list right_paren { - $$.v = UniqueConstraintDefinition{$3.v as []Identifier} - } - -unique_specification: - PRIMARY KEY - -unique_column_list: - column_name_list { $$.v = $1.v as []Identifier } - -table_row_value_expression: - row_value_constructor { $$.v = $1.v as RowValueConstructor } - -contextually_typed_row_value_expression: - contextually_typed_row_value_constructor { - $$.v = $1.v as ContextuallyTypedRowValueConstructor - } - -row_value_predicand: - row_value_constructor_predicand { - $$.v = $1.v as RowValueConstructorPredicand - } - -sql_schema_statement: - sql_schema_definition_statement { $$.v = $1.v as Stmt } -| sql_schema_manipulation_statement { $$.v = $1.v as Stmt } - -sql_schema_definition_statement: - schema_definition { $$.v = $1.v as Stmt } -| table_definition { $$.v = $1.v as Stmt } -| sequence_generator_definition { $$.v = Stmt($1.v as SequenceGeneratorDefinition) } - -sql_schema_manipulation_statement: - drop_schema_statement { $$.v = $1.v as Stmt } -| drop_table_statement { $$.v = $1.v as Stmt } -| alter_sequence_generator_statement { $$.v = Stmt($1.v as AlterSequenceGeneratorStatement) } -| drop_sequence_generator_statement { $$.v = $1.v as Stmt } - -sql_transaction_statement: - start_transaction_statement { $$.v = $1.v as Stmt } -| commit_statement { $$.v = $1.v as Stmt } -| rollback_statement { $$.v = $1.v as Stmt } - -sql_session_statement: - set_schema_statement { $$.v = Stmt($1.v as SetSchemaStatement) } -| set_catalog_statement { $$.v = $1.v as Stmt } - -datetime_value_function: - current_date_value_function { - $$.v = DatetimeValueFunction($1.v as CurrentDate) - } -| current_time_value_function { - $$.v = DatetimeValueFunction($1.v as CurrentTime) - } -| current_timestamp_value_function { - $$.v = DatetimeValueFunction($1.v as CurrentTimestamp) - } -| current_local_time_value_function { - $$.v = DatetimeValueFunction($1.v as LocalTime) - } -| current_local_timestamp_value_function { - $$.v = DatetimeValueFunction($1.v as LocalTimestamp) - } - -current_date_value_function: - CURRENT_DATE { $$.v = CurrentDate{} } - -current_time_value_function: - CURRENT_TIME { $$.v = CurrentTime{default_time_precision} } -| CURRENT_TIME left_paren time_precision right_paren { - $$.v = CurrentTime{($3.v as string).int()} - } - -current_local_time_value_function: - LOCALTIME { $$.v = LocalTime{0} } -| LOCALTIME left_paren time_precision right_paren { - $$.v = LocalTime{($3.v as string).int()} - } - -current_timestamp_value_function: - CURRENT_TIMESTAMP { $$.v = CurrentTimestamp{default_timestamp_precision} } -| CURRENT_TIMESTAMP left_paren timestamp_precision right_paren { - $$.v = CurrentTimestamp{($3.v as string).int()} - } - -current_local_timestamp_value_function: - LOCALTIMESTAMP { $$.v = LocalTimestamp{6} } -| LOCALTIMESTAMP left_paren timestamp_precision right_paren { - $$.v = LocalTimestamp{($3.v as string).int()} - } - -joined_table: - qualified_join { $$.v = $1.v as QualifiedJoin } - -join_specification: - join_condition { $$.v = $1.v as BooleanValueExpression } - -join_condition: - ON search_condition { $$.v = $2.v } - -join_type: - INNER -| outer_join_type { $$.v = $1.v as string } -| outer_join_type OUTER { $$.v = $1.v as string } - -outer_join_type: - LEFT { $$.v = $1.v as string } -| RIGHT { $$.v = $1.v as string } - -null_predicate: - row_value_predicand null_predicate_part_2 { - $$.v = NullPredicate{$1.v as RowValueConstructorPredicand, !($2.v as bool)} - } - -null_predicate_part_2: - IS NULL { $$.v = true } -| IS NOT NULL { $$.v = false } - -predicate: - comparison_predicate { $$.v = Predicate($1.v as ComparisonPredicate) } -| between_predicate { $$.v = Predicate($1.v as BetweenPredicate) } -| like_predicate { $$.v = Predicate($1.v as CharacterLikePredicate) } -| similar_predicate { $$.v = Predicate($1.v as SimilarPredicate) } -| null_predicate { $$.v = Predicate($1.v as NullPredicate) } - -start_transaction_statement: - START TRANSACTION { $$.v = Stmt(StartTransactionStatement{}) } - -query_expression: - query_expression_body { $$.v = QueryExpression{body: $1.v as SimpleTable} } -| query_expression_body order_by_clause { - $$.v = QueryExpression{ - body: $1.v as SimpleTable - order: $2.v as []SortSpecification - } - } -| query_expression_body result_offset_clause { - $$.v = QueryExpression{ - body: $1.v as SimpleTable - offset: $2.v as ValueSpecification - } - } -| query_expression_body order_by_clause result_offset_clause { - $$.v = QueryExpression{ - body: $1.v as SimpleTable - offset: $3.v as ValueSpecification - order: $2.v as []SortSpecification - } - } -| query_expression_body fetch_first_clause { - $$.v = QueryExpression{ - body: $1.v as SimpleTable - fetch: $2.v as ValueSpecification - } - } -| query_expression_body order_by_clause fetch_first_clause { - $$.v = QueryExpression{ - body: $1.v as SimpleTable - fetch: $3.v as ValueSpecification - order: $2.v as []SortSpecification - } - } -| query_expression_body order_by_clause result_offset_clause - fetch_first_clause { - $$.v = QueryExpression{ - body: $1.v as SimpleTable - offset: $3.v as ValueSpecification - fetch: $4.v as ValueSpecification - order: $2.v as []SortSpecification - } - } -| query_expression_body result_offset_clause fetch_first_clause { - $$.v = QueryExpression{ - body: $1.v as SimpleTable - offset: $2.v as ValueSpecification - fetch: $3.v as ValueSpecification - } - } - -query_expression_body: - query_term { $$.v = $1.v as SimpleTable } - -query_term: - query_primary { $$.v = $1.v as SimpleTable } - -query_primary: - simple_table { $$.v = $1.v as SimpleTable } - -simple_table: - query_specification { $$.v = SimpleTable($1.v as QuerySpecification) } -| table_value_constructor { $$.v = $1.v as SimpleTable } - -order_by_clause: - ORDER BY sort_specification_list { $$.v = $3.v } - -result_offset_clause: - OFFSET offset_row_count row_or_rows { $$.v = $2.v } - -fetch_first_clause: - FETCH FIRST fetch_first_quantity row_or_rows ONLY { $$.v = $3.v } - -fetch_first_quantity: - fetch_first_row_count { $$.v = $1.v as ValueSpecification } - -offset_row_count: - simple_value_specification { $$.v = $1.v as ValueSpecification } - -fetch_first_row_count: - simple_value_specification { $$.v = $1.v as ValueSpecification } - -row_or_rows: - ROW -| ROWS - -similar_predicate: - row_value_predicand similar_predicate_part_2 { - like := $2.v as SimilarPredicate - $$.v = SimilarPredicate{$1.v as RowValueConstructorPredicand, like.right, like.not} - } - -similar_predicate_part_2: - SIMILAR TO similar_pattern { - $$.v = SimilarPredicate{none, $3.v as CharacterValueExpression, false} - } -| NOT SIMILAR TO similar_pattern { - $$.v = SimilarPredicate{none, $4.v as CharacterValueExpression, true} - } - -similar_pattern: - character_value_expression { $$.v = $1.v as CharacterValueExpression } - -left_paren: OPERATOR_LEFT_PAREN - -right_paren: OPERATOR_RIGHT_PAREN - -asterisk: OPERATOR_ASTERISK { $$.v = $1.v as string } - -plus_sign: OPERATOR_PLUS { $$.v = $1.v as string } - -comma: OPERATOR_COMMA - -minus_sign: OPERATOR_MINUS { $$.v = $1.v as string } - -period: OPERATOR_PERIOD - -solidus: OPERATOR_SOLIDUS { $$.v = $1.v as string } - -colon: OPERATOR_COLON - -less_than_operator: OPERATOR_LESS_THAN - -equals_operator: OPERATOR_EQUALS - -greater_than_operator: OPERATOR_GREATER_THAN - -table_constraint_definition: - table_constraint { $$.v = $1.v as TableElement } - -table_constraint: - unique_constraint_definition { - $$.v = TableElement($1.v as UniqueConstraintDefinition) - } - -column_definition: - column_name data_type_or_domain_name { - $$.v = TableElement(Column{$1.v as Identifier, $2.v as Type, false}) - } -| column_name data_type_or_domain_name column_constraint_definition { - $$.v = TableElement(Column{$1.v as Identifier, $2.v as Type, $3.v as bool}) - } - -data_type_or_domain_name: - data_type { $$.v = $1.v as Type } - -column_constraint_definition: - column_constraint { $$.v = $1.v as bool } - -column_constraint: - NOT NULL { $$.v = true } - -set_schema_statement: - SET schema_name_characteristic { - $$.v = SetSchemaStatement{$2.v as ValueSpecification} - } - -schema_name_characteristic: - SCHEMA value_specification { $$.v = $2.v } - -// was: COUNT left_paren asterisk right_paren -aggregate_function: - COUNT OPERATOR_LEFT_PAREN_ASTERISK right_paren { - $$.v = AggregateFunction(AggregateFunctionCount{}) - } -| general_set_function { $$.v = $1.v as AggregateFunction } - -general_set_function: - set_function_type left_paren value_expression right_paren { - $$.v = AggregateFunction(RoutineInvocation{ - $1.v as string, [$3.v as ValueExpression]}) - } - -set_function_type: - computational_operation { $$.v = $1.v as string } - -computational_operation: - AVG { $$.v = $1.v as string } -| MAX { $$.v = $1.v as string } -| MIN { $$.v = $1.v as string } -| SUM { $$.v = $1.v as string } -| COUNT { $$.v = $1.v as string } - -set_catalog_statement: - SET catalog_name_characteristic { - $$.v = Stmt(SetCatalogStatement{$2.v as ValueSpecification}) - } - -catalog_name_characteristic: - CATALOG value_specification { $$.v = $2.v as ValueSpecification } - -drop_table_statement: - DROP TABLE table_name { $$.v = Stmt(DropTableStatement{$3.v as Identifier}) } - -value_specification: - literal { $$.v = ValueSpecification($1.v as Value) } -| general_value_specification { - $$.v = ValueSpecification($1.v as GeneralValueSpecification) - } - -unsigned_value_specification: - unsigned_literal { $$.v = ValueSpecification($1.v as Value) } -| general_value_specification { - $$.v = ValueSpecification($1.v as GeneralValueSpecification) - } - -general_value_specification: - host_parameter_specification { $$.v = $1.v as GeneralValueSpecification } -| CURRENT_CATALOG { $$.v = GeneralValueSpecification(CurrentCatalog{}) } -| CURRENT_SCHEMA { $$.v = GeneralValueSpecification(CurrentSchema{}) } - -simple_value_specification: - literal { $$.v = ValueSpecification($1.v as Value) } -| host_parameter_name { - $$.v = ValueSpecification($1.v as GeneralValueSpecification) - } - -host_parameter_specification: - host_parameter_name { $$.v = $1.v as GeneralValueSpecification } - -insert_statement: - INSERT INTO insertion_target insert_columns_and_source { - stmt := $4.v as InsertStatement - $$.v = Stmt(InsertStatement{$3.v as Identifier, stmt.columns, stmt.values}) - } - -insertion_target: - table_name { $$.v = $1.v as Identifier } - -insert_columns_and_source: - from_constructor { $$.v = $1.v as InsertStatement } - -from_constructor: - left_paren insert_column_list right_paren - contextually_typed_table_value_constructor { - $$.v = InsertStatement{ - columns: $2.v as []Identifier - values: $4.v as []ContextuallyTypedRowValueConstructor - } - } - -insert_column_list: - column_name_list { $$.v = $1.v as []Identifier } - -value_expression_primary: - parenthesized_value_expression { - $$.v = ValueExpressionPrimary($1.v as ParenthesizedValueExpression) - } -| nonparenthesized_value_expression_primary { - $$.v = ValueExpressionPrimary($1.v as NonparenthesizedValueExpressionPrimary) - } - -parenthesized_value_expression: - left_paren value_expression right_paren { - $$.v = ParenthesizedValueExpression{$2.v as ValueExpression} - } - -nonparenthesized_value_expression_primary: - unsigned_value_specification { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as ValueSpecification) - } -| column_reference { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as Identifier) - } -| set_function_specification { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as AggregateFunction) - } -| routine_invocation { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as RoutineInvocation) - } -| case_expression { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as CaseExpression) - } -| cast_specification { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as CastSpecification) - } -| next_value_expression { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as NextValueExpression) - } - -string_value_function: - character_value_function { $$.v = $1.v as CharacterValueFunction } - -character_value_function: - character_substring_function { - $$.v = CharacterValueFunction($1.v as CharacterSubstringFunction) - } -| fold { $$.v = CharacterValueFunction($1.v as RoutineInvocation) } -| trim_function { $$.v = CharacterValueFunction($1.v as TrimFunction) } - -character_substring_function: - SUBSTRING left_paren character_value_expression FROM start_position - right_paren { - $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, - $5.v as NumericValueExpression, none, 'CHARACTERS'} - } -| SUBSTRING left_paren character_value_expression FROM start_position FOR - string_length right_paren { - $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, - $5.v as NumericValueExpression, $7.v as NumericValueExpression, - 'CHARACTERS'} - } -| SUBSTRING left_paren character_value_expression FROM start_position USING - char_length_units right_paren { - $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, - $5.v as NumericValueExpression, none, $7.v as string} - } -| SUBSTRING left_paren character_value_expression FROM start_position FOR - string_length USING char_length_units right_paren { - $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, - $5.v as NumericValueExpression, $7.v as NumericValueExpression, - $9.v as string} - } - -fold: - UPPER left_paren character_value_expression right_paren { - $$.v = RoutineInvocation{'UPPER', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression))]} - } -| LOWER left_paren character_value_expression right_paren { - $$.v = RoutineInvocation{'LOWER', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression))]} - } - -trim_function: - TRIM left_paren trim_operands right_paren { $$.v = $3.v as TrimFunction } - -trim_operands: - trim_source { - space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) - $$.v = TrimFunction{'BOTH', space, $1.v as CharacterValueExpression} - } -| FROM trim_source { - space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) - $$.v = TrimFunction{'BOTH', space, $2.v as CharacterValueExpression} - } -| trim_specification FROM trim_source { - space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) - $$.v = TrimFunction{$1.v as string, space, $3.v as CharacterValueExpression} - } -| trim_character FROM trim_source { - $$.v = TrimFunction{'BOTH', $1.v as CharacterValueExpression, $3.v as CharacterValueExpression} - } -| trim_specification trim_character FROM trim_source { - $$.v = TrimFunction{$1.v as string, $2.v as CharacterValueExpression, $4.v as CharacterValueExpression} - } - -trim_source: - character_value_expression { $$.v = $1.v as CharacterValueExpression } - -trim_specification: - LEADING { $$.v = $1.v as string } -| TRAILING { $$.v = $1.v as string } -| BOTH { $$.v = $1.v as string } - -trim_character: - character_value_expression { $$.v = $1.v as CharacterValueExpression } - -start_position: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } - -string_length: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } - -numeric_value_expression: - term { $$.v = NumericValueExpression{term: $1.v as Term} } -| numeric_value_expression plus_sign term { - n := $1.v as NumericValueExpression - $$.v = NumericValueExpression{&n, '+', $3.v as Term} - } -| numeric_value_expression minus_sign term { - n := $1.v as NumericValueExpression - $$.v = NumericValueExpression{&n, '-', $3.v as Term} - } - -term: - factor { $$.v = Term{factor: $1.v as NumericPrimary} } -| term asterisk factor { - t := $1.v as Term - $$.v = Term{&t, '*', $3.v as NumericPrimary} - } -| term solidus factor { - t := $1.v as Term - $$.v = Term{&t, '/', $3.v as NumericPrimary} - } - -factor: - numeric_primary { $$.v = $1.v as NumericPrimary } -| sign numeric_primary { - $$.v = parse_factor_2($1.v as string, $2.v as NumericPrimary)! - } - -numeric_primary: - value_expression_primary { - $$.v = NumericPrimary($1.v as ValueExpressionPrimary) - } -| numeric_value_function { $$.v = NumericPrimary($1.v as RoutineInvocation) } - -routine_invocation: - routine_name sql_argument_list { - $$.v = RoutineInvocation{($1.v as Identifier).entity_name, $2.v as []ValueExpression} - } - -routine_name: - qualified_identifier { - $$.v = new_function_identifier(($1.v as IdentifierChain).identifier)! - } - -sql_argument_list: - left_paren right_paren { $$.v = []ValueExpression{} } -| left_paren sql_argument right_paren { $$.v = [$2.v as ValueExpression] } -| left_paren sql_argument_list comma sql_argument right_paren { - $$.v = append_list($2.v as []ValueExpression, $4.v as ValueExpression) - } - -sql_argument: - value_expression { $$.v = $1.v as ValueExpression } - %% diff --git a/vsql/std_10_10_sort_specification_list.y b/vsql/std_10_10_sort_specification_list.y new file mode 100644 index 0000000..c6cd0f3 --- /dev/null +++ b/vsql/std_10_10_sort_specification_list.y @@ -0,0 +1,22 @@ +%% + +sort_specification_list: + sort_specification { $$.v = [$1.v as SortSpecification] } +| sort_specification_list comma sort_specification { + $$.v = append_list($1.v as []SortSpecification, $3.v as SortSpecification) + } + +sort_specification: + sort_key { $$.v = SortSpecification{$1.v as ValueExpression, true} } +| sort_key ordering_specification { + $$.v = SortSpecification{$1.v as ValueExpression, $2.v as bool} + } + +sort_key: + value_expression { $$.v = $1.v as ValueExpression } + +ordering_specification: + ASC { $$.v = true } +| DESC { $$.v = false } + +%% diff --git a/vsql/std_10_4_routine_invocation.y b/vsql/std_10_4_routine_invocation.y new file mode 100644 index 0000000..039ab8f --- /dev/null +++ b/vsql/std_10_4_routine_invocation.y @@ -0,0 +1,23 @@ +%% + +routine_invocation: + routine_name sql_argument_list { + $$.v = RoutineInvocation{($1.v as Identifier).entity_name, $2.v as []ValueExpression} + } + +routine_name: + qualified_identifier { + $$.v = new_function_identifier(($1.v as IdentifierChain).identifier)! + } + +sql_argument_list: + left_paren right_paren { $$.v = []ValueExpression{} } +| left_paren sql_argument right_paren { $$.v = [$2.v as ValueExpression] } +| left_paren sql_argument_list comma sql_argument right_paren { + $$.v = append_list($2.v as []ValueExpression, $4.v as ValueExpression) + } + +sql_argument: + value_expression { $$.v = $1.v as ValueExpression } + +%% diff --git a/vsql/std_10_9_aggregate_function.y b/vsql/std_10_9_aggregate_function.y new file mode 100644 index 0000000..f920c42 --- /dev/null +++ b/vsql/std_10_9_aggregate_function.y @@ -0,0 +1,26 @@ +%% + +// was: COUNT left_paren asterisk right_paren +aggregate_function: + COUNT OPERATOR_LEFT_PAREN_ASTERISK right_paren { + $$.v = AggregateFunction(AggregateFunctionCount{}) + } +| general_set_function { $$.v = $1.v as AggregateFunction } + +general_set_function: + set_function_type left_paren value_expression right_paren { + $$.v = AggregateFunction(RoutineInvocation{ + $1.v as string, [$3.v as ValueExpression]}) + } + +set_function_type: + computational_operation { $$.v = $1.v as string } + +computational_operation: + AVG { $$.v = $1.v as string } +| MAX { $$.v = $1.v as string } +| MIN { $$.v = $1.v as string } +| SUM { $$.v = $1.v as string } +| COUNT { $$.v = $1.v as string } + +%% diff --git a/vsql/std_11_1_schema_definition.y b/vsql/std_11_1_schema_definition.y new file mode 100644 index 0000000..5889c42 --- /dev/null +++ b/vsql/std_11_1_schema_definition.y @@ -0,0 +1,11 @@ +%% + +schema_definition: + CREATE SCHEMA schema_name_clause { + $$.v = Stmt(SchemaDefinition{$3.v as Identifier}) + } + +schema_name_clause: + schema_name { $$.v = $1.v as Identifier } + +%% diff --git a/vsql/std_11_2_drop_schema_statement.y b/vsql/std_11_2_drop_schema_statement.y new file mode 100644 index 0000000..b1a609b --- /dev/null +++ b/vsql/std_11_2_drop_schema_statement.y @@ -0,0 +1,12 @@ +%% + +drop_schema_statement: + DROP SCHEMA schema_name drop_behavior { + $$.v = Stmt(DropSchemaStatement{$3.v as Identifier, $4.v as string}) + } + +drop_behavior: + CASCADE { $$.v = $1.v as string } +| RESTRICT { $$.v = $1.v as string } + +%% diff --git a/vsql/std_11_31_drop_table_statement.y b/vsql/std_11_31_drop_table_statement.y new file mode 100644 index 0000000..968768e --- /dev/null +++ b/vsql/std_11_31_drop_table_statement.y @@ -0,0 +1,6 @@ +%% + +drop_table_statement: + DROP TABLE table_name { $$.v = Stmt(DropTableStatement{$3.v as Identifier}) } + +%% diff --git a/vsql/std_11_3_table_definition.y b/vsql/std_11_3_table_definition.y new file mode 100644 index 0000000..d6b3d23 --- /dev/null +++ b/vsql/std_11_3_table_definition.y @@ -0,0 +1,24 @@ +%% + +table_definition: + CREATE TABLE table_name table_contents_source { + $$.v = Stmt(TableDefinition{$3.v as Identifier, $4.v as []TableElement}) + } + +table_contents_source: + table_element_list { $$.v = $1.v as []TableElement } + +table_element_list: + left_paren table_elements right_paren { $$.v = $2.v as []TableElement } + +table_element: + column_definition { $$.v = $1.v as TableElement } +| table_constraint_definition { $$.v = $1.v as TableElement } + +table_elements: + table_element { $$.v = [$1.v as TableElement] } +| table_elements comma table_element { + $$.v = append_list($1.v as []TableElement, $3.v as TableElement) + } + +%% diff --git a/vsql/std_11_4_column_definition.y b/vsql/std_11_4_column_definition.y new file mode 100644 index 0000000..8796fc9 --- /dev/null +++ b/vsql/std_11_4_column_definition.y @@ -0,0 +1,20 @@ +%% + +column_definition: + column_name data_type_or_domain_name { + $$.v = TableElement(Column{$1.v as Identifier, $2.v as Type, false}) + } +| column_name data_type_or_domain_name column_constraint_definition { + $$.v = TableElement(Column{$1.v as Identifier, $2.v as Type, $3.v as bool}) + } + +data_type_or_domain_name: + data_type { $$.v = $1.v as Type } + +column_constraint_definition: + column_constraint { $$.v = $1.v as bool } + +column_constraint: + NOT NULL { $$.v = true } + +%% diff --git a/vsql/std_11_6_table_constraint_definition.y b/vsql/std_11_6_table_constraint_definition.y new file mode 100644 index 0000000..1e11614 --- /dev/null +++ b/vsql/std_11_6_table_constraint_definition.y @@ -0,0 +1,11 @@ +%% + +table_constraint_definition: + table_constraint { $$.v = $1.v as TableElement } + +table_constraint: + unique_constraint_definition { + $$.v = TableElement($1.v as UniqueConstraintDefinition) + } + +%% diff --git a/vsql/std_11_72_sequence_generator_definition.y b/vsql/std_11_72_sequence_generator_definition.y new file mode 100644 index 0000000..e95d87d --- /dev/null +++ b/vsql/std_11_72_sequence_generator_definition.y @@ -0,0 +1,98 @@ +%% + +sequence_generator_definition: + CREATE SEQUENCE sequence_generator_name { + $$.v = SequenceGeneratorDefinition{ + name: $3.v as Identifier + } + } +| CREATE SEQUENCE sequence_generator_name sequence_generator_options { + $$.v = SequenceGeneratorDefinition{ + name: $3.v as Identifier + options: $4.v as []SequenceGeneratorOption + } + } + +sequence_generator_options: + sequence_generator_option { $$.v = $1.v as []SequenceGeneratorOption } +| sequence_generator_options sequence_generator_option { + $$.v = $1.v as []SequenceGeneratorOption + } + +sequence_generator_option: + common_sequence_generator_options { $$.v = $1.v as []SequenceGeneratorOption } + +common_sequence_generator_options: + common_sequence_generator_option { $$.v = [$1.v as SequenceGeneratorOption] } +| common_sequence_generator_options common_sequence_generator_option { + $$.v = append_list($1.v as []SequenceGeneratorOption, + $2.v as SequenceGeneratorOption) + } + +common_sequence_generator_option: + sequence_generator_start_with_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorStartWithOption) + } +| basic_sequence_generator_option { $$.v = $1.v as SequenceGeneratorOption } + +basic_sequence_generator_option: + sequence_generator_increment_by_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorIncrementByOption) + } +| sequence_generator_maxvalue_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorMaxvalueOption) + } +| sequence_generator_minvalue_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorMinvalueOption) + } +| sequence_generator_cycle_option { + $$.v = SequenceGeneratorOption(SequenceGeneratorCycleOption{$1.v as bool}) + } + +sequence_generator_start_with_option: + START WITH sequence_generator_start_value { + $$.v = SequenceGeneratorStartWithOption{ + start_value: $3.v as Value + } + } + +sequence_generator_start_value: + signed_numeric_literal { $$.v = $1.v as Value } + +sequence_generator_increment_by_option: + INCREMENT BY sequence_generator_increment { + $$.v = SequenceGeneratorIncrementByOption{ + increment_by: $3.v as Value + } + } + +sequence_generator_increment: + signed_numeric_literal { $$.v = $1.v as Value } + +sequence_generator_maxvalue_option: + MAXVALUE sequence_generator_max_value { + $$.v = SequenceGeneratorMaxvalueOption{ + max_value: $2.v as Value + } + } +| NO MAXVALUE { $$.v = SequenceGeneratorMaxvalueOption{} } + +sequence_generator_max_value: + signed_numeric_literal { $$.v = $1.v as Value } + +sequence_generator_minvalue_option: + MINVALUE sequence_generator_min_value { + $$.v = SequenceGeneratorMinvalueOption{ + min_value: $2.v as Value + } + } +| NO MINVALUE { $$.v = SequenceGeneratorMinvalueOption{} } + +sequence_generator_min_value: + signed_numeric_literal { $$.v = $1.v as Value } + +sequence_generator_cycle_option: + CYCLE { $$.v = true } +| NO CYCLE { $$.v = false } + +%% diff --git a/vsql/std_11_73_alter_sequence_generator_statement.y b/vsql/std_11_73_alter_sequence_generator_statement.y new file mode 100644 index 0000000..59c4834 --- /dev/null +++ b/vsql/std_11_73_alter_sequence_generator_statement.y @@ -0,0 +1,35 @@ +%% + +alter_sequence_generator_statement: + ALTER SEQUENCE sequence_generator_name alter_sequence_generator_options { + $$.v = AlterSequenceGeneratorStatement{ + name: $3.v as Identifier + options: $4.v as []SequenceGeneratorOption + } + } + +alter_sequence_generator_options: + alter_sequence_generator_option { $$.v = [$1.v as SequenceGeneratorOption] } +| alter_sequence_generator_options alter_sequence_generator_option { + $$.v = append_list($1.v as []SequenceGeneratorOption, + $2.v as SequenceGeneratorOption) + } + +alter_sequence_generator_option: + alter_sequence_generator_restart_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorRestartOption) + } +| basic_sequence_generator_option { $$.v = $1.v as SequenceGeneratorOption } + +alter_sequence_generator_restart_option: + RESTART { $$.v = SequenceGeneratorRestartOption{} } +| RESTART WITH sequence_generator_restart_value { + $$.v = SequenceGeneratorRestartOption{ + restart_value: $3.v as Value + } + } + +sequence_generator_restart_value: + signed_numeric_literal { $$.v = $1.v as Value } + +%% diff --git a/vsql/std_11_74_drop_sequence_generator_statement.y b/vsql/std_11_74_drop_sequence_generator_statement.y new file mode 100644 index 0000000..c91d27a --- /dev/null +++ b/vsql/std_11_74_drop_sequence_generator_statement.y @@ -0,0 +1,8 @@ +%% + +drop_sequence_generator_statement: + DROP SEQUENCE sequence_generator_name { + $$.v = Stmt(DropSequenceGeneratorStatement{$3.v as Identifier}) + } + +%% diff --git a/vsql/std_11_7_unique_constraint_definition.y b/vsql/std_11_7_unique_constraint_definition.y new file mode 100644 index 0000000..378114b --- /dev/null +++ b/vsql/std_11_7_unique_constraint_definition.y @@ -0,0 +1,14 @@ +%% + +unique_constraint_definition: + unique_specification left_paren unique_column_list right_paren { + $$.v = UniqueConstraintDefinition{$3.v as []Identifier} + } + +unique_specification: + PRIMARY KEY + +unique_column_list: + column_name_list { $$.v = $1.v as []Identifier } + +%% diff --git a/vsql/std_13_4_sql_procedure_statement.y b/vsql/std_13_4_sql_procedure_statement.y new file mode 100644 index 0000000..8d8820d --- /dev/null +++ b/vsql/std_13_4_sql_procedure_statement.y @@ -0,0 +1,27 @@ +%% + +sql_schema_statement: + sql_schema_definition_statement { $$.v = $1.v as Stmt } +| sql_schema_manipulation_statement { $$.v = $1.v as Stmt } + +sql_schema_definition_statement: + schema_definition { $$.v = $1.v as Stmt } +| table_definition { $$.v = $1.v as Stmt } +| sequence_generator_definition { $$.v = Stmt($1.v as SequenceGeneratorDefinition) } + +sql_schema_manipulation_statement: + drop_schema_statement { $$.v = $1.v as Stmt } +| drop_table_statement { $$.v = $1.v as Stmt } +| alter_sequence_generator_statement { $$.v = Stmt($1.v as AlterSequenceGeneratorStatement) } +| drop_sequence_generator_statement { $$.v = $1.v as Stmt } + +sql_transaction_statement: + start_transaction_statement { $$.v = $1.v as Stmt } +| commit_statement { $$.v = $1.v as Stmt } +| rollback_statement { $$.v = $1.v as Stmt } + +sql_session_statement: + set_schema_statement { $$.v = Stmt($1.v as SetSchemaStatement) } +| set_catalog_statement { $$.v = $1.v as Stmt } + +%% diff --git a/vsql/std_14_11_insert_statement.y b/vsql/std_14_11_insert_statement.y new file mode 100644 index 0000000..39ada83 --- /dev/null +++ b/vsql/std_14_11_insert_statement.y @@ -0,0 +1,27 @@ +%% + +insert_statement: + INSERT INTO insertion_target insert_columns_and_source { + stmt := $4.v as InsertStatement + $$.v = Stmt(InsertStatement{$3.v as Identifier, stmt.columns, stmt.values}) + } + +insertion_target: + table_name { $$.v = $1.v as Identifier } + +insert_columns_and_source: + from_constructor { $$.v = $1.v as InsertStatement } + +from_constructor: + left_paren insert_column_list right_paren + contextually_typed_table_value_constructor { + $$.v = InsertStatement{ + columns: $2.v as []Identifier + values: $4.v as []ContextuallyTypedRowValueConstructor + } + } + +insert_column_list: + column_name_list { $$.v = $1.v as []Identifier } + +%% diff --git a/vsql/std_14_14_update_statement_searched.y b/vsql/std_14_14_update_statement_searched.y new file mode 100644 index 0000000..fe75dc0 --- /dev/null +++ b/vsql/std_14_14_update_statement_searched.y @@ -0,0 +1,13 @@ +%% + +update_statement_searched: + UPDATE target_table SET set_clause_list { + $$.v = Stmt(UpdateStatementSearched{$2.v as Identifier, + $4.v as map[string]UpdateSource, none}) + } +| UPDATE target_table SET set_clause_list WHERE search_condition { + $$.v = Stmt(UpdateStatementSearched{$2.v as Identifier, + $4.v as map[string]UpdateSource, $6.v as BooleanValueExpression}) + } + +%% diff --git a/vsql/std_14_15_set_clause_list.y b/vsql/std_14_15_set_clause_list.y new file mode 100644 index 0000000..d707413 --- /dev/null +++ b/vsql/std_14_15_set_clause_list.y @@ -0,0 +1,32 @@ +%% + +set_clause_list: + set_clause { $$.v = $1.v as map[string]UpdateSource } +| set_clause_list comma set_clause { + $$.v = merge_maps($1.v as map[string]UpdateSource, + $3.v as map[string]UpdateSource) + } + +set_clause: + set_target equals_operator update_source { + $$.v = { + ($1.v as Identifier).str(): $3.v as UpdateSource + } + } + +set_target: + update_target { $$.v = $1.v as Identifier } + +update_target: + object_column { $$.v = $1.v as Identifier } + +update_source: + value_expression { $$.v = UpdateSource($1.v as ValueExpression) } +| contextually_typed_value_specification { + $$.v = UpdateSource($1.v as NullSpecification) + } + +object_column: + column_name { $$.v = $1.v as Identifier } + +%% diff --git a/vsql/std_14_3_cursor_specification.y b/vsql/std_14_3_cursor_specification.y new file mode 100644 index 0000000..7245d46 --- /dev/null +++ b/vsql/std_14_3_cursor_specification.y @@ -0,0 +1,6 @@ +%% + +cursor_specification: + query_expression { $$.v = Stmt($1.v as QueryExpression) } + +%% diff --git a/vsql/std_14_8_delete_statement_positioned.y b/vsql/std_14_8_delete_statement_positioned.y new file mode 100644 index 0000000..d370d47 --- /dev/null +++ b/vsql/std_14_8_delete_statement_positioned.y @@ -0,0 +1,6 @@ +%% + +target_table: + table_name { $$.v = $1.v as Identifier } + +%% diff --git a/vsql/std_14_9_delete_statement_searched.y b/vsql/std_14_9_delete_statement_searched.y new file mode 100644 index 0000000..e5b6db0 --- /dev/null +++ b/vsql/std_14_9_delete_statement_searched.y @@ -0,0 +1,14 @@ +%% + +delete_statement_searched: + DELETE FROM target_table { + $$.v = Stmt(DeleteStatementSearched{$3.v as Identifier, none}) + } +| DELETE FROM target_table WHERE search_condition { + $$.v = Stmt(DeleteStatementSearched{ + $3.v as Identifier + $5.v as BooleanValueExpression + }) + } + +%% diff --git a/vsql/std_17_1_start_transaction_statement.y b/vsql/std_17_1_start_transaction_statement.y new file mode 100644 index 0000000..fce0a31 --- /dev/null +++ b/vsql/std_17_1_start_transaction_statement.y @@ -0,0 +1,6 @@ +%% + +start_transaction_statement: + START TRANSACTION { $$.v = Stmt(StartTransactionStatement{}) } + +%% diff --git a/vsql/std_17_7_commit_statement.y b/vsql/std_17_7_commit_statement.y new file mode 100644 index 0000000..29aa910 --- /dev/null +++ b/vsql/std_17_7_commit_statement.y @@ -0,0 +1,7 @@ +%% + +commit_statement: + COMMIT { $$.v = Stmt(CommitStatement{}) } +| COMMIT WORK { $$.v = Stmt(CommitStatement{}) } + +%% diff --git a/vsql/std_17_8_rollback_statement.y b/vsql/std_17_8_rollback_statement.y new file mode 100644 index 0000000..098686b --- /dev/null +++ b/vsql/std_17_8_rollback_statement.y @@ -0,0 +1,7 @@ +%% + +rollback_statement: + ROLLBACK { $$.v = Stmt(RollbackStatement{}) } +| ROLLBACK WORK { $$.v = Stmt(RollbackStatement{}) } + +%% diff --git a/vsql/std_19_5_set_catalog_statement.y b/vsql/std_19_5_set_catalog_statement.y new file mode 100644 index 0000000..573c81f --- /dev/null +++ b/vsql/std_19_5_set_catalog_statement.y @@ -0,0 +1,11 @@ +%% + +set_catalog_statement: + SET catalog_name_characteristic { + $$.v = Stmt(SetCatalogStatement{$2.v as ValueSpecification}) + } + +catalog_name_characteristic: + CATALOG value_specification { $$.v = $2.v as ValueSpecification } + +%% diff --git a/vsql/std_19_6_set_schema_statement.y b/vsql/std_19_6_set_schema_statement.y new file mode 100644 index 0000000..6286b99 --- /dev/null +++ b/vsql/std_19_6_set_schema_statement.y @@ -0,0 +1,11 @@ +%% + +set_schema_statement: + SET schema_name_characteristic { + $$.v = SetSchemaStatement{$2.v as ValueSpecification} + } + +schema_name_characteristic: + SCHEMA value_specification { $$.v = $2.v } + +%% diff --git a/vsql/std_20_7_prepare_statement.y b/vsql/std_20_7_prepare_statement.y new file mode 100644 index 0000000..800fbd2 --- /dev/null +++ b/vsql/std_20_7_prepare_statement.y @@ -0,0 +1,27 @@ +%% + +preparable_statement: + preparable_sql_data_statement { $$.v = $1.v as Stmt } +| preparable_sql_schema_statement { $$.v = $1.v as Stmt } +| preparable_sql_transaction_statement { $$.v = $1.v as Stmt } +| preparable_sql_session_statement { $$.v = $1.v as Stmt } + +preparable_sql_data_statement: + delete_statement_searched { $$.v = $1.v as Stmt } +| insert_statement { $$.v = $1.v as Stmt } +| dynamic_select_statement { $$.v = $1.v as Stmt } +| update_statement_searched { $$.v = $1.v as Stmt } + +preparable_sql_schema_statement: + sql_schema_statement { $$.v = $1.v as Stmt } + +preparable_sql_transaction_statement: + sql_transaction_statement { $$.v = $1.v as Stmt } + +preparable_sql_session_statement: + sql_session_statement { $$.v = $1.v as Stmt } + +dynamic_select_statement: + cursor_specification { $$.v = $1.v as Stmt } + +%% diff --git a/vsql/std_5_1_sql_terminal_character.y b/vsql/std_5_1_sql_terminal_character.y new file mode 100644 index 0000000..e18d05d --- /dev/null +++ b/vsql/std_5_1_sql_terminal_character.y @@ -0,0 +1,27 @@ +%% + +left_paren: OPERATOR_LEFT_PAREN + +right_paren: OPERATOR_RIGHT_PAREN + +asterisk: OPERATOR_ASTERISK { $$.v = $1.v as string } + +plus_sign: OPERATOR_PLUS { $$.v = $1.v as string } + +comma: OPERATOR_COMMA + +minus_sign: OPERATOR_MINUS { $$.v = $1.v as string } + +period: OPERATOR_PERIOD + +solidus: OPERATOR_SOLIDUS { $$.v = $1.v as string } + +colon: OPERATOR_COLON + +less_than_operator: OPERATOR_LESS_THAN + +equals_operator: OPERATOR_EQUALS + +greater_than_operator: OPERATOR_GREATER_THAN + +%% diff --git a/vsql/std_5_2_token_and_separator.v b/vsql/std_5_2_token_and_separator.v deleted file mode 100644 index 778ee64..0000000 --- a/vsql/std_5_2_token_and_separator.v +++ /dev/null @@ -1,315 +0,0 @@ -module vsql - -// ISO/IEC 9075-2:2016(E), 5.2, and -// -// # Function -// -// Specify lexical units (tokens and separators) that participate in SQL -// language. -// -// # Format -//~ -//~ ::= "||" -// -// is added on top of the original to -// allow non-reserved words to be used as identifiers. As far as I can tell, -// only s are restricted. See "9075-2:2016 5.2 #26". -// -//~ -//~ /* IdentifierChain */ ::= -//~ -//~ | -> string_identifier -//~ -//~ /* IdentifierChain */ ::= -//~ -//~ -//~ /* IdentifierChain */ ::= -//~ ^identifier -//~ -//~ ::= "<>" -//~ -//~ ::= ">=" -//~ -//~ ::= "<=" -//~ -//~ /* string */ ::= -//~ A -//~ | ABSOLUTE -//~ | ACTION -//~ | ADA -//~ | ADD -//~ | ADMIN -//~ | AFTER -//~ | ALWAYS -//~ | ASC -//~ | ASSERTION -//~ | ASSIGNMENT -//~ | ATTRIBUTE -//~ | ATTRIBUTES -//~ | BEFORE -//~ | BERNOULLI -//~ | BREADTH -//~ | C -//~ | CASCADE -//~ | CATALOG -//~ | CATALOG_NAME -//~ | CHAIN -//~ | CHAINING -//~ | CHARACTER_SET_CATALOG -//~ | CHARACTER_SET_NAME -//~ | CHARACTER_SET_SCHEMA -//~ | CHARACTERISTICS -//~ | CHARACTERS -//~ | CLASS_ORIGIN -//~ | COBOL -//~ | COLLATION -//~ | COLLATION_CATALOG -//~ | COLLATION_NAME -//~ | COLLATION_SCHEMA -//~ | COLUMNS -//~ | COLUMN_NAME -//~ | COMMAND_FUNCTION -//~ | COMMAND_FUNCTION_CODE -//~ | COMMITTED -//~ | CONDITIONAL -//~ | CONDITION_NUMBER -//~ | CONNECTION -//~ | CONNECTION_NAME -//~ | CONSTRAINT_CATALOG -//~ | CONSTRAINT_NAME -//~ | CONSTRAINT_SCHEMA -//~ | CONSTRAINTS -//~ | CONSTRUCTOR -//~ | CONTINUE -//~ | CURSOR_NAME -//~ | DATA -//~ | DATETIME_INTERVAL_CODE -//~ | DATETIME_INTERVAL_PRECISION -//~ | DEFAULTS -//~ | DEFERRABLE -//~ | DEFERRED -//~ | DEFINED -//~ | DEFINER -//~ | DEGREE -//~ | DEPTH -//~ | DERIVED -//~ | DESC -//~ | DESCRIBE_CATALOG -//~ | DESCRIBE_NAME -//~ | DESCRIBE_PROCEDURE_SPECIFIC_CATALOG -//~ | DESCRIBE_PROCEDURE_SPECIFIC_NAME -//~ | DESCRIBE_PROCEDURE_SPECIFIC_SCHEMA -//~ | DESCRIBE_SCHEMA -//~ | DESCRIPTOR -//~ | DIAGNOSTICS -//~ | DISPATCH -//~ | DOMAIN -//~ | DYNAMIC_FUNCTION -//~ | DYNAMIC_FUNCTION_CODE -//~ | ENCODING -//~ | ENFORCED -//~ | ERROR -//~ | EXCLUDE -//~ | EXCLUDING -//~ | EXPRESSION -//~ | FINAL -//~ | FINISH -//~ | FINISH_CATALOG -//~ | FINISH_NAME -//~ | FINISH_PROCEDURE_SPECIFIC_CATALOG -//~ | FINISH_PROCEDURE_SPECIFIC_NAME -//~ | FINISH_PROCEDURE_SPECIFIC_SCHEMA -//~ | FINISH_SCHEMA -//~ | FIRST -//~ | FLAG -//~ | FOLLOWING -//~ | FORMAT -//~ | FORTRAN -//~ | FOUND -//~ | FULFILL -//~ | FULFILL_CATALOG -//~ | FULFILL_NAME -//~ | FULFILL_PROCEDURE_SPECIFIC_CATALOG -//~ | FULFILL_PROCEDURE_SPECIFIC_NAME -//~ | FULFILL_PROCEDURE_SPECIFIC_SCHEMA -//~ | FULFILL_SCHEMA -//~ | G -//~ | GENERAL -//~ | GENERATED -//~ | GO -//~ | GOTO -//~ | GRANTED -//~ | HAS_PASS_THROUGH_COLUMNS -//~ | HAS_PASS_THRU_COLS -//~ | HIERARCHY -//~ | IGNORE -//~ | IMMEDIATE -//~ | IMMEDIATELY -//~ | IMPLEMENTATION -//~ | INCLUDING -//~ | INCREMENT -//~ | INITIALLY -//~ | INPUT -//~ | INSTANCE -//~ | INSTANTIABLE -//~ | INSTEAD -//~ | INVOKER -//~ | ISOLATION -//~ | IS_PRUNABLE -//~ | JSON -//~ | K -//~ | KEEP -//~ | KEY -//~ | KEYS -//~ | KEY_MEMBER -//~ | KEY_TYPE -//~ | LAST -//~ | LENGTH -//~ | LEVEL -//~ | LOCATOR -//~ | M -//~ | MAP -//~ | MATCHED -//~ | MAXVALUE -//~ | MESSAGE_LENGTH -//~ | MESSAGE_OCTET_LENGTH -//~ | MESSAGE_TEXT -//~ | MINVALUE -//~ | MORE -//~ | MUMPS -//~ | NAME -//~ | NAMES -//~ | NESTED -//~ | NESTING -//~ | NEXT -//~ | NFC -//~ | NFD -//~ | NFKC -//~ | NFKD -//~ | NORMALIZED -//~ | NULLABLE -//~ | NULLS -//~ | NUMBER -//~ | OBJECT -//~ | OCTETS -//~ | OPTION -//~ | OPTIONS -//~ | ORDERING -//~ | ORDINALITY -//~ | OTHERS -//~ | OUTPUT -//~ | OVERFLOW -//~ | OVERRIDING -//~ | P -//~ | PAD -//~ | PARAMETER_MODE -//~ | PARAMETER_NAME -//~ | PARAMETER_ORDINAL_POSITION -//~ | PARAMETER_SPECIFIC_CATALOG -//~ | PARAMETER_SPECIFIC_NAME -//~ | PARAMETER_SPECIFIC_SCHEMA -//~ | PARTIAL -//~ | PASCAL -//~ | PASS -//~ | PASSING -//~ | PAST -//~ | PATH -//~ | PLACING -//~ | PLAN -//~ | PLI -//~ | PRECEDING -//~ | PRESERVE -//~ | PRIOR -//~ | PRIVATE -//~ | PRIVATE_PARAMETERS -//~ | PRIVATE_PARAMS_S -//~ | PRIVILEGES -//~ | PRUNE -//~ | PUBLIC -//~ | QUOTES -//~ | READ -//~ | RELATIVE -//~ | REPEATABLE -//~ | RESPECT -//~ | RESTART -//~ | RESTRICT -//~ | RETURNED_CARDINALITY -//~ | RETURNED_LENGTH -//~ | RETURNED_OCTET_LENGTH -//~ | RETURNED_SQLSTATE -//~ | RETURNING -//~ | RETURNS_ONLY_PASS_THROUGH -//~ | RET_ONLY_PASS_THRU -//~ | ROLE -//~ | ROUTINE -//~ | ROUTINE_CATALOG -//~ | ROUTINE_NAME -//~ | ROUTINE_SCHEMA -//~ | ROW_COUNT -//~ | SCALAR -//~ | SCALE -//~ | SCHEMA -//~ | SCHEMA_NAME -//~ | SCOPE_CATALOG -//~ | SCOPE_NAME -//~ | SCOPE_SCHEMA -//~ | SECTION -//~ | SECURITY -//~ | SELF -//~ | SEQUENCE -//~ | SERIALIZABLE -//~ | SERVER_NAME -//~ | SESSION -//~ | SETS -//~ | SIMPLE -//~ | SIZE -//~ | SOURCE -//~ | SPACE -//~ | SPECIFIC_NAME -//~ | START_CATALOG -//~ | START_NAME -//~ | START_PROCEDURE_SPECIFIC_CATALOG -//~ | START_PROCEDURE_SPECIFIC_NAME -//~ | START_PROCEDURE_SPECIFIC_SCHEMA -//~ | START_SCHEMA -//~ | STATE -//~ | STATEMENT -//~ | STRING -//~ | STRUCTURE -//~ | STYLE -//~ | SUBCLASS_ORIGIN -//~ | T -//~ | TABLE_NAME -//~ | TABLE_SEMANTICS -//~ | TEMPORARY -//~ | THROUGH -//~ | TIES -//~ | TOP_LEVEL_COUNT -//~ | TRANSACTION -//~ | TRANSACTION_ACTIVE -//~ | TRANSACTIONS_COMMITTED -//~ | TRANSACTIONS_ROLLED_BACK -//~ | TRANSFORM -//~ | TRANSFORMS -//~ | TRIGGER_CATALOG -//~ | TRIGGER_NAME -//~ | TRIGGER_SCHEMA -//~ | TYPE -//~ | UNBOUNDED -//~ | UNCOMMITTED -//~ | UNCONDITIONAL -//~ | UNDER -//~ | UNNAMED -//~ | USAGE -//~ | USER_DEFINED_TYPE_CATALOG -//~ | USER_DEFINED_TYPE_CODE -//~ | USER_DEFINED_TYPE_NAME -//~ | USER_DEFINED_TYPE_SCHEMA -//~ | UTF16 -//~ | UTF32 -//~ | UTF8 -//~ | VIEW -//~ | WORK -//~ | WRAPPER -//~ | WRITE -//~ | ZONE diff --git a/vsql/std_5_2_token_and_separator.y b/vsql/std_5_2_token_and_separator.y new file mode 100644 index 0000000..51b26ce --- /dev/null +++ b/vsql/std_5_2_token_and_separator.y @@ -0,0 +1,304 @@ +%% + +concatenation_operator: + OPERATOR_DOUBLE_PIPE + +regular_identifier: + identifier_body { $$.v = $1.v as IdentifierChain } +| non_reserved_word { $$.v = IdentifierChain{$1.v as string} } + +identifier_body: + identifier_start { $$.v = $1.v as IdentifierChain } + +identifier_start: + LITERAL_IDENTIFIER { $$.v = $1.v as IdentifierChain } + +not_equals_operator: OPERATOR_NOT_EQUALS + +greater_than_or_equals_operator: OPERATOR_GREATER_EQUALS + +less_than_or_equals_operator: OPERATOR_LESS_EQUALS + +non_reserved_word: + A +| ABSOLUTE +| ACTION +| ADA +| ADD +| ADMIN +| AFTER +| ALWAYS +| ASC +| ASSERTION +| ASSIGNMENT +| ATTRIBUTE +| ATTRIBUTES +| BEFORE +| BERNOULLI +| BREADTH +| C +| CASCADE +| CATALOG +| CATALOG_NAME +| CHAIN +| CHAINING +| CHARACTER_SET_CATALOG +| CHARACTER_SET_NAME +| CHARACTER_SET_SCHEMA +| CHARACTERISTICS +| CHARACTERS +| CLASS_ORIGIN +| COBOL +| COLLATION +| COLLATION_CATALOG +| COLLATION_NAME +| COLLATION_SCHEMA +| COLUMNS +| COLUMN_NAME +| COMMAND_FUNCTION +| COMMAND_FUNCTION_CODE +| COMMITTED +| CONDITIONAL +| CONDITION_NUMBER +| CONNECTION +| CONNECTION_NAME +| CONSTRAINT_CATALOG +| CONSTRAINT_NAME +| CONSTRAINT_SCHEMA +| CONSTRAINTS +| CONSTRUCTOR +| CONTINUE +| CURSOR_NAME +| DATA +| DATETIME_INTERVAL_CODE +| DATETIME_INTERVAL_PRECISION +| DEFAULTS +| DEFERRABLE +| DEFERRED +| DEFINED +| DEFINER +| DEGREE +| DEPTH +| DERIVED +| DESC +| DESCRIBE_CATALOG +| DESCRIBE_NAME +| DESCRIBE_PROCEDURE_SPECIFIC_CATALOG +| DESCRIBE_PROCEDURE_SPECIFIC_NAME +| DESCRIBE_PROCEDURE_SPECIFIC_SCHEMA +| DESCRIBE_SCHEMA +| DESCRIPTOR +| DIAGNOSTICS +| DISPATCH +| DOMAIN +| DYNAMIC_FUNCTION +| DYNAMIC_FUNCTION_CODE +| ENCODING +| ENFORCED +| ERROR +| EXCLUDE +| EXCLUDING +| EXPRESSION +| FINAL +| FINISH +| FINISH_CATALOG +| FINISH_NAME +| FINISH_PROCEDURE_SPECIFIC_CATALOG +| FINISH_PROCEDURE_SPECIFIC_NAME +| FINISH_PROCEDURE_SPECIFIC_SCHEMA +| FINISH_SCHEMA +| FIRST +| FLAG +| FOLLOWING +| FORMAT +| FORTRAN +| FOUND +| FULFILL +| FULFILL_CATALOG +| FULFILL_NAME +| FULFILL_PROCEDURE_SPECIFIC_CATALOG +| FULFILL_PROCEDURE_SPECIFIC_NAME +| FULFILL_PROCEDURE_SPECIFIC_SCHEMA +| FULFILL_SCHEMA +| G +| GENERAL +| GENERATED +| GO +| GOTO +| GRANTED +| HAS_PASS_THROUGH_COLUMNS +| HAS_PASS_THRU_COLS +| HIERARCHY +| IGNORE +| IMMEDIATE +| IMMEDIATELY +| IMPLEMENTATION +| INCLUDING +| INCREMENT +| INITIALLY +| INPUT +| INSTANCE +| INSTANTIABLE +| INSTEAD +| INVOKER +| ISOLATION +| IS_PRUNABLE +| JSON +| K +| KEEP +| KEY +| KEYS +| KEY_MEMBER +| KEY_TYPE +| LAST +| LENGTH +| LEVEL +| LOCATOR +| M +| MAP +| MATCHED +| MAXVALUE +| MESSAGE_LENGTH +| MESSAGE_OCTET_LENGTH +| MESSAGE_TEXT +| MINVALUE +| MORE +| MUMPS +| NAME +| NAMES +| NESTED +| NESTING +| NEXT +| NFC +| NFD +| NFKC +| NFKD +| NORMALIZED +| NULLABLE +| NULLS +| NUMBER +| OBJECT +| OCTETS +| OPTION +| OPTIONS +| ORDERING +| ORDINALITY +| OTHERS +| OUTPUT +| OVERFLOW +| OVERRIDING +| P +| PAD +| PARAMETER_MODE +| PARAMETER_NAME +| PARAMETER_ORDINAL_POSITION +| PARAMETER_SPECIFIC_CATALOG +| PARAMETER_SPECIFIC_NAME +| PARAMETER_SPECIFIC_SCHEMA +| PARTIAL +| PASCAL +| PASS +| PASSING +| PAST +| PATH +| PLACING +| PLAN +| PLI +| PRECEDING +| PRESERVE +| PRIOR +| PRIVATE +| PRIVATE_PARAMETERS +| PRIVATE_PARAMS_S +| PRIVILEGES +| PRUNE +| PUBLIC +| QUOTES +| READ +| RELATIVE +| REPEATABLE +| RESPECT +| RESTART +| RESTRICT +| RETURNED_CARDINALITY +| RETURNED_LENGTH +| RETURNED_OCTET_LENGTH +| RETURNED_SQLSTATE +| RETURNING +| RETURNS_ONLY_PASS_THROUGH +| RET_ONLY_PASS_THRU +| ROLE +| ROUTINE +| ROUTINE_CATALOG +| ROUTINE_NAME +| ROUTINE_SCHEMA +| ROW_COUNT +| SCALAR +| SCALE +| SCHEMA +| SCHEMA_NAME +| SCOPE_CATALOG +| SCOPE_NAME +| SCOPE_SCHEMA +| SECTION +| SECURITY +| SELF +| SEQUENCE +| SERIALIZABLE +| SERVER_NAME +| SESSION +| SETS +| SIMPLE +| SIZE +| SOURCE +| SPACE +| SPECIFIC_NAME +| START_CATALOG +| START_NAME +| START_PROCEDURE_SPECIFIC_CATALOG +| START_PROCEDURE_SPECIFIC_NAME +| START_PROCEDURE_SPECIFIC_SCHEMA +| START_SCHEMA +| STATE +| STATEMENT +| STRING +| STRUCTURE +| STYLE +| SUBCLASS_ORIGIN +| T +| TABLE_NAME +| TABLE_SEMANTICS +| TEMPORARY +| THROUGH +| TIES +| TOP_LEVEL_COUNT +| TRANSACTION +| TRANSACTION_ACTIVE +| TRANSACTIONS_COMMITTED +| TRANSACTIONS_ROLLED_BACK +| TRANSFORM +| TRANSFORMS +| TRIGGER_CATALOG +| TRIGGER_NAME +| TRIGGER_SCHEMA +| TYPE +| UNBOUNDED +| UNCOMMITTED +| UNCONDITIONAL +| UNDER +| UNNAMED +| USAGE +| USER_DEFINED_TYPE_CATALOG +| USER_DEFINED_TYPE_CODE +| USER_DEFINED_TYPE_NAME +| USER_DEFINED_TYPE_SCHEMA +| UTF16 +| UTF32 +| UTF8 +| VIEW +| WORK +| WRAPPER +| WRITE +| ZONE + +%% diff --git a/vsql/std_5_3_literal.y b/vsql/std_5_3_literal.y new file mode 100644 index 0000000..4ac634e --- /dev/null +++ b/vsql/std_5_3_literal.y @@ -0,0 +1,96 @@ +%% + +literal: + signed_numeric_literal { $$.v = $1.v as Value } +| general_literal { $$.v = $1.v as Value } + +unsigned_literal: + unsigned_numeric_literal { $$.v = $1.v as Value } +| general_literal { $$.v = $1.v as Value } + +general_literal: + character_string_literal { $$.v = $1.v as Value } +| datetime_literal { $$.v = $1.v as Value } +| boolean_literal { $$.v = $1.v as Value } + +character_string_literal: + LITERAL_STRING { $$.v = $1.v as Value } + +signed_numeric_literal: + unsigned_numeric_literal { $$.v = $1.v as Value } +| sign unsigned_numeric_literal { + $$.v = numeric_literal($1.v as string + ($2.v as Value).str())! + } + +unsigned_numeric_literal: + exact_numeric_literal { $$.v = $1.v as Value } +| approximate_numeric_literal { $$.v = $1.v as Value } + +exact_numeric_literal: + unsigned_integer { $$.v = numeric_literal($1.v as string)! } +| unsigned_integer period { $$.v = numeric_literal(($1.v as string) + '.')! } +| unsigned_integer period unsigned_integer { + $$.v = numeric_literal(($1.v as string) + '.' + ($3.v as string))! + } +| period unsigned_integer { $$.v = numeric_literal('0.' + ($2.v as string))! } + +sign: + plus_sign { $$.v = $1.v as string } +| minus_sign { $$.v = $1.v as string } + +approximate_numeric_literal: + mantissa E exponent { + $$.v = new_double_precision_value( + ($1.v as Value).as_f64()! * math.pow(10, ($3.v as Value).as_f64()!)) + } + +mantissa: + exact_numeric_literal { $$.v = $1.v as Value } + +exponent: + signed_integer { $$.v = $1.v as Value } + +signed_integer: + unsigned_integer { $$.v = new_numeric_value($1.v as string) } +| sign unsigned_integer { + $$.v = if $1.v as string == '-' { + new_numeric_value('-' + ($2.v as string)) + } else { + new_numeric_value($2.v as string) + } + } + +unsigned_integer: + LITERAL_NUMBER { $$.v = $1.v as string } + +datetime_literal: + date_literal { $$.v = $1.v as Value } +| time_literal { $$.v = $1.v as Value } +| timestamp_literal { $$.v = $1.v as Value } + +date_literal: + DATE date_string { $$.v = new_date_value(($2.v as Value).string_value())! } + +time_literal: + TIME time_string { $$.v = new_time_value(($2.v as Value).string_value())! } + +timestamp_literal: + TIMESTAMP timestamp_string { + $$.v = new_timestamp_value(($2.v as Value).string_value())! + } + +date_string: + LITERAL_STRING { $$.v = $1.v as Value } + +time_string: + LITERAL_STRING { $$.v = $1.v as Value } + +timestamp_string: + LITERAL_STRING { $$.v = $1.v as Value } + +boolean_literal: + TRUE { $$.v = new_boolean_value(true) } +| FALSE { $$.v = new_boolean_value(false) } +| UNKNOWN { $$.v = new_unknown_value() } + +%% diff --git a/vsql/std_5_4_names_and_identifiers.y b/vsql/std_5_4_names_and_identifiers.y new file mode 100644 index 0000000..f01cd21 --- /dev/null +++ b/vsql/std_5_4_names_and_identifiers.y @@ -0,0 +1,71 @@ +%% + +identifier: + actual_identifier { $$.v = $1.v as IdentifierChain } + +actual_identifier: + regular_identifier { $$.v = $1.v as IdentifierChain } + +table_name: + local_or_schema_qualified_name { + $$.v = new_table_identifier(($1.v as IdentifierChain).identifier)! + } + +schema_name: + catalog_name period unqualified_schema_name { + $$.v = new_schema_identifier(($1.v as IdentifierChain).str() + '.' + + ($3.v as Identifier).str())! + } +| unqualified_schema_name { $$.v = $1.v as Identifier } + +unqualified_schema_name: + identifier { + $$.v = new_schema_identifier(($1.v as IdentifierChain).identifier)! + } + +catalog_name: + identifier { $$.v = $1.v as IdentifierChain } + +schema_qualified_name: + qualified_identifier { $$.v = $1.v as IdentifierChain } +| schema_name period qualified_identifier { + $$.v = IdentifierChain{($1.v as Identifier).schema_name + '.' + + ($3.v as IdentifierChain).str()} + } + +local_or_schema_qualified_name: + qualified_identifier { $$.v = $1.v as IdentifierChain } +| local_or_schema_qualifier period qualified_identifier { + $$.v = IdentifierChain{($1.v as Identifier).str() + '.' + + ($3.v as IdentifierChain).str()} + } + +local_or_schema_qualifier: + schema_name { $$.v = $1.v as Identifier } + +qualified_identifier: + identifier { $$.v = $1.v as IdentifierChain } + +column_name: + identifier { + $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! + } + +host_parameter_name: + colon identifier { + $$.v = GeneralValueSpecification(HostParameterName{ + ($2.v as IdentifierChain).identifier} + ) + } + +correlation_name: + identifier { + $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! + } + +sequence_generator_name: + schema_qualified_name { + $$.v = new_table_identifier(($1.v as IdentifierChain).identifier)! + } + +%% diff --git a/vsql/std_6_12_case_expression.y b/vsql/std_6_12_case_expression.y new file mode 100644 index 0000000..8254dfd --- /dev/null +++ b/vsql/std_6_12_case_expression.y @@ -0,0 +1,25 @@ +%% + +case_expression: + case_abbreviation { $$.v = $1.v as CaseExpression } + +case_abbreviation: + NULLIF left_paren value_expression comma value_expression right_paren { + $$.v = CaseExpression(CaseExpressionNullIf{ + $3.v as ValueExpression + $5.v as ValueExpression + }) + } +| COALESCE left_paren value_expression_list right_paren { + $$.v = CaseExpression(CaseExpressionCoalesce{$3.v as []ValueExpression}) + } + +// These are non-standard, just to simplify standard rules: + +value_expression_list: + value_expression { $$.v = [$1.v as ValueExpression] } +| value_expression_list comma value_expression { + $$.v = append_list($1.v as []ValueExpression, $3.v as ValueExpression) + } + +%% diff --git a/vsql/std_6_13_cast_specification.y b/vsql/std_6_13_cast_specification.y new file mode 100644 index 0000000..9e2c797 --- /dev/null +++ b/vsql/std_6_13_cast_specification.y @@ -0,0 +1,17 @@ +%% + +cast_specification: + CAST left_paren cast_operand AS cast_target right_paren { + $$.v = CastSpecification{$3.v as CastOperand, $5.v as Type} + } + +cast_operand: + value_expression { $$.v = CastOperand($1.v as ValueExpression) } +| implicitly_typed_value_specification { + $$.v = CastOperand($1.v as NullSpecification) + } + +cast_target: + data_type { $$.v = $1.v as Type } + +%% diff --git a/vsql/std_6_14_next_value_expression.y b/vsql/std_6_14_next_value_expression.y new file mode 100644 index 0000000..81189ef --- /dev/null +++ b/vsql/std_6_14_next_value_expression.y @@ -0,0 +1,10 @@ +%% + +next_value_expression: + NEXT VALUE FOR sequence_generator_name { + $$.v = NextValueExpression{ + name: $4.v as Identifier + } + } + +%% diff --git a/vsql/std_6_1_data_type.y b/vsql/std_6_1_data_type.y new file mode 100644 index 0000000..3f5084a --- /dev/null +++ b/vsql/std_6_1_data_type.y @@ -0,0 +1,121 @@ +%% + +data_type: + predefined_type { $$.v = $1.v as Type } + +predefined_type: + character_string_type { $$.v = $1.v as Type } +| numeric_type { $$.v = $1.v as Type } +| boolean_type { $$.v = $1.v as Type } +| datetime_type { $$.v = $1.v as Type } + +character_string_type: + CHARACTER { $$.v = new_type('CHARACTER', 1, 0) } +| CHARACTER left_paren character_length right_paren { + $$.v = new_type('CHARACTER', ($3.v as string).int(), 0) + } +| CHAR { $$.v = new_type('CHARACTER', 1, 0) } +| CHAR left_paren character_length right_paren { + $$.v = new_type('CHARACTER', ($3.v as string).int(), 0) + } +| CHARACTER VARYING left_paren character_length right_paren { + $$.v = new_type('CHARACTER VARYING', ($4.v as string).int(), 0) + } +| CHAR VARYING left_paren character_length right_paren { + $$.v = new_type('CHARACTER VARYING', ($4.v as string).int(), 0) + } +| VARCHAR left_paren character_length right_paren { + $$.v = new_type('CHARACTER VARYING', ($3.v as string).int(), 0) + } + +numeric_type: + exact_numeric_type { $$.v = $1.v as Type } +| approximate_numeric_type { $$.v = $1.v as Type } + +exact_numeric_type: + NUMERIC { $$.v = new_type('NUMERIC', 0, 0) } +| NUMERIC left_paren precision right_paren { + $$.v = new_type('NUMERIC', ($3.v as string).int(), 0) + } +| NUMERIC left_paren precision comma scale right_paren { + $$.v = new_type('NUMERIC', ($3.v as string).int(), ($5.v as string).i16()) + } +| DECIMAL { $$.v = new_type('DECIMAL', 0, 0) } +| DECIMAL left_paren precision right_paren { + $$.v = new_type('DECIMAL', ($3.v as string).int(), 0) + } +| DECIMAL left_paren precision comma scale right_paren { + $$.v = new_type('DECIMAL', ($3.v as string).int(), ($5.v as string).i16()) + } +| SMALLINT { $$.v = new_type('SMALLINT', 0, 0) } +| INTEGER { $$.v = new_type('INTEGER', 0, 0) } +| INT { $$.v = new_type('INTEGER', 0, 0) } +| BIGINT { $$.v = new_type('BIGINT', 0, 0) } + +approximate_numeric_type: + FLOAT { $$.v = new_type('FLOAT', 0, 0) } +| FLOAT left_paren precision right_paren { + $$.v = new_type('FLOAT', ($3.v as string).int(), 0) + } +| REAL { $$.v = new_type('REAL', 0, 0) } +| DOUBLE PRECISION { $$.v = new_type('DOUBLE PRECISION', 0, 0) } + +length: + unsigned_integer { $$.v = $1.v as string } + +character_length: + length { $$.v = $1.v as string } + +char_length_units: + CHARACTERS { $$.v = $1.v as string } +| OCTETS { $$.v = $1.v as string } + +precision: + unsigned_integer { $$.v = $1.v as string } + +scale: + unsigned_integer { $$.v = $1.v as string } + +boolean_type: + BOOLEAN { $$.v = new_type('BOOLEAN', 0, 0) } + +datetime_type: + DATE { $$.v = new_type('DATE', 0, 0) } +| TIME { $$.v = parse_time_prec_tz_type('0', false)! } +| TIME left_paren time_precision right_paren { + $$.v = parse_time_prec_tz_type($3.v as string, false)! + } +| TIME with_or_without_time_zone { + $$.v = parse_time_prec_tz_type('0', $2.v as bool)! + } +| TIME left_paren time_precision right_paren with_or_without_time_zone { + $$.v = parse_time_prec_tz_type($3.v as string, $5.v as bool)! + } +| TIMESTAMP { $$.v = parse_timestamp_prec_tz_type('0', false)! } +| TIMESTAMP left_paren timestamp_precision right_paren { + $$.v = parse_timestamp_prec_tz_type($3.v as string, false)! + } +| TIMESTAMP with_or_without_time_zone { + // ISO/IEC 9075-2:2016(E), 6.1, 36) If is not + // specified, then 6 is implicit. + $$.v = parse_timestamp_prec_tz_type('6', $2.v as bool)! +} +| TIMESTAMP left_paren timestamp_precision right_paren + with_or_without_time_zone { + $$.v = parse_timestamp_prec_tz_type($3.v as string, $5.v as bool)! + } + +with_or_without_time_zone: + WITH TIME ZONE { $$.v = true } +| WITHOUT TIME ZONE { $$.v = false } + +time_precision: + time_fractional_seconds_precision { $$.v = $1.v as string } + +timestamp_precision: + time_fractional_seconds_precision { $$.v = $1.v as string } + +time_fractional_seconds_precision: + unsigned_integer { $$.v = $1.v as string } + +%% diff --git a/vsql/std_6_28_value_expression.y b/vsql/std_6_28_value_expression.y new file mode 100644 index 0000000..de37342 --- /dev/null +++ b/vsql/std_6_28_value_expression.y @@ -0,0 +1,22 @@ +%% + +value_expression: + common_value_expression { + $$.v = ValueExpression($1.v as CommonValueExpression) + } +| boolean_value_expression { + $$.v = ValueExpression($1.v as BooleanValueExpression) + } + +common_value_expression: + numeric_value_expression { + $$.v = CommonValueExpression($1.v as NumericValueExpression) + } +| string_value_expression { + $$.v = CommonValueExpression($1.v as CharacterValueExpression) + } +| datetime_value_expression { + $$.v = CommonValueExpression($1.v as DatetimePrimary) + } + +%% diff --git a/vsql/std_6_29_numeric_value_expression.y b/vsql/std_6_29_numeric_value_expression.y new file mode 100644 index 0000000..d0ada0d --- /dev/null +++ b/vsql/std_6_29_numeric_value_expression.y @@ -0,0 +1,37 @@ +%% + +numeric_value_expression: + term { $$.v = NumericValueExpression{term: $1.v as Term} } +| numeric_value_expression plus_sign term { + n := $1.v as NumericValueExpression + $$.v = NumericValueExpression{&n, '+', $3.v as Term} + } +| numeric_value_expression minus_sign term { + n := $1.v as NumericValueExpression + $$.v = NumericValueExpression{&n, '-', $3.v as Term} + } + +term: + factor { $$.v = Term{factor: $1.v as NumericPrimary} } +| term asterisk factor { + t := $1.v as Term + $$.v = Term{&t, '*', $3.v as NumericPrimary} + } +| term solidus factor { + t := $1.v as Term + $$.v = Term{&t, '/', $3.v as NumericPrimary} + } + +factor: + numeric_primary { $$.v = $1.v as NumericPrimary } +| sign numeric_primary { + $$.v = parse_factor_2($1.v as string, $2.v as NumericPrimary)! + } + +numeric_primary: + value_expression_primary { + $$.v = NumericPrimary($1.v as ValueExpressionPrimary) + } +| numeric_value_function { $$.v = NumericPrimary($1.v as RoutineInvocation) } + +%% diff --git a/vsql/std_6_30_numeric_value_function.y b/vsql/std_6_30_numeric_value_function.y new file mode 100644 index 0000000..f61ca38 --- /dev/null +++ b/vsql/std_6_30_numeric_value_function.y @@ -0,0 +1,160 @@ +%% + +numeric_value_function: + position_expression { $$.v = $1.v as RoutineInvocation } +| length_expression { $$.v = $1.v as RoutineInvocation } +| absolute_value_expression { $$.v = $1.v as RoutineInvocation } +| modulus_expression { $$.v = $1.v as RoutineInvocation } +| trigonometric_function { $$.v = $1.v as RoutineInvocation } +| common_logarithm { $$.v = $1.v as RoutineInvocation } +| natural_logarithm { $$.v = $1.v as RoutineInvocation } +| exponential_function { $$.v = $1.v as RoutineInvocation } +| power_function { $$.v = $1.v as RoutineInvocation } +| square_root { $$.v = $1.v as RoutineInvocation } +| floor_function { $$.v = $1.v as RoutineInvocation } +| ceiling_function { $$.v = $1.v as RoutineInvocation } + +position_expression: + character_position_expression { $$.v = $1.v as RoutineInvocation } + +character_position_expression: + POSITION left_paren character_value_expression_1 IN + character_value_expression_2 right_paren { + $$.v = RoutineInvocation{'POSITION', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), + ValueExpression(CommonValueExpression($5.v as CharacterValueExpression)), + ]} + } + +character_value_expression_1: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +character_value_expression_2: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +length_expression: + char_length_expression { $$.v = $1.v as RoutineInvocation } +| octet_length_expression { $$.v = $1.v as RoutineInvocation } + +char_length_expression: + CHAR_LENGTH left_paren character_value_expression right_paren { + $$.v = RoutineInvocation{'CHAR_LENGTH', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), + ]} + } +| CHARACTER_LENGTH left_paren character_value_expression right_paren { + $$.v = RoutineInvocation{'CHAR_LENGTH', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), + ]} + } + +octet_length_expression: + OCTET_LENGTH left_paren string_value_expression right_paren { + $$.v = RoutineInvocation{'OCTET_LENGTH', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), + ]} + } + +absolute_value_expression: + ABS left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'ABS', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +modulus_expression: + MOD left_paren numeric_value_expression_dividend comma + numeric_value_expression_divisor right_paren { + $$.v = RoutineInvocation{'MOD', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ValueExpression(CommonValueExpression($5.v as NumericValueExpression)) + ]} + } + +numeric_value_expression_dividend: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +numeric_value_expression_divisor: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +trigonometric_function: + trigonometric_function_name left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{$1.v as string, [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)), + ]} + } + +trigonometric_function_name: + SIN { $$.v = $1.v as string } +| COS { $$.v = $1.v as string } +| TAN { $$.v = $1.v as string } +| SINH { $$.v = $1.v as string } +| COSH { $$.v = $1.v as string } +| TANH { $$.v = $1.v as string } +| ASIN { $$.v = $1.v as string } +| ACOS { $$.v = $1.v as string } +| ATAN { $$.v = $1.v as string } + +common_logarithm: + LOG10 left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'LOG10', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +natural_logarithm: + LN left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'LN', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +exponential_function: + EXP left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'EXP', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +power_function: + POWER left_paren numeric_value_expression_base comma + numeric_value_expression_exponent right_paren { + $$.v = RoutineInvocation{'POWER', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)), + ValueExpression(CommonValueExpression($5.v as NumericValueExpression)) + ]} + } + +numeric_value_expression_base: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +numeric_value_expression_exponent: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +square_root: + SQRT left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'SQRT', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +floor_function: + FLOOR left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'FLOOR', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +ceiling_function: + CEIL left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'CEILING', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } +| CEILING left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'CEILING', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +%% diff --git a/vsql/std_6_31_string_value_expression.y b/vsql/std_6_31_string_value_expression.y new file mode 100644 index 0000000..ed05cf6 --- /dev/null +++ b/vsql/std_6_31_string_value_expression.y @@ -0,0 +1,29 @@ +%% + +string_value_expression: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +character_value_expression: + concatenation { $$.v = CharacterValueExpression($1.v as Concatenation) } +| character_factor { $$.v = CharacterValueExpression($1.v as CharacterPrimary) } + +concatenation: + character_value_expression concatenation_operator character_factor { + $$.v = Concatenation{ + $1.v as CharacterValueExpression + $3.v as CharacterPrimary + } + } + +character_factor: + character_primary { $$.v = $1.v as CharacterPrimary } + +character_primary: + value_expression_primary { + $$.v = CharacterPrimary($1.v as ValueExpressionPrimary) + } +| string_value_function { + $$.v = CharacterPrimary($1.v as CharacterValueFunction) + } + +%% diff --git a/vsql/std_6_32_string_value_function.y b/vsql/std_6_32_string_value_function.y new file mode 100644 index 0000000..28104dc --- /dev/null +++ b/vsql/std_6_32_string_value_function.y @@ -0,0 +1,87 @@ +%% + +string_value_function: + character_value_function { $$.v = $1.v as CharacterValueFunction } + +character_value_function: + character_substring_function { + $$.v = CharacterValueFunction($1.v as CharacterSubstringFunction) + } +| fold { $$.v = CharacterValueFunction($1.v as RoutineInvocation) } +| trim_function { $$.v = CharacterValueFunction($1.v as TrimFunction) } + +character_substring_function: + SUBSTRING left_paren character_value_expression FROM start_position + right_paren { + $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, + $5.v as NumericValueExpression, none, 'CHARACTERS'} + } +| SUBSTRING left_paren character_value_expression FROM start_position FOR + string_length right_paren { + $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, + $5.v as NumericValueExpression, $7.v as NumericValueExpression, + 'CHARACTERS'} + } +| SUBSTRING left_paren character_value_expression FROM start_position USING + char_length_units right_paren { + $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, + $5.v as NumericValueExpression, none, $7.v as string} + } +| SUBSTRING left_paren character_value_expression FROM start_position FOR + string_length USING char_length_units right_paren { + $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, + $5.v as NumericValueExpression, $7.v as NumericValueExpression, + $9.v as string} + } + +fold: + UPPER left_paren character_value_expression right_paren { + $$.v = RoutineInvocation{'UPPER', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression))]} + } +| LOWER left_paren character_value_expression right_paren { + $$.v = RoutineInvocation{'LOWER', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression))]} + } + +trim_function: + TRIM left_paren trim_operands right_paren { $$.v = $3.v as TrimFunction } + +trim_operands: + trim_source { + space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) + $$.v = TrimFunction{'BOTH', space, $1.v as CharacterValueExpression} + } +| FROM trim_source { + space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) + $$.v = TrimFunction{'BOTH', space, $2.v as CharacterValueExpression} + } +| trim_specification FROM trim_source { + space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) + $$.v = TrimFunction{$1.v as string, space, $3.v as CharacterValueExpression} + } +| trim_character FROM trim_source { + $$.v = TrimFunction{'BOTH', $1.v as CharacterValueExpression, $3.v as CharacterValueExpression} + } +| trim_specification trim_character FROM trim_source { + $$.v = TrimFunction{$1.v as string, $2.v as CharacterValueExpression, $4.v as CharacterValueExpression} + } + +trim_source: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +trim_specification: + LEADING { $$.v = $1.v as string } +| TRAILING { $$.v = $1.v as string } +| BOTH { $$.v = $1.v as string } + +trim_character: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +start_position: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +string_length: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +%% diff --git a/vsql/std_6_35_datetime_value_expression.y b/vsql/std_6_35_datetime_value_expression.y new file mode 100644 index 0000000..122bf8f --- /dev/null +++ b/vsql/std_6_35_datetime_value_expression.y @@ -0,0 +1,14 @@ +%% + +datetime_value_expression: + datetime_term { $$.v = $1.v as DatetimePrimary } + +datetime_term: + datetime_factor { $$.v = $1.v as DatetimePrimary } + +datetime_factor: + datetime_primary { $$.v = $1.v as DatetimePrimary } + +// Note: datetime_primary is defined in grammar.y. See there for details. + +%% diff --git a/vsql/std_6_36_datetime_value_function.y b/vsql/std_6_36_datetime_value_function.y new file mode 100644 index 0000000..4877cd2 --- /dev/null +++ b/vsql/std_6_36_datetime_value_function.y @@ -0,0 +1,47 @@ +%% + +datetime_value_function: + current_date_value_function { + $$.v = DatetimeValueFunction($1.v as CurrentDate) + } +| current_time_value_function { + $$.v = DatetimeValueFunction($1.v as CurrentTime) + } +| current_timestamp_value_function { + $$.v = DatetimeValueFunction($1.v as CurrentTimestamp) + } +| current_local_time_value_function { + $$.v = DatetimeValueFunction($1.v as LocalTime) + } +| current_local_timestamp_value_function { + $$.v = DatetimeValueFunction($1.v as LocalTimestamp) + } + +current_date_value_function: + CURRENT_DATE { $$.v = CurrentDate{} } + +current_time_value_function: + CURRENT_TIME { $$.v = CurrentTime{default_time_precision} } +| CURRENT_TIME left_paren time_precision right_paren { + $$.v = CurrentTime{($3.v as string).int()} + } + +current_local_time_value_function: + LOCALTIME { $$.v = LocalTime{0} } +| LOCALTIME left_paren time_precision right_paren { + $$.v = LocalTime{($3.v as string).int()} + } + +current_timestamp_value_function: + CURRENT_TIMESTAMP { $$.v = CurrentTimestamp{default_timestamp_precision} } +| CURRENT_TIMESTAMP left_paren timestamp_precision right_paren { + $$.v = CurrentTimestamp{($3.v as string).int()} + } + +current_local_timestamp_value_function: + LOCALTIMESTAMP { $$.v = LocalTimestamp{6} } +| LOCALTIMESTAMP left_paren timestamp_precision right_paren { + $$.v = LocalTimestamp{($3.v as string).int()} + } + +%% diff --git a/vsql/std_6_39_boolean_value_expression.y b/vsql/std_6_39_boolean_value_expression.y new file mode 100644 index 0000000..a402a74 --- /dev/null +++ b/vsql/std_6_39_boolean_value_expression.y @@ -0,0 +1,90 @@ +%% + +boolean_value_expression: + boolean_term { $$.v = BooleanValueExpression{term: $1.v as BooleanTerm} } +| boolean_value_expression OR boolean_term { + expr := $1.v as BooleanValueExpression + $$.v = BooleanValueExpression{&expr, $3.v as BooleanTerm} + } + +boolean_term: + boolean_factor { $$.v = BooleanTerm{factor: $1.v as BooleanTest} } +| boolean_term AND boolean_factor { + term := $1.v as BooleanTerm + $$.v = BooleanTerm{&term, $3.v as BooleanTest} + } + +boolean_factor: + boolean_test { $$.v = $1.v as BooleanTest } +| NOT boolean_test { + b := $2.v as BooleanTest + $$.v = BooleanTest{b.expr, b.not, b.value, !b.inverse} + } + +boolean_test: + boolean_primary { $$.v = BooleanTest{expr: $1.v as BooleanPrimary} } +| boolean_primary IS_TRUE { + $$.v = BooleanTest{ + $1.v as BooleanPrimary + false + new_boolean_value(true) + false + } + } +| boolean_primary IS_FALSE { + $$.v = BooleanTest{ + $1.v as BooleanPrimary + false + new_boolean_value(false) + false + } + } +| boolean_primary IS_UNKNOWN { + $$.v = BooleanTest{ + $1.v as BooleanPrimary + false + new_unknown_value() + false + } + } +| boolean_primary IS_NOT_TRUE { + $$.v = BooleanTest{ + $1.v as BooleanPrimary + true + new_boolean_value(true) + false + } + } +| boolean_primary IS_NOT_FALSE { + $$.v = BooleanTest{ + $1.v as BooleanPrimary + true + new_boolean_value(false) + false + } + } +| boolean_primary IS_NOT_UNKNOWN { + $$.v = BooleanTest{ + $1.v as BooleanPrimary + true + new_unknown_value() + false + } + } + +boolean_primary: + predicate { $$.v = BooleanPrimary($1.v as Predicate) } +| boolean_predicand { $$.v = BooleanPrimary($1.v as BooleanPredicand) } + +boolean_predicand: + parenthesized_boolean_value_expression { + $$.v = BooleanPredicand($1.v as BooleanValueExpression) + } +| nonparenthesized_value_expression_primary { + $$.v = BooleanPredicand($1.v as NonparenthesizedValueExpressionPrimary) + } + +parenthesized_boolean_value_expression: + left_paren boolean_value_expression right_paren { $$.v = $2.v } + +%% diff --git a/vsql/std_6_3_value_expression_primary.y b/vsql/std_6_3_value_expression_primary.y new file mode 100644 index 0000000..7cbf768 --- /dev/null +++ b/vsql/std_6_3_value_expression_primary.y @@ -0,0 +1,39 @@ +%% + +value_expression_primary: + parenthesized_value_expression { + $$.v = ValueExpressionPrimary($1.v as ParenthesizedValueExpression) + } +| nonparenthesized_value_expression_primary { + $$.v = ValueExpressionPrimary($1.v as NonparenthesizedValueExpressionPrimary) + } + +parenthesized_value_expression: + left_paren value_expression right_paren { + $$.v = ParenthesizedValueExpression{$2.v as ValueExpression} + } + +nonparenthesized_value_expression_primary: + unsigned_value_specification { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as ValueSpecification) + } +| column_reference { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as Identifier) + } +| set_function_specification { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as AggregateFunction) + } +| routine_invocation { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as RoutineInvocation) + } +| case_expression { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as CaseExpression) + } +| cast_specification { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as CastSpecification) + } +| next_value_expression { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as NextValueExpression) + } + +%% diff --git a/vsql/std_6_4_value_specification_and_target_specification.y b/vsql/std_6_4_value_specification_and_target_specification.y new file mode 100644 index 0000000..54192f2 --- /dev/null +++ b/vsql/std_6_4_value_specification_and_target_specification.y @@ -0,0 +1,29 @@ +%% + +value_specification: + literal { $$.v = ValueSpecification($1.v as Value) } +| general_value_specification { + $$.v = ValueSpecification($1.v as GeneralValueSpecification) + } + +unsigned_value_specification: + unsigned_literal { $$.v = ValueSpecification($1.v as Value) } +| general_value_specification { + $$.v = ValueSpecification($1.v as GeneralValueSpecification) + } + +general_value_specification: + host_parameter_specification { $$.v = $1.v as GeneralValueSpecification } +| CURRENT_CATALOG { $$.v = GeneralValueSpecification(CurrentCatalog{}) } +| CURRENT_SCHEMA { $$.v = GeneralValueSpecification(CurrentSchema{}) } + +simple_value_specification: + literal { $$.v = ValueSpecification($1.v as Value) } +| host_parameter_name { + $$.v = ValueSpecification($1.v as GeneralValueSpecification) + } + +host_parameter_specification: + host_parameter_name { $$.v = $1.v as GeneralValueSpecification } + +%% diff --git a/vsql/std_6_5_contextually_typed_value_specification.y b/vsql/std_6_5_contextually_typed_value_specification.y new file mode 100644 index 0000000..5c125e2 --- /dev/null +++ b/vsql/std_6_5_contextually_typed_value_specification.y @@ -0,0 +1,12 @@ +%% + +contextually_typed_value_specification: + implicitly_typed_value_specification { $$.v = $1.v as NullSpecification } + +implicitly_typed_value_specification: + null_specification { $$.v = $1.v as NullSpecification } + +null_specification: + NULL { $$.v = NullSpecification{} } + +%% diff --git a/vsql/std_6_6_identifier_chain.y b/vsql/std_6_6_identifier_chain.y new file mode 100644 index 0000000..992b6b0 --- /dev/null +++ b/vsql/std_6_6_identifier_chain.y @@ -0,0 +1,14 @@ +%% + +identifier_chain: + identifier { $$.v = $1.v as IdentifierChain } +| identifier period identifier { + $$.v = IdentifierChain{ + ($1.v as IdentifierChain).identifier + '.' + ($3.v as IdentifierChain).identifier + } + } + +basic_identifier_chain: + identifier_chain { $$.v = $1.v as IdentifierChain } + +%% diff --git a/vsql/std_6_7_column_reference.y b/vsql/std_6_7_column_reference.y index ce632e4..906fe6f 100644 --- a/vsql/std_6_7_column_reference.y +++ b/vsql/std_6_7_column_reference.y @@ -5,4 +5,4 @@ column_reference: $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! } -%% +%% \ No newline at end of file diff --git a/vsql/std_6_9_set_function_specification.y b/vsql/std_6_9_set_function_specification.y new file mode 100644 index 0000000..4c9a25d --- /dev/null +++ b/vsql/std_6_9_set_function_specification.y @@ -0,0 +1,6 @@ +%% + +set_function_specification: + aggregate_function { $$.v = $1.v as AggregateFunction } + +%% diff --git a/vsql/std_7_10_joined_table.y b/vsql/std_7_10_joined_table.y new file mode 100644 index 0000000..974184f --- /dev/null +++ b/vsql/std_7_10_joined_table.y @@ -0,0 +1,21 @@ +%% + +joined_table: + qualified_join { $$.v = $1.v as QualifiedJoin } + +join_specification: + join_condition { $$.v = $1.v as BooleanValueExpression } + +join_condition: + ON search_condition { $$.v = $2.v } + +join_type: + INNER +| outer_join_type { $$.v = $1.v as string } +| outer_join_type OUTER { $$.v = $1.v as string } + +outer_join_type: + LEFT { $$.v = $1.v as string } +| RIGHT { $$.v = $1.v as string } + +%% diff --git a/vsql/std_7_12_where_clause.y b/vsql/std_7_12_where_clause.y new file mode 100644 index 0000000..df5df86 --- /dev/null +++ b/vsql/std_7_12_where_clause.y @@ -0,0 +1,6 @@ +%% + +where_clause: + WHERE search_condition { $$.v = $2.v as BooleanValueExpression } + +%% diff --git a/vsql/std_7_13_group_by_clause.y b/vsql/std_7_13_group_by_clause.y new file mode 100644 index 0000000..ec35862 --- /dev/null +++ b/vsql/std_7_13_group_by_clause.y @@ -0,0 +1,21 @@ +%% + +group_by_clause: + GROUP BY grouping_element_list { $$.v = $3.v } + +grouping_element_list: + grouping_element { $$.v = [$1.v as Identifier] } +| grouping_element_list comma grouping_element { + $$.v = append_list($1.v as []Identifier, $3.v as Identifier) + } + +grouping_element: + ordinary_grouping_set { $$.v = $1.v as Identifier } + +ordinary_grouping_set: + grouping_column_reference { $$.v = $1.v as Identifier } + +grouping_column_reference: + column_reference { $$.v = $1.v as Identifier } + +%% diff --git a/vsql/std_7_16_query_specification.y b/vsql/std_7_16_query_specification.y new file mode 100644 index 0000000..3d48c27 --- /dev/null +++ b/vsql/std_7_16_query_specification.y @@ -0,0 +1,50 @@ +%% + +query_specification: + SELECT select_list table_expression { + $$.v = QuerySpecification{ + exprs: $2.v as SelectList + table_expression: $3.v as TableExpression + } + } + +select_list: + asterisk { $$.v = SelectList(AsteriskExpr(true)) } +| select_sublist { $$.v = $1.v as SelectList } +| select_list comma select_sublist { + mut new_select_list := (($1.v as SelectList) as []DerivedColumn).clone() + new_select_list << (($3.v as SelectList) as []DerivedColumn)[0] + $$.v = SelectList(new_select_list) + } + +select_sublist: + derived_column { $$.v = SelectList([$1.v as DerivedColumn]) } +| qualified_asterisk { $$.v = SelectList($1.v as QualifiedAsteriskExpr) } + +// was: asterisked_identifier_chain period asterisk +qualified_asterisk: + asterisked_identifier_chain OPERATOR_PERIOD_ASTERISK { + $$.v = QualifiedAsteriskExpr{ + new_column_identifier(($1.v as IdentifierChain).identifier)! + } + } + +asterisked_identifier_chain: + asterisked_identifier { $$.v = $1.v as IdentifierChain } + +asterisked_identifier: + identifier { $$.v = $1.v as IdentifierChain } + +derived_column: + value_expression { + $$.v = DerivedColumn{$1.v as ValueExpression, Identifier{}} + } +| value_expression as_clause { + $$.v = DerivedColumn{$1.v as ValueExpression, $2.v as Identifier} + } + +as_clause: + AS column_name { $$.v = $2.v as Identifier } +| column_name { $$.v = $1.v as Identifier } + +%% diff --git a/vsql/std_7_17_query_expression.y b/vsql/std_7_17_query_expression.y new file mode 100644 index 0000000..45b442f --- /dev/null +++ b/vsql/std_7_17_query_expression.y @@ -0,0 +1,89 @@ +%% + +query_expression: + query_expression_body { $$.v = QueryExpression{body: $1.v as SimpleTable} } +| query_expression_body order_by_clause { + $$.v = QueryExpression{ + body: $1.v as SimpleTable + order: $2.v as []SortSpecification + } + } +| query_expression_body result_offset_clause { + $$.v = QueryExpression{ + body: $1.v as SimpleTable + offset: $2.v as ValueSpecification + } + } +| query_expression_body order_by_clause result_offset_clause { + $$.v = QueryExpression{ + body: $1.v as SimpleTable + offset: $3.v as ValueSpecification + order: $2.v as []SortSpecification + } + } +| query_expression_body fetch_first_clause { + $$.v = QueryExpression{ + body: $1.v as SimpleTable + fetch: $2.v as ValueSpecification + } + } +| query_expression_body order_by_clause fetch_first_clause { + $$.v = QueryExpression{ + body: $1.v as SimpleTable + fetch: $3.v as ValueSpecification + order: $2.v as []SortSpecification + } + } +| query_expression_body order_by_clause result_offset_clause + fetch_first_clause { + $$.v = QueryExpression{ + body: $1.v as SimpleTable + offset: $3.v as ValueSpecification + fetch: $4.v as ValueSpecification + order: $2.v as []SortSpecification + } + } +| query_expression_body result_offset_clause fetch_first_clause { + $$.v = QueryExpression{ + body: $1.v as SimpleTable + offset: $2.v as ValueSpecification + fetch: $3.v as ValueSpecification + } + } + +query_expression_body: + query_term { $$.v = $1.v as SimpleTable } + +query_term: + query_primary { $$.v = $1.v as SimpleTable } + +query_primary: + simple_table { $$.v = $1.v as SimpleTable } + +simple_table: + query_specification { $$.v = SimpleTable($1.v as QuerySpecification) } +| table_value_constructor { $$.v = $1.v as SimpleTable } + +order_by_clause: + ORDER BY sort_specification_list { $$.v = $3.v } + +result_offset_clause: + OFFSET offset_row_count row_or_rows { $$.v = $2.v } + +fetch_first_clause: + FETCH FIRST fetch_first_quantity row_or_rows ONLY { $$.v = $3.v } + +fetch_first_quantity: + fetch_first_row_count { $$.v = $1.v as ValueSpecification } + +offset_row_count: + simple_value_specification { $$.v = $1.v as ValueSpecification } + +fetch_first_row_count: + simple_value_specification { $$.v = $1.v as ValueSpecification } + +row_or_rows: + ROW +| ROWS + +%% diff --git a/vsql/std_7_19_subquery.y b/vsql/std_7_19_subquery.y new file mode 100644 index 0000000..5fc1be1 --- /dev/null +++ b/vsql/std_7_19_subquery.y @@ -0,0 +1,16 @@ +%% + +row_subquery: + subquery { $$.v = $1.v as QueryExpression } + +table_subquery: + subquery { $$.v = $1.v as TablePrimary } + +subquery: + left_paren query_expression right_paren { + $$.v = TablePrimary{ + body: $2.v as QueryExpression + } + } + +%% diff --git a/vsql/std_7_1_row_value_constructor.y b/vsql/std_7_1_row_value_constructor.y new file mode 100644 index 0000000..0edf728 --- /dev/null +++ b/vsql/std_7_1_row_value_constructor.y @@ -0,0 +1,75 @@ +%% + +row_value_constructor: + common_value_expression { + $$.v = RowValueConstructor($1.v as CommonValueExpression) + } +| boolean_value_expression { + $$.v = RowValueConstructor($1.v as BooleanValueExpression) + } +| explicit_row_value_constructor { + $$.v = RowValueConstructor($1.v as ExplicitRowValueConstructor) + } + +explicit_row_value_constructor: + ROW left_paren row_value_constructor_element_list right_paren { + $$.v = ExplicitRowValueConstructor(ExplicitRowValueConstructorRow{$3.v as []ValueExpression}) + } +| row_subquery { $$.v = ExplicitRowValueConstructor($1.v as QueryExpression) } + +row_value_constructor_element_list: + row_value_constructor_element { $$.v = [$1.v as ValueExpression] } +| row_value_constructor_element_list comma row_value_constructor_element { + $$.v = append_list($1.v as []ValueExpression, $3.v as ValueExpression) + } + +row_value_constructor_element: + value_expression { $$.v = $1.v as ValueExpression } + +contextually_typed_row_value_constructor: + common_value_expression { + $$.v = ContextuallyTypedRowValueConstructor($1.v as CommonValueExpression) + } +| boolean_value_expression { + $$.v = ContextuallyTypedRowValueConstructor($1.v as BooleanValueExpression) + } +| contextually_typed_value_specification { + $$.v = ContextuallyTypedRowValueConstructor($1.v as NullSpecification) + } +| left_paren contextually_typed_value_specification right_paren { + $$.v = ContextuallyTypedRowValueConstructor($2.v as NullSpecification) + } +| left_paren contextually_typed_row_value_constructor_element comma + contextually_typed_row_value_constructor_element_list right_paren { + $$.v = ContextuallyTypedRowValueConstructor(push_list( + $2.v as ContextuallyTypedRowValueConstructorElement, + $4.v as []ContextuallyTypedRowValueConstructorElement)) + } + +contextually_typed_row_value_constructor_element_list: + contextually_typed_row_value_constructor_element { + $$.v = [$1.v as ContextuallyTypedRowValueConstructorElement] + } +| contextually_typed_row_value_constructor_element_list comma + contextually_typed_row_value_constructor_element { + $$.v = append_list($1.v as []ContextuallyTypedRowValueConstructorElement, + $3.v as ContextuallyTypedRowValueConstructorElement) + } + +contextually_typed_row_value_constructor_element: + value_expression { + $$.v = ContextuallyTypedRowValueConstructorElement($1.v as ValueExpression) + } +| contextually_typed_value_specification { + $$.v = ContextuallyTypedRowValueConstructorElement($1.v as NullSpecification) + } + +row_value_constructor_predicand: + common_value_expression { + $$.v = RowValueConstructorPredicand($1.v as CommonValueExpression) + } +| boolean_predicand { + $$.v = RowValueConstructorPredicand($1.v as BooleanPredicand) + } + +%% diff --git a/vsql/std_7_2_row_value_expression.y b/vsql/std_7_2_row_value_expression.y new file mode 100644 index 0000000..e576126 --- /dev/null +++ b/vsql/std_7_2_row_value_expression.y @@ -0,0 +1,16 @@ +%% + +table_row_value_expression: + row_value_constructor { $$.v = $1.v as RowValueConstructor } + +contextually_typed_row_value_expression: + contextually_typed_row_value_constructor { + $$.v = $1.v as ContextuallyTypedRowValueConstructor + } + +row_value_predicand: + row_value_constructor_predicand { + $$.v = $1.v as RowValueConstructorPredicand + } + +%% diff --git a/vsql/std_7_3_table_value_constructor.y b/vsql/std_7_3_table_value_constructor.y new file mode 100644 index 0000000..265f83f --- /dev/null +++ b/vsql/std_7_3_table_value_constructor.y @@ -0,0 +1,30 @@ +%% + +table_value_constructor: + VALUES row_value_expression_list { + $$.v = SimpleTable($2.v as []RowValueConstructor) + } + +row_value_expression_list: + table_row_value_expression { $$.v = [$1.v as RowValueConstructor] } +| row_value_expression_list comma table_row_value_expression { + $$.v = append_list($1.v as []RowValueConstructor, + $3.v as RowValueConstructor) + } + +contextually_typed_table_value_constructor: + VALUES contextually_typed_row_value_expression_list { + $$.v = $2.v as []ContextuallyTypedRowValueConstructor + } + +contextually_typed_row_value_expression_list: + contextually_typed_row_value_expression { + $$.v = [$1.v as ContextuallyTypedRowValueConstructor] + } +| contextually_typed_row_value_expression_list comma + contextually_typed_row_value_expression { + $$.v = append_list($1.v as []ContextuallyTypedRowValueConstructor, + $3.v as ContextuallyTypedRowValueConstructor) + } + +%% diff --git a/vsql/std_7_4_table_expression.y b/vsql/std_7_4_table_expression.y new file mode 100644 index 0000000..21aab7f --- /dev/null +++ b/vsql/std_7_4_table_expression.y @@ -0,0 +1,25 @@ +%% + +table_expression: + from_clause { + $$.v = TableExpression{$1.v as TableReference, none, []Identifier{}} + } +| from_clause where_clause { + $$.v = TableExpression{ + $1.v as TableReference + $2.v as BooleanValueExpression + []Identifier{} + } + } +| from_clause group_by_clause { + $$.v = TableExpression{$1.v as TableReference, none, $2.v as []Identifier} + } +| from_clause where_clause group_by_clause { + $$.v = TableExpression{ + $1.v as TableReference + $2.v as BooleanValueExpression + $3.v as []Identifier + } + } + +%% \ No newline at end of file diff --git a/vsql/std_7_5_from_clause.y b/vsql/std_7_5_from_clause.y new file mode 100644 index 0000000..34d0020 --- /dev/null +++ b/vsql/std_7_5_from_clause.y @@ -0,0 +1,9 @@ +%% + +from_clause: + FROM table_reference_list { $$.v = $2.v as TableReference } + +table_reference_list: + table_reference { $$.v = $1.v as TableReference } + +%% diff --git a/vsql/std_7_6_table_reference.y b/vsql/std_7_6_table_reference.y new file mode 100644 index 0000000..24dc3b7 --- /dev/null +++ b/vsql/std_7_6_table_reference.y @@ -0,0 +1,84 @@ +%% + +table_reference: + table_factor { $$.v = TableReference($1.v as TablePrimary) } +| joined_table { $$.v = TableReference($1.v as QualifiedJoin) } + +qualified_join: + table_reference JOIN table_reference join_specification { + $$.v = QualifiedJoin{ + $1.v as TableReference + 'INNER' + $3.v as TableReference + $4.v as BooleanValueExpression + } + } +| table_reference join_type JOIN table_reference join_specification { + $$.v = QualifiedJoin{ + $1.v as TableReference + $2.v as string + $4.v as TableReference + $5.v as BooleanValueExpression + } + } + +table_factor: + table_primary { $$.v = $1.v as TablePrimary } + +table_primary: + table_or_query_name { + $$.v = TablePrimary{ + body: $1.v as Identifier + } + } +| derived_table { $$.v = $1.v as TablePrimary } +| derived_table correlation_or_recognition { + $$.v = TablePrimary{ + body: ($1.v as TablePrimary).body + correlation: $2.v as Correlation + } + } + +correlation_or_recognition: + correlation_name { + $$.v = Correlation{ + name: $1.v as Identifier + } + } +| AS correlation_name { + $$.v = Correlation{ + name: $2.v as Identifier + } + } +| correlation_name parenthesized_derived_column_list { + $$.v = Correlation{ + name: $1.v as Identifier + columns: $2.v as []Identifier + } + } +| AS correlation_name parenthesized_derived_column_list { + $$.v = Correlation{ + name: $2.v as Identifier + columns: $3.v as []Identifier + } + } + +derived_table: + table_subquery { $$.v = $1.v as TablePrimary } + +table_or_query_name: + table_name { $$.v = $1.v as Identifier } + +derived_column_list: + column_name_list { $$.v = $1.v as []Identifier } + +column_name_list: + column_name { $$.v = [$1.v as Identifier] } +| column_name_list comma column_name { + $$.v = append_list($1.v as []Identifier, $3.v as Identifier) + } + +parenthesized_derived_column_list: + left_paren derived_column_list right_paren { $$.v = $2.v } + +%% diff --git a/vsql/std_8_1_predicate.y b/vsql/std_8_1_predicate.y new file mode 100644 index 0000000..4f72ede --- /dev/null +++ b/vsql/std_8_1_predicate.y @@ -0,0 +1,10 @@ +%% + +predicate: + comparison_predicate { $$.v = Predicate($1.v as ComparisonPredicate) } +| between_predicate { $$.v = Predicate($1.v as BetweenPredicate) } +| like_predicate { $$.v = Predicate($1.v as CharacterLikePredicate) } +| similar_predicate { $$.v = Predicate($1.v as SimilarPredicate) } +| null_predicate { $$.v = Predicate($1.v as NullPredicate) } + +%% diff --git a/vsql/std_8_21_search_condition.y b/vsql/std_8_21_search_condition.y new file mode 100644 index 0000000..83a01f2 --- /dev/null +++ b/vsql/std_8_21_search_condition.y @@ -0,0 +1,6 @@ +%% + +search_condition: + boolean_value_expression { $$.v = $1.v as BooleanValueExpression } + +%% diff --git a/vsql/std_8_2_comparison_predicate.y b/vsql/std_8_2_comparison_predicate.y new file mode 100644 index 0000000..cfe4553 --- /dev/null +++ b/vsql/std_8_2_comparison_predicate.y @@ -0,0 +1,29 @@ +%% + +comparison_predicate: + row_value_predicand comparison_predicate_part_2 { + comp := $2.v as ComparisonPredicatePart2 + $$.v = ComparisonPredicate{ + $1.v as RowValueConstructorPredicand + comp.op + comp.expr + } + } + +comparison_predicate_part_2: + comp_op row_value_predicand { + $$.v = ComparisonPredicatePart2{ + $1.v as string + $2.v as RowValueConstructorPredicand + } + } + +comp_op: + equals_operator { $$.v = $1.v as string } +| not_equals_operator { $$.v = $1.v as string } +| less_than_operator { $$.v = $1.v as string } +| greater_than_operator { $$.v = $1.v as string } +| less_than_or_equals_operator { $$.v = $1.v as string } +| greater_than_or_equals_operator { $$.v = $1.v as string } + +%% diff --git a/vsql/std_8_3_between_predicate.y b/vsql/std_8_3_between_predicate.y new file mode 100644 index 0000000..ed9707e --- /dev/null +++ b/vsql/std_8_3_between_predicate.y @@ -0,0 +1,42 @@ +%% + +between_predicate: + row_value_predicand between_predicate_part_2 { + between := $2.v as BetweenPredicate + $$.v = BetweenPredicate{ + not: between.not + symmetric: between.symmetric + expr: $1.v as RowValueConstructorPredicand + left: between.left + right: between.right + } + } + +between_predicate_part_2: + between_predicate_part_1 row_value_predicand AND row_value_predicand { + $$.v = BetweenPredicate{ + not: !($1.v as bool) + symmetric: false + left: $2.v as RowValueConstructorPredicand + right: $4.v as RowValueConstructorPredicand + } + } +| between_predicate_part_1 is_symmetric row_value_predicand AND + row_value_predicand { + $$.v = BetweenPredicate{ + not: !($1.v as bool) + symmetric: $2.v as bool + left: $3.v as RowValueConstructorPredicand + right: $5.v as RowValueConstructorPredicand + } + } + +between_predicate_part_1: + BETWEEN { $$.v = true } +| NOT BETWEEN { $$.v = false } + +is_symmetric: + SYMMETRIC { $$.v = true } +| ASYMMETRIC { $$.v = false } + +%% diff --git a/vsql/std_8_5_like_predicate.y b/vsql/std_8_5_like_predicate.y new file mode 100644 index 0000000..9077f9c --- /dev/null +++ b/vsql/std_8_5_like_predicate.y @@ -0,0 +1,27 @@ +%% + +like_predicate: + character_like_predicate { $$.v = $1.v as CharacterLikePredicate } + +character_like_predicate: + row_value_predicand character_like_predicate_part_2 { + like := $2.v as CharacterLikePredicate + $$.v = CharacterLikePredicate{ + $1.v as RowValueConstructorPredicand + like.right + like.not + } + } + +character_like_predicate_part_2: + LIKE character_pattern { + $$.v = CharacterLikePredicate{none, $2.v as CharacterValueExpression, false} + } +| NOT LIKE character_pattern { + $$.v = CharacterLikePredicate{none, $3.v as CharacterValueExpression, true} + } + +character_pattern: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +%% diff --git a/vsql/std_8_6_similar_predicate.y b/vsql/std_8_6_similar_predicate.y new file mode 100644 index 0000000..92d92e0 --- /dev/null +++ b/vsql/std_8_6_similar_predicate.y @@ -0,0 +1,20 @@ +%% + +similar_predicate: + row_value_predicand similar_predicate_part_2 { + like := $2.v as SimilarPredicate + $$.v = SimilarPredicate{$1.v as RowValueConstructorPredicand, like.right, like.not} + } + +similar_predicate_part_2: + SIMILAR TO similar_pattern { + $$.v = SimilarPredicate{none, $3.v as CharacterValueExpression, false} + } +| NOT SIMILAR TO similar_pattern { + $$.v = SimilarPredicate{none, $4.v as CharacterValueExpression, true} + } + +similar_pattern: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +%% diff --git a/vsql/std_8_8_null_predicate.y b/vsql/std_8_8_null_predicate.y new file mode 100644 index 0000000..65f123a --- /dev/null +++ b/vsql/std_8_8_null_predicate.y @@ -0,0 +1,12 @@ +%% + +null_predicate: + row_value_predicand null_predicate_part_2 { + $$.v = NullPredicate{$1.v as RowValueConstructorPredicand, !($2.v as bool)} + } + +null_predicate_part_2: + IS NULL { $$.v = true } +| IS NOT NULL { $$.v = false } + +%% diff --git a/vsql/y.y b/vsql/y.y index e80fbe2..863195d 100644 --- a/vsql/y.y +++ b/vsql/y.y @@ -667,145 +667,30 @@ import math // literals %token LITERAL_IDENTIFIER LITERAL_STRING LITERAL_NUMBER; -%token E +%token E; // pseudo keywords %token IS_TRUE IS_FALSE IS_UNKNOWN IS_NOT_TRUE IS_NOT_FALSE IS_NOT_UNKNOWN; %start start; - - %% - - // This is a special case that uses `yyrcvr.lval` to make sure the parser // captures the final result. start: preparable_statement { yyrcvr.lval.v = $1.v as Stmt } -// 7.3
- -table_value_constructor: - VALUES row_value_expression_list { - $$.v = SimpleTable($2.v as []RowValueConstructor) - } - -row_value_expression_list: - table_row_value_expression { $$.v = [$1.v as RowValueConstructor] } -| row_value_expression_list comma table_row_value_expression { - $$.v = append_list($1.v as []RowValueConstructor, - $3.v as RowValueConstructor) - } - -contextually_typed_table_value_constructor: - VALUES contextually_typed_row_value_expression_list { - $$.v = $2.v as []ContextuallyTypedRowValueConstructor - } - -contextually_typed_row_value_expression_list: - contextually_typed_row_value_expression { - $$.v = [$1.v as ContextuallyTypedRowValueConstructor] - } -| contextually_typed_row_value_expression_list comma - contextually_typed_row_value_expression { - $$.v = append_list($1.v as []ContextuallyTypedRowValueConstructor, - $3.v as ContextuallyTypedRowValueConstructor) - } - -// 11.74 - -drop_sequence_generator_statement: - DROP SEQUENCE sequence_generator_name { - $$.v = Stmt(DropSequenceGeneratorStatement{$3.v as Identifier}) - } - -// 14.8 - -target_table: - table_name { $$.v = $1.v as Identifier } - -// 20.7 - -preparable_statement: - preparable_sql_data_statement { $$.v = $1.v as Stmt } -| preparable_sql_schema_statement { $$.v = $1.v as Stmt } -| preparable_sql_transaction_statement { $$.v = $1.v as Stmt } -| preparable_sql_session_statement { $$.v = $1.v as Stmt } - -preparable_sql_data_statement: - delete_statement_searched { $$.v = $1.v as Stmt } -| insert_statement { $$.v = $1.v as Stmt } -| dynamic_select_statement { $$.v = $1.v as Stmt } -| update_statement_searched { $$.v = $1.v as Stmt } - -preparable_sql_schema_statement: - sql_schema_statement { $$.v = $1.v as Stmt } - -preparable_sql_transaction_statement: - sql_transaction_statement { $$.v = $1.v as Stmt } - -preparable_sql_session_statement: - sql_session_statement { $$.v = $1.v as Stmt } - -// 6.12 - -case_expression: - case_abbreviation { $$.v = $1.v as CaseExpression } - -case_abbreviation: - NULLIF left_paren value_expression comma value_expression right_paren { - $$.v = CaseExpression(CaseExpressionNullIf{ - $3.v as ValueExpression - $5.v as ValueExpression - }) - } -| COALESCE left_paren value_expression_list right_paren { - $$.v = CaseExpression(CaseExpressionCoalesce{$3.v as []ValueExpression}) - } - -value_expression_list: - value_expression { $$.v = [$1.v as ValueExpression] } -| value_expression_list comma value_expression { - $$.v = append_list($1.v as []ValueExpression, $3.v as ValueExpression) - } - -// 11.73 - -alter_sequence_generator_statement: - ALTER SEQUENCE sequence_generator_name alter_sequence_generator_options { - $$.v = AlterSequenceGeneratorStatement{ - name: $3.v as Identifier - options: $4.v as []SequenceGeneratorOption - } - } - -alter_sequence_generator_options: - alter_sequence_generator_option { $$.v = [$1.v as SequenceGeneratorOption] } -| alter_sequence_generator_options alter_sequence_generator_option { - $$.v = append_list($1.v as []SequenceGeneratorOption, - $2.v as SequenceGeneratorOption) - } - -alter_sequence_generator_option: - alter_sequence_generator_restart_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorRestartOption) +// This is from 6.35. I have no idea why this needs to be placed higher than +// other rules, but without doing this it will report that "datetime_primary" +// cannot be reduced. +datetime_primary: + value_expression_primary { + $$.v = DatetimePrimary($1.v as ValueExpressionPrimary) } -| basic_sequence_generator_option { $$.v = $1.v as SequenceGeneratorOption } - -alter_sequence_generator_restart_option: - RESTART { $$.v = SequenceGeneratorRestartOption{} } -| RESTART WITH sequence_generator_restart_value { - $$.v = SequenceGeneratorRestartOption{ - restart_value: $3.v as Value - } +| datetime_value_function { + $$.v = DatetimePrimary($1.v as DatetimeValueFunction) } -sequence_generator_restart_value: - signed_numeric_literal { $$.v = $1.v as Value } -commit_statement: - COMMIT { $$.v = Stmt(CommitStatement{}) } -| COMMIT WORK { $$.v = Stmt(CommitStatement{}) } sort_specification_list: sort_specification { $$.v = [$1.v as SortSpecification] } @@ -826,59 +711,81 @@ ordering_specification: ASC { $$.v = true } | DESC { $$.v = false } -row_subquery: - subquery { $$.v = $1.v as QueryExpression } -table_subquery: - subquery { $$.v = $1.v as TablePrimary } -subquery: - left_paren query_expression right_paren { - $$.v = TablePrimary{ - body: $2.v as QueryExpression - } +routine_invocation: + routine_name sql_argument_list { + $$.v = RoutineInvocation{($1.v as Identifier).entity_name, $2.v as []ValueExpression} } -set_clause_list: - set_clause { $$.v = $1.v as map[string]UpdateSource } -| set_clause_list comma set_clause { - $$.v = merge_maps($1.v as map[string]UpdateSource, - $3.v as map[string]UpdateSource) +routine_name: + qualified_identifier { + $$.v = new_function_identifier(($1.v as IdentifierChain).identifier)! } -set_clause: - set_target equals_operator update_source { - $$.v = { - ($1.v as Identifier).str(): $3.v as UpdateSource - } +sql_argument_list: + left_paren right_paren { $$.v = []ValueExpression{} } +| left_paren sql_argument right_paren { $$.v = [$2.v as ValueExpression] } +| left_paren sql_argument_list comma sql_argument right_paren { + $$.v = append_list($2.v as []ValueExpression, $4.v as ValueExpression) } -set_target: - update_target { $$.v = $1.v as Identifier } +sql_argument: + value_expression { $$.v = $1.v as ValueExpression } -update_target: - object_column { $$.v = $1.v as Identifier } -update_source: - value_expression { $$.v = UpdateSource($1.v as ValueExpression) } -| contextually_typed_value_specification { - $$.v = UpdateSource($1.v as NullSpecification) + +// was: COUNT left_paren asterisk right_paren +aggregate_function: + COUNT OPERATOR_LEFT_PAREN_ASTERISK right_paren { + $$.v = AggregateFunction(AggregateFunctionCount{}) } +| general_set_function { $$.v = $1.v as AggregateFunction } -object_column: - column_name { $$.v = $1.v as Identifier } +general_set_function: + set_function_type left_paren value_expression right_paren { + $$.v = AggregateFunction(RoutineInvocation{ + $1.v as string, [$3.v as ValueExpression]}) + } -delete_statement_searched: - DELETE FROM target_table { - $$.v = Stmt(DeleteStatementSearched{$3.v as Identifier, none}) +set_function_type: + computational_operation { $$.v = $1.v as string } + +computational_operation: + AVG { $$.v = $1.v as string } +| MAX { $$.v = $1.v as string } +| MIN { $$.v = $1.v as string } +| SUM { $$.v = $1.v as string } +| COUNT { $$.v = $1.v as string } + + + +schema_definition: + CREATE SCHEMA schema_name_clause { + $$.v = Stmt(SchemaDefinition{$3.v as Identifier}) } -| DELETE FROM target_table WHERE search_condition { - $$.v = Stmt(DeleteStatementSearched{ - $3.v as Identifier - $5.v as BooleanValueExpression - }) + +schema_name_clause: + schema_name { $$.v = $1.v as Identifier } + + + +drop_schema_statement: + DROP SCHEMA schema_name drop_behavior { + $$.v = Stmt(DropSchemaStatement{$3.v as Identifier, $4.v as string}) } +drop_behavior: + CASCADE { $$.v = $1.v as string } +| RESTRICT { $$.v = $1.v as string } + + + +drop_table_statement: + DROP TABLE table_name { $$.v = Stmt(DropTableStatement{$3.v as Identifier}) } + + + table_definition: CREATE TABLE table_name table_contents_source { $$.v = Stmt(TableDefinition{$3.v as Identifier, $4.v as []TableElement}) @@ -900,467 +807,395 @@ table_elements: $$.v = append_list($1.v as []TableElement, $3.v as TableElement) } -dynamic_select_statement: - cursor_specification { $$.v = $1.v as Stmt } -schema_definition: - CREATE SCHEMA schema_name_clause { - $$.v = Stmt(SchemaDefinition{$3.v as Identifier}) + +column_definition: + column_name data_type_or_domain_name { + $$.v = TableElement(Column{$1.v as Identifier, $2.v as Type, false}) + } +| column_name data_type_or_domain_name column_constraint_definition { + $$.v = TableElement(Column{$1.v as Identifier, $2.v as Type, $3.v as bool}) } -schema_name_clause: - schema_name { $$.v = $1.v as Identifier } +data_type_or_domain_name: + data_type { $$.v = $1.v as Type } -cursor_specification: - query_expression { $$.v = Stmt($1.v as QueryExpression) } +column_constraint_definition: + column_constraint { $$.v = $1.v as bool } -datetime_value_expression: - datetime_term { $$.v = $1.v as DatetimePrimary } +column_constraint: + NOT NULL { $$.v = true } -datetime_term: - datetime_factor { $$.v = $1.v as DatetimePrimary } -datetime_factor: - datetime_primary { $$.v = $1.v as DatetimePrimary } -datetime_primary: - value_expression_primary { - $$.v = DatetimePrimary($1.v as ValueExpressionPrimary) - } -| datetime_value_function { - $$.v = DatetimePrimary($1.v as DatetimeValueFunction) - } +table_constraint_definition: + table_constraint { $$.v = $1.v as TableElement } -update_statement_searched: - UPDATE target_table SET set_clause_list { - $$.v = Stmt(UpdateStatementSearched{$2.v as Identifier, - $4.v as map[string]UpdateSource, none}) - } -| UPDATE target_table SET set_clause_list WHERE search_condition { - $$.v = Stmt(UpdateStatementSearched{$2.v as Identifier, - $4.v as map[string]UpdateSource, $6.v as BooleanValueExpression}) +table_constraint: + unique_constraint_definition { + $$.v = TableElement($1.v as UniqueConstraintDefinition) } -identifier_chain: - identifier { $$.v = $1.v as IdentifierChain } -| identifier period identifier { - $$.v = IdentifierChain{ - ($1.v as IdentifierChain).identifier + '.' + ($3.v as IdentifierChain).identifier + + +sequence_generator_definition: + CREATE SEQUENCE sequence_generator_name { + $$.v = SequenceGeneratorDefinition{ + name: $3.v as Identifier + } + } +| CREATE SEQUENCE sequence_generator_name sequence_generator_options { + $$.v = SequenceGeneratorDefinition{ + name: $3.v as Identifier + options: $4.v as []SequenceGeneratorOption } } -basic_identifier_chain: - identifier_chain { $$.v = $1.v as IdentifierChain } - -cast_specification: - CAST left_paren cast_operand AS cast_target right_paren { - $$.v = CastSpecification{$3.v as CastOperand, $5.v as Type} +sequence_generator_options: + sequence_generator_option { $$.v = $1.v as []SequenceGeneratorOption } +| sequence_generator_options sequence_generator_option { + $$.v = $1.v as []SequenceGeneratorOption } -cast_operand: - value_expression { $$.v = CastOperand($1.v as ValueExpression) } -| implicitly_typed_value_specification { - $$.v = CastOperand($1.v as NullSpecification) +sequence_generator_option: + common_sequence_generator_options { $$.v = $1.v as []SequenceGeneratorOption } + +common_sequence_generator_options: + common_sequence_generator_option { $$.v = [$1.v as SequenceGeneratorOption] } +| common_sequence_generator_options common_sequence_generator_option { + $$.v = append_list($1.v as []SequenceGeneratorOption, + $2.v as SequenceGeneratorOption) } -cast_target: - data_type { $$.v = $1.v as Type } +common_sequence_generator_option: + sequence_generator_start_with_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorStartWithOption) + } +| basic_sequence_generator_option { $$.v = $1.v as SequenceGeneratorOption } -rollback_statement: - ROLLBACK { $$.v = Stmt(RollbackStatement{}) } -| ROLLBACK WORK { $$.v = Stmt(RollbackStatement{}) } +basic_sequence_generator_option: + sequence_generator_increment_by_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorIncrementByOption) + } +| sequence_generator_maxvalue_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorMaxvalueOption) + } +| sequence_generator_minvalue_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorMinvalueOption) + } +| sequence_generator_cycle_option { + $$.v = SequenceGeneratorOption(SequenceGeneratorCycleOption{$1.v as bool}) + } -next_value_expression: - NEXT VALUE FOR sequence_generator_name { - $$.v = NextValueExpression{ - name: $4.v as Identifier +sequence_generator_start_with_option: + START WITH sequence_generator_start_value { + $$.v = SequenceGeneratorStartWithOption{ + start_value: $3.v as Value } } -where_clause: - WHERE search_condition { $$.v = $2.v as BooleanValueExpression } - -literal: +sequence_generator_start_value: signed_numeric_literal { $$.v = $1.v as Value } -| general_literal { $$.v = $1.v as Value } - -unsigned_literal: - unsigned_numeric_literal { $$.v = $1.v as Value } -| general_literal { $$.v = $1.v as Value } -general_literal: - character_string_literal { $$.v = $1.v as Value } -| datetime_literal { $$.v = $1.v as Value } -| boolean_literal { $$.v = $1.v as Value } +sequence_generator_increment_by_option: + INCREMENT BY sequence_generator_increment { + $$.v = SequenceGeneratorIncrementByOption{ + increment_by: $3.v as Value + } + } -character_string_literal: - LITERAL_STRING { $$.v = $1.v as Value } +sequence_generator_increment: + signed_numeric_literal { $$.v = $1.v as Value } -signed_numeric_literal: - unsigned_numeric_literal { $$.v = $1.v as Value } -| sign unsigned_numeric_literal { - $$.v = numeric_literal($1.v as string + ($2.v as Value).str())! +sequence_generator_maxvalue_option: + MAXVALUE sequence_generator_max_value { + $$.v = SequenceGeneratorMaxvalueOption{ + max_value: $2.v as Value + } } +| NO MAXVALUE { $$.v = SequenceGeneratorMaxvalueOption{} } -unsigned_numeric_literal: - exact_numeric_literal { $$.v = $1.v as Value } -| approximate_numeric_literal { $$.v = $1.v as Value } +sequence_generator_max_value: + signed_numeric_literal { $$.v = $1.v as Value } -exact_numeric_literal: - unsigned_integer { $$.v = numeric_literal($1.v as string)! } -| unsigned_integer period { $$.v = numeric_literal(($1.v as string) + '.')! } -| unsigned_integer period unsigned_integer { - $$.v = numeric_literal(($1.v as string) + '.' + ($3.v as string))! +sequence_generator_minvalue_option: + MINVALUE sequence_generator_min_value { + $$.v = SequenceGeneratorMinvalueOption{ + min_value: $2.v as Value + } } -| period unsigned_integer { $$.v = numeric_literal('0.' + ($2.v as string))! } +| NO MINVALUE { $$.v = SequenceGeneratorMinvalueOption{} } -sign: - plus_sign { $$.v = $1.v as string } -| minus_sign { $$.v = $1.v as string } +sequence_generator_min_value: + signed_numeric_literal { $$.v = $1.v as Value } -approximate_numeric_literal: - mantissa E exponent { - $$.v = new_double_precision_value( - ($1.v as Value).as_f64()! * math.pow(10, ($3.v as Value).as_f64()!)) - } +sequence_generator_cycle_option: + CYCLE { $$.v = true } +| NO CYCLE { $$.v = false } -mantissa: - exact_numeric_literal { $$.v = $1.v as Value } -exponent: - signed_integer { $$.v = $1.v as Value } -signed_integer: - unsigned_integer { $$.v = new_numeric_value($1.v as string) } -| sign unsigned_integer { - $$.v = if $1.v as string == '-' { - new_numeric_value('-' + ($2.v as string)) - } else { - new_numeric_value($2.v as string) +alter_sequence_generator_statement: + ALTER SEQUENCE sequence_generator_name alter_sequence_generator_options { + $$.v = AlterSequenceGeneratorStatement{ + name: $3.v as Identifier + options: $4.v as []SequenceGeneratorOption } } -unsigned_integer: - LITERAL_NUMBER { $$.v = $1.v as string } +alter_sequence_generator_options: + alter_sequence_generator_option { $$.v = [$1.v as SequenceGeneratorOption] } +| alter_sequence_generator_options alter_sequence_generator_option { + $$.v = append_list($1.v as []SequenceGeneratorOption, + $2.v as SequenceGeneratorOption) + } -datetime_literal: - date_literal { $$.v = $1.v as Value } -| time_literal { $$.v = $1.v as Value } -| timestamp_literal { $$.v = $1.v as Value } +alter_sequence_generator_option: + alter_sequence_generator_restart_option { + $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorRestartOption) + } +| basic_sequence_generator_option { $$.v = $1.v as SequenceGeneratorOption } -date_literal: - DATE date_string { $$.v = new_date_value(($2.v as Value).string_value())! } +alter_sequence_generator_restart_option: + RESTART { $$.v = SequenceGeneratorRestartOption{} } +| RESTART WITH sequence_generator_restart_value { + $$.v = SequenceGeneratorRestartOption{ + restart_value: $3.v as Value + } + } -time_literal: - TIME time_string { $$.v = new_time_value(($2.v as Value).string_value())! } +sequence_generator_restart_value: + signed_numeric_literal { $$.v = $1.v as Value } -timestamp_literal: - TIMESTAMP timestamp_string { - $$.v = new_timestamp_value(($2.v as Value).string_value())! + + +drop_sequence_generator_statement: + DROP SEQUENCE sequence_generator_name { + $$.v = Stmt(DropSequenceGeneratorStatement{$3.v as Identifier}) } -date_string: - LITERAL_STRING { $$.v = $1.v as Value } -time_string: - LITERAL_STRING { $$.v = $1.v as Value } -timestamp_string: - LITERAL_STRING { $$.v = $1.v as Value } +unique_constraint_definition: + unique_specification left_paren unique_column_list right_paren { + $$.v = UniqueConstraintDefinition{$3.v as []Identifier} + } -boolean_literal: - TRUE { $$.v = new_boolean_value(true) } -| FALSE { $$.v = new_boolean_value(false) } -| UNKNOWN { $$.v = new_unknown_value() } +unique_specification: + PRIMARY KEY -contextually_typed_value_specification: - implicitly_typed_value_specification { $$.v = $1.v as NullSpecification } +unique_column_list: + column_name_list { $$.v = $1.v as []Identifier } -implicitly_typed_value_specification: - null_specification { $$.v = $1.v as NullSpecification } -null_specification: - NULL { $$.v = NullSpecification{} } -from_clause: - FROM table_reference_list { $$.v = $2.v as TableReference } +sql_schema_statement: + sql_schema_definition_statement { $$.v = $1.v as Stmt } +| sql_schema_manipulation_statement { $$.v = $1.v as Stmt } -table_reference_list: - table_reference { $$.v = $1.v as TableReference } +sql_schema_definition_statement: + schema_definition { $$.v = $1.v as Stmt } +| table_definition { $$.v = $1.v as Stmt } +| sequence_generator_definition { $$.v = Stmt($1.v as SequenceGeneratorDefinition) } -between_predicate: - row_value_predicand between_predicate_part_2 { - between := $2.v as BetweenPredicate - $$.v = BetweenPredicate{ - not: between.not - symmetric: between.symmetric - expr: $1.v as RowValueConstructorPredicand - left: between.left - right: between.right - } - } +sql_schema_manipulation_statement: + drop_schema_statement { $$.v = $1.v as Stmt } +| drop_table_statement { $$.v = $1.v as Stmt } +| alter_sequence_generator_statement { $$.v = Stmt($1.v as AlterSequenceGeneratorStatement) } +| drop_sequence_generator_statement { $$.v = $1.v as Stmt } -between_predicate_part_2: - between_predicate_part_1 row_value_predicand AND row_value_predicand { - $$.v = BetweenPredicate{ - not: !($1.v as bool) - symmetric: false - left: $2.v as RowValueConstructorPredicand - right: $4.v as RowValueConstructorPredicand - } - } -| between_predicate_part_1 is_symmetric row_value_predicand AND - row_value_predicand { - $$.v = BetweenPredicate{ - not: !($1.v as bool) - symmetric: $2.v as bool - left: $3.v as RowValueConstructorPredicand - right: $5.v as RowValueConstructorPredicand - } - } - -between_predicate_part_1: - BETWEEN { $$.v = true } -| NOT BETWEEN { $$.v = false } +sql_transaction_statement: + start_transaction_statement { $$.v = $1.v as Stmt } +| commit_statement { $$.v = $1.v as Stmt } +| rollback_statement { $$.v = $1.v as Stmt } -is_symmetric: - SYMMETRIC { $$.v = true } -| ASYMMETRIC { $$.v = false } +sql_session_statement: + set_schema_statement { $$.v = Stmt($1.v as SetSchemaStatement) } +| set_catalog_statement { $$.v = $1.v as Stmt } -identifier: - actual_identifier { $$.v = $1.v as IdentifierChain } -actual_identifier: - regular_identifier { $$.v = $1.v as IdentifierChain } -table_name: - local_or_schema_qualified_name { - $$.v = new_table_identifier(($1.v as IdentifierChain).identifier)! +insert_statement: + INSERT INTO insertion_target insert_columns_and_source { + stmt := $4.v as InsertStatement + $$.v = Stmt(InsertStatement{$3.v as Identifier, stmt.columns, stmt.values}) } -schema_name: - catalog_name period unqualified_schema_name { - $$.v = new_schema_identifier(($1.v as IdentifierChain).str() + '.' + - ($3.v as Identifier).str())! - } -| unqualified_schema_name { $$.v = $1.v as Identifier } +insertion_target: + table_name { $$.v = $1.v as Identifier } -unqualified_schema_name: - identifier { - $$.v = new_schema_identifier(($1.v as IdentifierChain).identifier)! +insert_columns_and_source: + from_constructor { $$.v = $1.v as InsertStatement } + +from_constructor: + left_paren insert_column_list right_paren + contextually_typed_table_value_constructor { + $$.v = InsertStatement{ + columns: $2.v as []Identifier + values: $4.v as []ContextuallyTypedRowValueConstructor + } } -catalog_name: - identifier { $$.v = $1.v as IdentifierChain } +insert_column_list: + column_name_list { $$.v = $1.v as []Identifier } -schema_qualified_name: - qualified_identifier { $$.v = $1.v as IdentifierChain } -| schema_name period qualified_identifier { - $$.v = IdentifierChain{($1.v as Identifier).schema_name + '.' + - ($3.v as IdentifierChain).str()} - } -local_or_schema_qualified_name: - qualified_identifier { $$.v = $1.v as IdentifierChain } -| local_or_schema_qualifier period qualified_identifier { - $$.v = IdentifierChain{($1.v as Identifier).str() + '.' + - ($3.v as IdentifierChain).str()} + +update_statement_searched: + UPDATE target_table SET set_clause_list { + $$.v = Stmt(UpdateStatementSearched{$2.v as Identifier, + $4.v as map[string]UpdateSource, none}) + } +| UPDATE target_table SET set_clause_list WHERE search_condition { + $$.v = Stmt(UpdateStatementSearched{$2.v as Identifier, + $4.v as map[string]UpdateSource, $6.v as BooleanValueExpression}) } -local_or_schema_qualifier: - schema_name { $$.v = $1.v as Identifier } -qualified_identifier: - identifier { $$.v = $1.v as IdentifierChain } -column_name: - identifier { - $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! +set_clause_list: + set_clause { $$.v = $1.v as map[string]UpdateSource } +| set_clause_list comma set_clause { + $$.v = merge_maps($1.v as map[string]UpdateSource, + $3.v as map[string]UpdateSource) } -host_parameter_name: - colon identifier { - $$.v = GeneralValueSpecification(HostParameterName{ - ($2.v as IdentifierChain).identifier} - ) +set_clause: + set_target equals_operator update_source { + $$.v = { + ($1.v as Identifier).str(): $3.v as UpdateSource + } } -correlation_name: - identifier { - $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! - } +set_target: + update_target { $$.v = $1.v as Identifier } -sequence_generator_name: - schema_qualified_name { - $$.v = new_table_identifier(($1.v as IdentifierChain).identifier)! - } +update_target: + object_column { $$.v = $1.v as Identifier } -drop_schema_statement: - DROP SCHEMA schema_name drop_behavior { - $$.v = Stmt(DropSchemaStatement{$3.v as Identifier, $4.v as string}) +update_source: + value_expression { $$.v = UpdateSource($1.v as ValueExpression) } +| contextually_typed_value_specification { + $$.v = UpdateSource($1.v as NullSpecification) } -drop_behavior: - CASCADE { $$.v = $1.v as string } -| RESTRICT { $$.v = $1.v as string } +object_column: + column_name { $$.v = $1.v as Identifier } -numeric_value_function: - position_expression { $$.v = $1.v as RoutineInvocation } -| length_expression { $$.v = $1.v as RoutineInvocation } -| absolute_value_expression { $$.v = $1.v as RoutineInvocation } -| modulus_expression { $$.v = $1.v as RoutineInvocation } -| trigonometric_function { $$.v = $1.v as RoutineInvocation } -| common_logarithm { $$.v = $1.v as RoutineInvocation } -| natural_logarithm { $$.v = $1.v as RoutineInvocation } -| exponential_function { $$.v = $1.v as RoutineInvocation } -| power_function { $$.v = $1.v as RoutineInvocation } -| square_root { $$.v = $1.v as RoutineInvocation } -| floor_function { $$.v = $1.v as RoutineInvocation } -| ceiling_function { $$.v = $1.v as RoutineInvocation } -position_expression: - character_position_expression { $$.v = $1.v as RoutineInvocation } -character_position_expression: - POSITION left_paren character_value_expression_1 IN - character_value_expression_2 right_paren { - $$.v = RoutineInvocation{'POSITION', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), - ValueExpression(CommonValueExpression($5.v as CharacterValueExpression)), - ]} - } +cursor_specification: + query_expression { $$.v = Stmt($1.v as QueryExpression) } -character_value_expression_1: - character_value_expression { $$.v = $1.v as CharacterValueExpression } -character_value_expression_2: - character_value_expression { $$.v = $1.v as CharacterValueExpression } -length_expression: - char_length_expression { $$.v = $1.v as RoutineInvocation } -| octet_length_expression { $$.v = $1.v as RoutineInvocation } +target_table: + table_name { $$.v = $1.v as Identifier } -char_length_expression: - CHAR_LENGTH left_paren character_value_expression right_paren { - $$.v = RoutineInvocation{'CHAR_LENGTH', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), - ]} - } -| CHARACTER_LENGTH left_paren character_value_expression right_paren { - $$.v = RoutineInvocation{'CHAR_LENGTH', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), - ]} - } -octet_length_expression: - OCTET_LENGTH left_paren string_value_expression right_paren { - $$.v = RoutineInvocation{'OCTET_LENGTH', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), - ]} - } -absolute_value_expression: - ABS left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'ABS', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} +delete_statement_searched: + DELETE FROM target_table { + $$.v = Stmt(DeleteStatementSearched{$3.v as Identifier, none}) } - -modulus_expression: - MOD left_paren numeric_value_expression_dividend comma - numeric_value_expression_divisor right_paren { - $$.v = RoutineInvocation{'MOD', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ValueExpression(CommonValueExpression($5.v as NumericValueExpression)) - ]} +| DELETE FROM target_table WHERE search_condition { + $$.v = Stmt(DeleteStatementSearched{ + $3.v as Identifier + $5.v as BooleanValueExpression + }) } -numeric_value_expression_dividend: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } -numeric_value_expression_divisor: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } -trigonometric_function: - trigonometric_function_name left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{$1.v as string, [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)), - ]} - } +start_transaction_statement: + START TRANSACTION { $$.v = Stmt(StartTransactionStatement{}) } -trigonometric_function_name: - SIN { $$.v = $1.v as string } -| COS { $$.v = $1.v as string } -| TAN { $$.v = $1.v as string } -| SINH { $$.v = $1.v as string } -| COSH { $$.v = $1.v as string } -| TANH { $$.v = $1.v as string } -| ASIN { $$.v = $1.v as string } -| ACOS { $$.v = $1.v as string } -| ATAN { $$.v = $1.v as string } -common_logarithm: - LOG10 left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'LOG10', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } -natural_logarithm: - LN left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'LN', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } +commit_statement: + COMMIT { $$.v = Stmt(CommitStatement{}) } +| COMMIT WORK { $$.v = Stmt(CommitStatement{}) } -exponential_function: - EXP left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'EXP', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } -power_function: - POWER left_paren numeric_value_expression_base comma - numeric_value_expression_exponent right_paren { - $$.v = RoutineInvocation{'POWER', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)), - ValueExpression(CommonValueExpression($5.v as NumericValueExpression)) - ]} - } -numeric_value_expression_base: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } +rollback_statement: + ROLLBACK { $$.v = Stmt(RollbackStatement{}) } +| ROLLBACK WORK { $$.v = Stmt(RollbackStatement{}) } -numeric_value_expression_exponent: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } -square_root: - SQRT left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'SQRT', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } -floor_function: - FLOOR left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'FLOOR', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} +set_catalog_statement: + SET catalog_name_characteristic { + $$.v = Stmt(SetCatalogStatement{$2.v as ValueSpecification}) } -ceiling_function: - CEIL left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'CEILING', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} - } -| CEILING left_paren numeric_value_expression right_paren { - $$.v = RoutineInvocation{'CEILING', [ - ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) - ]} +catalog_name_characteristic: + CATALOG value_specification { $$.v = $2.v as ValueSpecification } + + + +set_schema_statement: + SET schema_name_characteristic { + $$.v = SetSchemaStatement{$2.v as ValueSpecification} } +schema_name_characteristic: + SCHEMA value_specification { $$.v = $2.v } + + + +preparable_statement: + preparable_sql_data_statement { $$.v = $1.v as Stmt } +| preparable_sql_schema_statement { $$.v = $1.v as Stmt } +| preparable_sql_transaction_statement { $$.v = $1.v as Stmt } +| preparable_sql_session_statement { $$.v = $1.v as Stmt } + +preparable_sql_data_statement: + delete_statement_searched { $$.v = $1.v as Stmt } +| insert_statement { $$.v = $1.v as Stmt } +| dynamic_select_statement { $$.v = $1.v as Stmt } +| update_statement_searched { $$.v = $1.v as Stmt } + +preparable_sql_schema_statement: + sql_schema_statement { $$.v = $1.v as Stmt } + +preparable_sql_transaction_statement: + sql_transaction_statement { $$.v = $1.v as Stmt } + +preparable_sql_session_statement: + sql_session_statement { $$.v = $1.v as Stmt } + +dynamic_select_statement: + cursor_specification { $$.v = $1.v as Stmt } + + + +left_paren: OPERATOR_LEFT_PAREN + +right_paren: OPERATOR_RIGHT_PAREN + +asterisk: OPERATOR_ASTERISK { $$.v = $1.v as string } + +plus_sign: OPERATOR_PLUS { $$.v = $1.v as string } + +comma: OPERATOR_COMMA + +minus_sign: OPERATOR_MINUS { $$.v = $1.v as string } + +period: OPERATOR_PERIOD + +solidus: OPERATOR_SOLIDUS { $$.v = $1.v as string } + +colon: OPERATOR_COLON + +less_than_operator: OPERATOR_LESS_THAN + +equals_operator: OPERATOR_EQUALS + +greater_than_operator: OPERATOR_GREATER_THAN + + + concatenation_operator: OPERATOR_DOUBLE_PIPE @@ -1662,500 +1497,341 @@ non_reserved_word: | WRITE | ZONE -data_type: - predefined_type { $$.v = $1.v as Type } -predefined_type: - character_string_type { $$.v = $1.v as Type } -| numeric_type { $$.v = $1.v as Type } -| boolean_type { $$.v = $1.v as Type } -| datetime_type { $$.v = $1.v as Type } -character_string_type: - CHARACTER { $$.v = new_type('CHARACTER', 1, 0) } -| CHARACTER left_paren character_length right_paren { - $$.v = new_type('CHARACTER', ($3.v as string).int(), 0) - } -| CHAR { $$.v = new_type('CHARACTER', 1, 0) } -| CHAR left_paren character_length right_paren { - $$.v = new_type('CHARACTER', ($3.v as string).int(), 0) - } -| CHARACTER VARYING left_paren character_length right_paren { - $$.v = new_type('CHARACTER VARYING', ($4.v as string).int(), 0) - } -| CHAR VARYING left_paren character_length right_paren { - $$.v = new_type('CHARACTER VARYING', ($4.v as string).int(), 0) - } -| VARCHAR left_paren character_length right_paren { - $$.v = new_type('CHARACTER VARYING', ($3.v as string).int(), 0) - } +literal: + signed_numeric_literal { $$.v = $1.v as Value } +| general_literal { $$.v = $1.v as Value } -numeric_type: - exact_numeric_type { $$.v = $1.v as Type } -| approximate_numeric_type { $$.v = $1.v as Type } +unsigned_literal: + unsigned_numeric_literal { $$.v = $1.v as Value } +| general_literal { $$.v = $1.v as Value } -exact_numeric_type: - NUMERIC { $$.v = new_type('NUMERIC', 0, 0) } -| NUMERIC left_paren precision right_paren { - $$.v = new_type('NUMERIC', ($3.v as string).int(), 0) - } -| NUMERIC left_paren precision comma scale right_paren { - $$.v = new_type('NUMERIC', ($3.v as string).int(), ($5.v as string).i16()) - } -| DECIMAL { $$.v = new_type('DECIMAL', 0, 0) } -| DECIMAL left_paren precision right_paren { - $$.v = new_type('DECIMAL', ($3.v as string).int(), 0) - } -| DECIMAL left_paren precision comma scale right_paren { - $$.v = new_type('DECIMAL', ($3.v as string).int(), ($5.v as string).i16()) - } -| SMALLINT { $$.v = new_type('SMALLINT', 0, 0) } -| INTEGER { $$.v = new_type('INTEGER', 0, 0) } -| INT { $$.v = new_type('INTEGER', 0, 0) } -| BIGINT { $$.v = new_type('BIGINT', 0, 0) } +general_literal: + character_string_literal { $$.v = $1.v as Value } +| datetime_literal { $$.v = $1.v as Value } +| boolean_literal { $$.v = $1.v as Value } -approximate_numeric_type: - FLOAT { $$.v = new_type('FLOAT', 0, 0) } -| FLOAT left_paren precision right_paren { - $$.v = new_type('FLOAT', ($3.v as string).int(), 0) +character_string_literal: + LITERAL_STRING { $$.v = $1.v as Value } + +signed_numeric_literal: + unsigned_numeric_literal { $$.v = $1.v as Value } +| sign unsigned_numeric_literal { + $$.v = numeric_literal($1.v as string + ($2.v as Value).str())! } -| REAL { $$.v = new_type('REAL', 0, 0) } -| DOUBLE PRECISION { $$.v = new_type('DOUBLE PRECISION', 0, 0) } -length: - unsigned_integer { $$.v = $1.v as string } +unsigned_numeric_literal: + exact_numeric_literal { $$.v = $1.v as Value } +| approximate_numeric_literal { $$.v = $1.v as Value } -character_length: - length { $$.v = $1.v as string } +exact_numeric_literal: + unsigned_integer { $$.v = numeric_literal($1.v as string)! } +| unsigned_integer period { $$.v = numeric_literal(($1.v as string) + '.')! } +| unsigned_integer period unsigned_integer { + $$.v = numeric_literal(($1.v as string) + '.' + ($3.v as string))! + } +| period unsigned_integer { $$.v = numeric_literal('0.' + ($2.v as string))! } -char_length_units: - CHARACTERS { $$.v = $1.v as string } -| OCTETS { $$.v = $1.v as string } +sign: + plus_sign { $$.v = $1.v as string } +| minus_sign { $$.v = $1.v as string } -precision: - unsigned_integer { $$.v = $1.v as string } +approximate_numeric_literal: + mantissa E exponent { + $$.v = new_double_precision_value( + ($1.v as Value).as_f64()! * math.pow(10, ($3.v as Value).as_f64()!)) + } -scale: - unsigned_integer { $$.v = $1.v as string } +mantissa: + exact_numeric_literal { $$.v = $1.v as Value } -boolean_type: - BOOLEAN { $$.v = new_type('BOOLEAN', 0, 0) } +exponent: + signed_integer { $$.v = $1.v as Value } -datetime_type: - DATE { $$.v = new_type('DATE', 0, 0) } -| TIME { $$.v = parse_time_prec_tz_type('0', false)! } -| TIME left_paren time_precision right_paren { - $$.v = parse_time_prec_tz_type($3.v as string, false)! - } -| TIME with_or_without_time_zone { - $$.v = parse_time_prec_tz_type('0', $2.v as bool)! - } -| TIME left_paren time_precision right_paren with_or_without_time_zone { - $$.v = parse_time_prec_tz_type($3.v as string, $5.v as bool)! - } -| TIMESTAMP { $$.v = parse_timestamp_prec_tz_type('0', false)! } -| TIMESTAMP left_paren timestamp_precision right_paren { - $$.v = parse_timestamp_prec_tz_type($3.v as string, false)! - } -| TIMESTAMP with_or_without_time_zone { - // ISO/IEC 9075-2:2016(E), 6.1, 36) If is not - // specified, then 6 is implicit. - $$.v = parse_timestamp_prec_tz_type('6', $2.v as bool)! -} -| TIMESTAMP left_paren timestamp_precision right_paren - with_or_without_time_zone { - $$.v = parse_timestamp_prec_tz_type($3.v as string, $5.v as bool)! +signed_integer: + unsigned_integer { $$.v = new_numeric_value($1.v as string) } +| sign unsigned_integer { + $$.v = if $1.v as string == '-' { + new_numeric_value('-' + ($2.v as string)) + } else { + new_numeric_value($2.v as string) + } } -with_or_without_time_zone: - WITH TIME ZONE { $$.v = true } -| WITHOUT TIME ZONE { $$.v = false } +unsigned_integer: + LITERAL_NUMBER { $$.v = $1.v as string } -time_precision: - time_fractional_seconds_precision { $$.v = $1.v as string } +datetime_literal: + date_literal { $$.v = $1.v as Value } +| time_literal { $$.v = $1.v as Value } +| timestamp_literal { $$.v = $1.v as Value } -timestamp_precision: - time_fractional_seconds_precision { $$.v = $1.v as string } +date_literal: + DATE date_string { $$.v = new_date_value(($2.v as Value).string_value())! } -time_fractional_seconds_precision: - unsigned_integer { $$.v = $1.v as string } +time_literal: + TIME time_string { $$.v = new_time_value(($2.v as Value).string_value())! } -like_predicate: - character_like_predicate { $$.v = $1.v as CharacterLikePredicate } +timestamp_literal: + TIMESTAMP timestamp_string { + $$.v = new_timestamp_value(($2.v as Value).string_value())! + } -character_like_predicate: - row_value_predicand character_like_predicate_part_2 { - like := $2.v as CharacterLikePredicate - $$.v = CharacterLikePredicate{ - $1.v as RowValueConstructorPredicand - like.right - like.not - } - } +date_string: + LITERAL_STRING { $$.v = $1.v as Value } -character_like_predicate_part_2: - LIKE character_pattern { - $$.v = CharacterLikePredicate{none, $2.v as CharacterValueExpression, false} - } -| NOT LIKE character_pattern { - $$.v = CharacterLikePredicate{none, $3.v as CharacterValueExpression, true} - } +time_string: + LITERAL_STRING { $$.v = $1.v as Value } -character_pattern: - character_value_expression { $$.v = $1.v as CharacterValueExpression } +timestamp_string: + LITERAL_STRING { $$.v = $1.v as Value } -comparison_predicate: - row_value_predicand comparison_predicate_part_2 { - comp := $2.v as ComparisonPredicatePart2 - $$.v = ComparisonPredicate{ - $1.v as RowValueConstructorPredicand - comp.op - comp.expr - } - } +boolean_literal: + TRUE { $$.v = new_boolean_value(true) } +| FALSE { $$.v = new_boolean_value(false) } +| UNKNOWN { $$.v = new_unknown_value() } -comparison_predicate_part_2: - comp_op row_value_predicand { - $$.v = ComparisonPredicatePart2{ - $1.v as string - $2.v as RowValueConstructorPredicand - } - } -comp_op: - equals_operator { $$.v = $1.v as string } -| not_equals_operator { $$.v = $1.v as string } -| less_than_operator { $$.v = $1.v as string } -| greater_than_operator { $$.v = $1.v as string } -| less_than_or_equals_operator { $$.v = $1.v as string } -| greater_than_or_equals_operator { $$.v = $1.v as string } -row_value_constructor: - common_value_expression { - $$.v = RowValueConstructor($1.v as CommonValueExpression) - } -| boolean_value_expression { - $$.v = RowValueConstructor($1.v as BooleanValueExpression) - } -| explicit_row_value_constructor { - $$.v = RowValueConstructor($1.v as ExplicitRowValueConstructor) +identifier: + actual_identifier { $$.v = $1.v as IdentifierChain } + +actual_identifier: + regular_identifier { $$.v = $1.v as IdentifierChain } + +table_name: + local_or_schema_qualified_name { + $$.v = new_table_identifier(($1.v as IdentifierChain).identifier)! } -explicit_row_value_constructor: - ROW left_paren row_value_constructor_element_list right_paren { - $$.v = ExplicitRowValueConstructor(ExplicitRowValueConstructorRow{$3.v as []ValueExpression}) +schema_name: + catalog_name period unqualified_schema_name { + $$.v = new_schema_identifier(($1.v as IdentifierChain).str() + '.' + + ($3.v as Identifier).str())! } -| row_subquery { $$.v = ExplicitRowValueConstructor($1.v as QueryExpression) } +| unqualified_schema_name { $$.v = $1.v as Identifier } -row_value_constructor_element_list: - row_value_constructor_element { $$.v = [$1.v as ValueExpression] } -| row_value_constructor_element_list comma row_value_constructor_element { - $$.v = append_list($1.v as []ValueExpression, $3.v as ValueExpression) +unqualified_schema_name: + identifier { + $$.v = new_schema_identifier(($1.v as IdentifierChain).identifier)! } -row_value_constructor_element: - value_expression { $$.v = $1.v as ValueExpression } +catalog_name: + identifier { $$.v = $1.v as IdentifierChain } -contextually_typed_row_value_constructor: - common_value_expression { - $$.v = ContextuallyTypedRowValueConstructor($1.v as CommonValueExpression) - } -| boolean_value_expression { - $$.v = ContextuallyTypedRowValueConstructor($1.v as BooleanValueExpression) - } -| contextually_typed_value_specification { - $$.v = ContextuallyTypedRowValueConstructor($1.v as NullSpecification) - } -| left_paren contextually_typed_value_specification right_paren { - $$.v = ContextuallyTypedRowValueConstructor($2.v as NullSpecification) - } -| left_paren contextually_typed_row_value_constructor_element comma - contextually_typed_row_value_constructor_element_list right_paren { - $$.v = ContextuallyTypedRowValueConstructor(push_list( - $2.v as ContextuallyTypedRowValueConstructorElement, - $4.v as []ContextuallyTypedRowValueConstructorElement)) +schema_qualified_name: + qualified_identifier { $$.v = $1.v as IdentifierChain } +| schema_name period qualified_identifier { + $$.v = IdentifierChain{($1.v as Identifier).schema_name + '.' + + ($3.v as IdentifierChain).str()} } -contextually_typed_row_value_constructor_element_list: - contextually_typed_row_value_constructor_element { - $$.v = [$1.v as ContextuallyTypedRowValueConstructorElement] - } -| contextually_typed_row_value_constructor_element_list comma - contextually_typed_row_value_constructor_element { - $$.v = append_list($1.v as []ContextuallyTypedRowValueConstructorElement, - $3.v as ContextuallyTypedRowValueConstructorElement) +local_or_schema_qualified_name: + qualified_identifier { $$.v = $1.v as IdentifierChain } +| local_or_schema_qualifier period qualified_identifier { + $$.v = IdentifierChain{($1.v as Identifier).str() + '.' + + ($3.v as IdentifierChain).str()} } -contextually_typed_row_value_constructor_element: - value_expression { - $$.v = ContextuallyTypedRowValueConstructorElement($1.v as ValueExpression) - } -| contextually_typed_value_specification { - $$.v = ContextuallyTypedRowValueConstructorElement($1.v as NullSpecification) +local_or_schema_qualifier: + schema_name { $$.v = $1.v as Identifier } + +qualified_identifier: + identifier { $$.v = $1.v as IdentifierChain } + +column_name: + identifier { + $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! } -row_value_constructor_predicand: - common_value_expression { - $$.v = RowValueConstructorPredicand($1.v as CommonValueExpression) +host_parameter_name: + colon identifier { + $$.v = GeneralValueSpecification(HostParameterName{ + ($2.v as IdentifierChain).identifier} + ) } -| boolean_predicand { - $$.v = RowValueConstructorPredicand($1.v as BooleanPredicand) + +correlation_name: + identifier { + $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! } -query_specification: - SELECT select_list table_expression { - $$.v = QuerySpecification{ - exprs: $2.v as SelectList - table_expression: $3.v as TableExpression - } +sequence_generator_name: + schema_qualified_name { + $$.v = new_table_identifier(($1.v as IdentifierChain).identifier)! } -select_list: - asterisk { $$.v = SelectList(AsteriskExpr(true)) } -| select_sublist { $$.v = $1.v as SelectList } -| select_list comma select_sublist { - mut new_select_list := (($1.v as SelectList) as []DerivedColumn).clone() - new_select_list << (($3.v as SelectList) as []DerivedColumn)[0] - $$.v = SelectList(new_select_list) + + +case_expression: + case_abbreviation { $$.v = $1.v as CaseExpression } + +case_abbreviation: + NULLIF left_paren value_expression comma value_expression right_paren { + $$.v = CaseExpression(CaseExpressionNullIf{ + $3.v as ValueExpression + $5.v as ValueExpression + }) + } +| COALESCE left_paren value_expression_list right_paren { + $$.v = CaseExpression(CaseExpressionCoalesce{$3.v as []ValueExpression}) } -select_sublist: - derived_column { $$.v = SelectList([$1.v as DerivedColumn]) } -| qualified_asterisk { $$.v = SelectList($1.v as QualifiedAsteriskExpr) } +// These are non-standard, just to simplify standard rules: -// was: asterisked_identifier_chain period asterisk -qualified_asterisk: - asterisked_identifier_chain OPERATOR_PERIOD_ASTERISK { - $$.v = QualifiedAsteriskExpr{ - new_column_identifier(($1.v as IdentifierChain).identifier)! - } +value_expression_list: + value_expression { $$.v = [$1.v as ValueExpression] } +| value_expression_list comma value_expression { + $$.v = append_list($1.v as []ValueExpression, $3.v as ValueExpression) } -asterisked_identifier_chain: - asterisked_identifier { $$.v = $1.v as IdentifierChain } -asterisked_identifier: - identifier { $$.v = $1.v as IdentifierChain } -derived_column: - value_expression { - $$.v = DerivedColumn{$1.v as ValueExpression, Identifier{}} +cast_specification: + CAST left_paren cast_operand AS cast_target right_paren { + $$.v = CastSpecification{$3.v as CastOperand, $5.v as Type} } -| value_expression as_clause { - $$.v = DerivedColumn{$1.v as ValueExpression, $2.v as Identifier} + +cast_operand: + value_expression { $$.v = CastOperand($1.v as ValueExpression) } +| implicitly_typed_value_specification { + $$.v = CastOperand($1.v as NullSpecification) } -as_clause: - AS column_name { $$.v = $2.v as Identifier } -| column_name { $$.v = $1.v as Identifier } +cast_target: + data_type { $$.v = $1.v as Type } -string_value_expression: - character_value_expression { $$.v = $1.v as CharacterValueExpression } -character_value_expression: - concatenation { $$.v = CharacterValueExpression($1.v as Concatenation) } -| character_factor { $$.v = CharacterValueExpression($1.v as CharacterPrimary) } -concatenation: - character_value_expression concatenation_operator character_factor { - $$.v = Concatenation{ - $1.v as CharacterValueExpression - $3.v as CharacterPrimary +next_value_expression: + NEXT VALUE FOR sequence_generator_name { + $$.v = NextValueExpression{ + name: $4.v as Identifier } } -character_factor: - character_primary { $$.v = $1.v as CharacterPrimary } -character_primary: - value_expression_primary { - $$.v = CharacterPrimary($1.v as ValueExpressionPrimary) - } -| string_value_function { - $$.v = CharacterPrimary($1.v as CharacterValueFunction) - } -set_function_specification: - aggregate_function { $$.v = $1.v as AggregateFunction } +data_type: + predefined_type { $$.v = $1.v as Type } -table_reference: - table_factor { $$.v = TableReference($1.v as TablePrimary) } -| joined_table { $$.v = TableReference($1.v as QualifiedJoin) } +predefined_type: + character_string_type { $$.v = $1.v as Type } +| numeric_type { $$.v = $1.v as Type } +| boolean_type { $$.v = $1.v as Type } +| datetime_type { $$.v = $1.v as Type } -qualified_join: - table_reference JOIN table_reference join_specification { - $$.v = QualifiedJoin{ - $1.v as TableReference - 'INNER' - $3.v as TableReference - $4.v as BooleanValueExpression - } +character_string_type: + CHARACTER { $$.v = new_type('CHARACTER', 1, 0) } +| CHARACTER left_paren character_length right_paren { + $$.v = new_type('CHARACTER', ($3.v as string).int(), 0) } -| table_reference join_type JOIN table_reference join_specification { - $$.v = QualifiedJoin{ - $1.v as TableReference - $2.v as string - $4.v as TableReference - $5.v as BooleanValueExpression - } +| CHAR { $$.v = new_type('CHARACTER', 1, 0) } +| CHAR left_paren character_length right_paren { + $$.v = new_type('CHARACTER', ($3.v as string).int(), 0) } - -table_factor: - table_primary { $$.v = $1.v as TablePrimary } - -table_primary: - table_or_query_name { - $$.v = TablePrimary{ - body: $1.v as Identifier - } +| CHARACTER VARYING left_paren character_length right_paren { + $$.v = new_type('CHARACTER VARYING', ($4.v as string).int(), 0) } -| derived_table { $$.v = $1.v as TablePrimary } -| derived_table correlation_or_recognition { - $$.v = TablePrimary{ - body: ($1.v as TablePrimary).body - correlation: $2.v as Correlation - } +| CHAR VARYING left_paren character_length right_paren { + $$.v = new_type('CHARACTER VARYING', ($4.v as string).int(), 0) + } +| VARCHAR left_paren character_length right_paren { + $$.v = new_type('CHARACTER VARYING', ($3.v as string).int(), 0) } -correlation_or_recognition: - correlation_name { - $$.v = Correlation{ - name: $1.v as Identifier - } +numeric_type: + exact_numeric_type { $$.v = $1.v as Type } +| approximate_numeric_type { $$.v = $1.v as Type } + +exact_numeric_type: + NUMERIC { $$.v = new_type('NUMERIC', 0, 0) } +| NUMERIC left_paren precision right_paren { + $$.v = new_type('NUMERIC', ($3.v as string).int(), 0) } -| AS correlation_name { - $$.v = Correlation{ - name: $2.v as Identifier - } +| NUMERIC left_paren precision comma scale right_paren { + $$.v = new_type('NUMERIC', ($3.v as string).int(), ($5.v as string).i16()) } -| correlation_name parenthesized_derived_column_list { - $$.v = Correlation{ - name: $1.v as Identifier - columns: $2.v as []Identifier - } +| DECIMAL { $$.v = new_type('DECIMAL', 0, 0) } +| DECIMAL left_paren precision right_paren { + $$.v = new_type('DECIMAL', ($3.v as string).int(), 0) } -| AS correlation_name parenthesized_derived_column_list { - $$.v = Correlation{ - name: $2.v as Identifier - columns: $3.v as []Identifier - } +| DECIMAL left_paren precision comma scale right_paren { + $$.v = new_type('DECIMAL', ($3.v as string).int(), ($5.v as string).i16()) } +| SMALLINT { $$.v = new_type('SMALLINT', 0, 0) } +| INTEGER { $$.v = new_type('INTEGER', 0, 0) } +| INT { $$.v = new_type('INTEGER', 0, 0) } +| BIGINT { $$.v = new_type('BIGINT', 0, 0) } -derived_table: - table_subquery { $$.v = $1.v as TablePrimary } - -table_or_query_name: - table_name { $$.v = $1.v as Identifier } - -derived_column_list: - column_name_list { $$.v = $1.v as []Identifier } - -column_name_list: - column_name { $$.v = [$1.v as Identifier] } -| column_name_list comma column_name { - $$.v = append_list($1.v as []Identifier, $3.v as Identifier) +approximate_numeric_type: + FLOAT { $$.v = new_type('FLOAT', 0, 0) } +| FLOAT left_paren precision right_paren { + $$.v = new_type('FLOAT', ($3.v as string).int(), 0) } +| REAL { $$.v = new_type('REAL', 0, 0) } +| DOUBLE PRECISION { $$.v = new_type('DOUBLE PRECISION', 0, 0) } -parenthesized_derived_column_list: - left_paren derived_column_list right_paren { $$.v = $2.v } +length: + unsigned_integer { $$.v = $1.v as string } -sequence_generator_definition: - CREATE SEQUENCE sequence_generator_name { - $$.v = SequenceGeneratorDefinition{ - name: $3.v as Identifier - } - } -| CREATE SEQUENCE sequence_generator_name sequence_generator_options { - $$.v = SequenceGeneratorDefinition{ - name: $3.v as Identifier - options: $4.v as []SequenceGeneratorOption - } - } +character_length: + length { $$.v = $1.v as string } -sequence_generator_options: - sequence_generator_option { $$.v = $1.v as []SequenceGeneratorOption } -| sequence_generator_options sequence_generator_option { - $$.v = $1.v as []SequenceGeneratorOption - } +char_length_units: + CHARACTERS { $$.v = $1.v as string } +| OCTETS { $$.v = $1.v as string } -sequence_generator_option: - common_sequence_generator_options { $$.v = $1.v as []SequenceGeneratorOption } +precision: + unsigned_integer { $$.v = $1.v as string } -common_sequence_generator_options: - common_sequence_generator_option { $$.v = [$1.v as SequenceGeneratorOption] } -| common_sequence_generator_options common_sequence_generator_option { - $$.v = append_list($1.v as []SequenceGeneratorOption, - $2.v as SequenceGeneratorOption) - } +scale: + unsigned_integer { $$.v = $1.v as string } -common_sequence_generator_option: - sequence_generator_start_with_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorStartWithOption) - } -| basic_sequence_generator_option { $$.v = $1.v as SequenceGeneratorOption } +boolean_type: + BOOLEAN { $$.v = new_type('BOOLEAN', 0, 0) } -basic_sequence_generator_option: - sequence_generator_increment_by_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorIncrementByOption) - } -| sequence_generator_maxvalue_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorMaxvalueOption) +datetime_type: + DATE { $$.v = new_type('DATE', 0, 0) } +| TIME { $$.v = parse_time_prec_tz_type('0', false)! } +| TIME left_paren time_precision right_paren { + $$.v = parse_time_prec_tz_type($3.v as string, false)! } -| sequence_generator_minvalue_option { - $$.v = SequenceGeneratorOption($1.v as SequenceGeneratorMinvalueOption) +| TIME with_or_without_time_zone { + $$.v = parse_time_prec_tz_type('0', $2.v as bool)! } -| sequence_generator_cycle_option { - $$.v = SequenceGeneratorOption(SequenceGeneratorCycleOption{$1.v as bool}) +| TIME left_paren time_precision right_paren with_or_without_time_zone { + $$.v = parse_time_prec_tz_type($3.v as string, $5.v as bool)! } - -sequence_generator_start_with_option: - START WITH sequence_generator_start_value { - $$.v = SequenceGeneratorStartWithOption{ - start_value: $3.v as Value - } +| TIMESTAMP { $$.v = parse_timestamp_prec_tz_type('0', false)! } +| TIMESTAMP left_paren timestamp_precision right_paren { + $$.v = parse_timestamp_prec_tz_type($3.v as string, false)! } - -sequence_generator_start_value: - signed_numeric_literal { $$.v = $1.v as Value } - -sequence_generator_increment_by_option: - INCREMENT BY sequence_generator_increment { - $$.v = SequenceGeneratorIncrementByOption{ - increment_by: $3.v as Value - } +| TIMESTAMP with_or_without_time_zone { + // ISO/IEC 9075-2:2016(E), 6.1, 36) If is not + // specified, then 6 is implicit. + $$.v = parse_timestamp_prec_tz_type('6', $2.v as bool)! +} +| TIMESTAMP left_paren timestamp_precision right_paren + with_or_without_time_zone { + $$.v = parse_timestamp_prec_tz_type($3.v as string, $5.v as bool)! } -sequence_generator_increment: - signed_numeric_literal { $$.v = $1.v as Value } - -sequence_generator_maxvalue_option: - MAXVALUE sequence_generator_max_value { - $$.v = SequenceGeneratorMaxvalueOption{ - max_value: $2.v as Value - } - } -| NO MAXVALUE { $$.v = SequenceGeneratorMaxvalueOption{} } +with_or_without_time_zone: + WITH TIME ZONE { $$.v = true } +| WITHOUT TIME ZONE { $$.v = false } -sequence_generator_max_value: - signed_numeric_literal { $$.v = $1.v as Value } +time_precision: + time_fractional_seconds_precision { $$.v = $1.v as string } -sequence_generator_minvalue_option: - MINVALUE sequence_generator_min_value { - $$.v = SequenceGeneratorMinvalueOption{ - min_value: $2.v as Value - } - } -| NO MINVALUE { $$.v = SequenceGeneratorMinvalueOption{} } +timestamp_precision: + time_fractional_seconds_precision { $$.v = $1.v as string } -sequence_generator_min_value: - signed_numeric_literal { $$.v = $1.v as Value } +time_fractional_seconds_precision: + unsigned_integer { $$.v = $1.v as string } -sequence_generator_cycle_option: - CYCLE { $$.v = true } -| NO CYCLE { $$.v = false } -search_condition: - boolean_value_expression { $$.v = $1.v as BooleanValueExpression } value_expression: common_value_expression { @@ -2176,45 +1852,375 @@ common_value_expression: $$.v = CommonValueExpression($1.v as DatetimePrimary) } -table_expression: - from_clause { - $$.v = TableExpression{$1.v as TableReference, none, []Identifier{}} + + +numeric_value_expression: + term { $$.v = NumericValueExpression{term: $1.v as Term} } +| numeric_value_expression plus_sign term { + n := $1.v as NumericValueExpression + $$.v = NumericValueExpression{&n, '+', $3.v as Term} } -| from_clause where_clause { - $$.v = TableExpression{ - $1.v as TableReference - $2.v as BooleanValueExpression - []Identifier{} - } +| numeric_value_expression minus_sign term { + n := $1.v as NumericValueExpression + $$.v = NumericValueExpression{&n, '-', $3.v as Term} } -| from_clause group_by_clause { - $$.v = TableExpression{$1.v as TableReference, none, $2.v as []Identifier} + +term: + factor { $$.v = Term{factor: $1.v as NumericPrimary} } +| term asterisk factor { + t := $1.v as Term + $$.v = Term{&t, '*', $3.v as NumericPrimary} } -| from_clause where_clause group_by_clause { - $$.v = TableExpression{ - $1.v as TableReference - $2.v as BooleanValueExpression - $3.v as []Identifier - } +| term solidus factor { + t := $1.v as Term + $$.v = Term{&t, '/', $3.v as NumericPrimary} } -group_by_clause: - GROUP BY grouping_element_list { $$.v = $3.v } +factor: + numeric_primary { $$.v = $1.v as NumericPrimary } +| sign numeric_primary { + $$.v = parse_factor_2($1.v as string, $2.v as NumericPrimary)! + } -grouping_element_list: - grouping_element { $$.v = [$1.v as Identifier] } -| grouping_element_list comma grouping_element { - $$.v = append_list($1.v as []Identifier, $3.v as Identifier) +numeric_primary: + value_expression_primary { + $$.v = NumericPrimary($1.v as ValueExpressionPrimary) } +| numeric_value_function { $$.v = NumericPrimary($1.v as RoutineInvocation) } -grouping_element: - ordinary_grouping_set { $$.v = $1.v as Identifier } -ordinary_grouping_set: - grouping_column_reference { $$.v = $1.v as Identifier } -grouping_column_reference: - column_reference { $$.v = $1.v as Identifier } +numeric_value_function: + position_expression { $$.v = $1.v as RoutineInvocation } +| length_expression { $$.v = $1.v as RoutineInvocation } +| absolute_value_expression { $$.v = $1.v as RoutineInvocation } +| modulus_expression { $$.v = $1.v as RoutineInvocation } +| trigonometric_function { $$.v = $1.v as RoutineInvocation } +| common_logarithm { $$.v = $1.v as RoutineInvocation } +| natural_logarithm { $$.v = $1.v as RoutineInvocation } +| exponential_function { $$.v = $1.v as RoutineInvocation } +| power_function { $$.v = $1.v as RoutineInvocation } +| square_root { $$.v = $1.v as RoutineInvocation } +| floor_function { $$.v = $1.v as RoutineInvocation } +| ceiling_function { $$.v = $1.v as RoutineInvocation } + +position_expression: + character_position_expression { $$.v = $1.v as RoutineInvocation } + +character_position_expression: + POSITION left_paren character_value_expression_1 IN + character_value_expression_2 right_paren { + $$.v = RoutineInvocation{'POSITION', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), + ValueExpression(CommonValueExpression($5.v as CharacterValueExpression)), + ]} + } + +character_value_expression_1: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +character_value_expression_2: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +length_expression: + char_length_expression { $$.v = $1.v as RoutineInvocation } +| octet_length_expression { $$.v = $1.v as RoutineInvocation } + +char_length_expression: + CHAR_LENGTH left_paren character_value_expression right_paren { + $$.v = RoutineInvocation{'CHAR_LENGTH', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), + ]} + } +| CHARACTER_LENGTH left_paren character_value_expression right_paren { + $$.v = RoutineInvocation{'CHAR_LENGTH', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), + ]} + } + +octet_length_expression: + OCTET_LENGTH left_paren string_value_expression right_paren { + $$.v = RoutineInvocation{'OCTET_LENGTH', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression)), + ]} + } + +absolute_value_expression: + ABS left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'ABS', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +modulus_expression: + MOD left_paren numeric_value_expression_dividend comma + numeric_value_expression_divisor right_paren { + $$.v = RoutineInvocation{'MOD', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ValueExpression(CommonValueExpression($5.v as NumericValueExpression)) + ]} + } + +numeric_value_expression_dividend: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +numeric_value_expression_divisor: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +trigonometric_function: + trigonometric_function_name left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{$1.v as string, [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)), + ]} + } + +trigonometric_function_name: + SIN { $$.v = $1.v as string } +| COS { $$.v = $1.v as string } +| TAN { $$.v = $1.v as string } +| SINH { $$.v = $1.v as string } +| COSH { $$.v = $1.v as string } +| TANH { $$.v = $1.v as string } +| ASIN { $$.v = $1.v as string } +| ACOS { $$.v = $1.v as string } +| ATAN { $$.v = $1.v as string } + +common_logarithm: + LOG10 left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'LOG10', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +natural_logarithm: + LN left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'LN', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +exponential_function: + EXP left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'EXP', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +power_function: + POWER left_paren numeric_value_expression_base comma + numeric_value_expression_exponent right_paren { + $$.v = RoutineInvocation{'POWER', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)), + ValueExpression(CommonValueExpression($5.v as NumericValueExpression)) + ]} + } + +numeric_value_expression_base: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +numeric_value_expression_exponent: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +square_root: + SQRT left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'SQRT', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +floor_function: + FLOOR left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'FLOOR', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + +ceiling_function: + CEIL left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'CEILING', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } +| CEILING left_paren numeric_value_expression right_paren { + $$.v = RoutineInvocation{'CEILING', [ + ValueExpression(CommonValueExpression($3.v as NumericValueExpression)) + ]} + } + + + +string_value_expression: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +character_value_expression: + concatenation { $$.v = CharacterValueExpression($1.v as Concatenation) } +| character_factor { $$.v = CharacterValueExpression($1.v as CharacterPrimary) } + +concatenation: + character_value_expression concatenation_operator character_factor { + $$.v = Concatenation{ + $1.v as CharacterValueExpression + $3.v as CharacterPrimary + } + } + +character_factor: + character_primary { $$.v = $1.v as CharacterPrimary } + +character_primary: + value_expression_primary { + $$.v = CharacterPrimary($1.v as ValueExpressionPrimary) + } +| string_value_function { + $$.v = CharacterPrimary($1.v as CharacterValueFunction) + } + + + +string_value_function: + character_value_function { $$.v = $1.v as CharacterValueFunction } + +character_value_function: + character_substring_function { + $$.v = CharacterValueFunction($1.v as CharacterSubstringFunction) + } +| fold { $$.v = CharacterValueFunction($1.v as RoutineInvocation) } +| trim_function { $$.v = CharacterValueFunction($1.v as TrimFunction) } + +character_substring_function: + SUBSTRING left_paren character_value_expression FROM start_position + right_paren { + $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, + $5.v as NumericValueExpression, none, 'CHARACTERS'} + } +| SUBSTRING left_paren character_value_expression FROM start_position FOR + string_length right_paren { + $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, + $5.v as NumericValueExpression, $7.v as NumericValueExpression, + 'CHARACTERS'} + } +| SUBSTRING left_paren character_value_expression FROM start_position USING + char_length_units right_paren { + $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, + $5.v as NumericValueExpression, none, $7.v as string} + } +| SUBSTRING left_paren character_value_expression FROM start_position FOR + string_length USING char_length_units right_paren { + $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, + $5.v as NumericValueExpression, $7.v as NumericValueExpression, + $9.v as string} + } + +fold: + UPPER left_paren character_value_expression right_paren { + $$.v = RoutineInvocation{'UPPER', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression))]} + } +| LOWER left_paren character_value_expression right_paren { + $$.v = RoutineInvocation{'LOWER', [ + ValueExpression(CommonValueExpression($3.v as CharacterValueExpression))]} + } + +trim_function: + TRIM left_paren trim_operands right_paren { $$.v = $3.v as TrimFunction } + +trim_operands: + trim_source { + space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) + $$.v = TrimFunction{'BOTH', space, $1.v as CharacterValueExpression} + } +| FROM trim_source { + space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) + $$.v = TrimFunction{'BOTH', space, $2.v as CharacterValueExpression} + } +| trim_specification FROM trim_source { + space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) + $$.v = TrimFunction{$1.v as string, space, $3.v as CharacterValueExpression} + } +| trim_character FROM trim_source { + $$.v = TrimFunction{'BOTH', $1.v as CharacterValueExpression, $3.v as CharacterValueExpression} + } +| trim_specification trim_character FROM trim_source { + $$.v = TrimFunction{$1.v as string, $2.v as CharacterValueExpression, $4.v as CharacterValueExpression} + } + +trim_source: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +trim_specification: + LEADING { $$.v = $1.v as string } +| TRAILING { $$.v = $1.v as string } +| BOTH { $$.v = $1.v as string } + +trim_character: + character_value_expression { $$.v = $1.v as CharacterValueExpression } + +start_position: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + +string_length: + numeric_value_expression { $$.v = $1.v as NumericValueExpression } + + + +datetime_value_expression: + datetime_term { $$.v = $1.v as DatetimePrimary } + +datetime_term: + datetime_factor { $$.v = $1.v as DatetimePrimary } + +datetime_factor: + datetime_primary { $$.v = $1.v as DatetimePrimary } + +// Note: datetime_primary is defined in grammar.y. See there for details. + + + +datetime_value_function: + current_date_value_function { + $$.v = DatetimeValueFunction($1.v as CurrentDate) + } +| current_time_value_function { + $$.v = DatetimeValueFunction($1.v as CurrentTime) + } +| current_timestamp_value_function { + $$.v = DatetimeValueFunction($1.v as CurrentTimestamp) + } +| current_local_time_value_function { + $$.v = DatetimeValueFunction($1.v as LocalTime) + } +| current_local_timestamp_value_function { + $$.v = DatetimeValueFunction($1.v as LocalTimestamp) + } + +current_date_value_function: + CURRENT_DATE { $$.v = CurrentDate{} } + +current_time_value_function: + CURRENT_TIME { $$.v = CurrentTime{default_time_precision} } +| CURRENT_TIME left_paren time_precision right_paren { + $$.v = CurrentTime{($3.v as string).int()} + } + +current_local_time_value_function: + LOCALTIME { $$.v = LocalTime{0} } +| LOCALTIME left_paren time_precision right_paren { + $$.v = LocalTime{($3.v as string).int()} + } + +current_timestamp_value_function: + CURRENT_TIMESTAMP { $$.v = CurrentTimestamp{default_timestamp_precision} } +| CURRENT_TIMESTAMP left_paren timestamp_precision right_paren { + $$.v = CurrentTimestamp{($3.v as string).int()} + } + +current_local_timestamp_value_function: + LOCALTIMESTAMP { $$.v = LocalTimestamp{6} } +| LOCALTIMESTAMP left_paren timestamp_precision right_paren { + $$.v = LocalTimestamp{($3.v as string).int()} + } + + boolean_value_expression: boolean_term { $$.v = BooleanValueExpression{term: $1.v as BooleanTerm} } @@ -2292,108 +2298,120 @@ boolean_primary: predicate { $$.v = BooleanPrimary($1.v as Predicate) } | boolean_predicand { $$.v = BooleanPrimary($1.v as BooleanPredicand) } -boolean_predicand: - parenthesized_boolean_value_expression { - $$.v = BooleanPredicand($1.v as BooleanValueExpression) +boolean_predicand: + parenthesized_boolean_value_expression { + $$.v = BooleanPredicand($1.v as BooleanValueExpression) + } +| nonparenthesized_value_expression_primary { + $$.v = BooleanPredicand($1.v as NonparenthesizedValueExpressionPrimary) + } + +parenthesized_boolean_value_expression: + left_paren boolean_value_expression right_paren { $$.v = $2.v } + + + +value_expression_primary: + parenthesized_value_expression { + $$.v = ValueExpressionPrimary($1.v as ParenthesizedValueExpression) + } +| nonparenthesized_value_expression_primary { + $$.v = ValueExpressionPrimary($1.v as NonparenthesizedValueExpressionPrimary) + } + +parenthesized_value_expression: + left_paren value_expression right_paren { + $$.v = ParenthesizedValueExpression{$2.v as ValueExpression} + } + +nonparenthesized_value_expression_primary: + unsigned_value_specification { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as ValueSpecification) + } +| column_reference { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as Identifier) + } +| set_function_specification { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as AggregateFunction) + } +| routine_invocation { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as RoutineInvocation) + } +| case_expression { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as CaseExpression) + } +| cast_specification { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as CastSpecification) + } +| next_value_expression { + $$.v = NonparenthesizedValueExpressionPrimary($1.v as NextValueExpression) + } + + + +value_specification: + literal { $$.v = ValueSpecification($1.v as Value) } +| general_value_specification { + $$.v = ValueSpecification($1.v as GeneralValueSpecification) } -| nonparenthesized_value_expression_primary { - $$.v = BooleanPredicand($1.v as NonparenthesizedValueExpressionPrimary) + +unsigned_value_specification: + unsigned_literal { $$.v = ValueSpecification($1.v as Value) } +| general_value_specification { + $$.v = ValueSpecification($1.v as GeneralValueSpecification) } -parenthesized_boolean_value_expression: - left_paren boolean_value_expression right_paren { $$.v = $2.v } +general_value_specification: + host_parameter_specification { $$.v = $1.v as GeneralValueSpecification } +| CURRENT_CATALOG { $$.v = GeneralValueSpecification(CurrentCatalog{}) } +| CURRENT_SCHEMA { $$.v = GeneralValueSpecification(CurrentSchema{}) } -unique_constraint_definition: - unique_specification left_paren unique_column_list right_paren { - $$.v = UniqueConstraintDefinition{$3.v as []Identifier} +simple_value_specification: + literal { $$.v = ValueSpecification($1.v as Value) } +| host_parameter_name { + $$.v = ValueSpecification($1.v as GeneralValueSpecification) } -unique_specification: - PRIMARY KEY +host_parameter_specification: + host_parameter_name { $$.v = $1.v as GeneralValueSpecification } -unique_column_list: - column_name_list { $$.v = $1.v as []Identifier } -table_row_value_expression: - row_value_constructor { $$.v = $1.v as RowValueConstructor } -contextually_typed_row_value_expression: - contextually_typed_row_value_constructor { - $$.v = $1.v as ContextuallyTypedRowValueConstructor - } +contextually_typed_value_specification: + implicitly_typed_value_specification { $$.v = $1.v as NullSpecification } -row_value_predicand: - row_value_constructor_predicand { - $$.v = $1.v as RowValueConstructorPredicand - } +implicitly_typed_value_specification: + null_specification { $$.v = $1.v as NullSpecification } -sql_schema_statement: - sql_schema_definition_statement { $$.v = $1.v as Stmt } -| sql_schema_manipulation_statement { $$.v = $1.v as Stmt } +null_specification: + NULL { $$.v = NullSpecification{} } -sql_schema_definition_statement: - schema_definition { $$.v = $1.v as Stmt } -| table_definition { $$.v = $1.v as Stmt } -| sequence_generator_definition { $$.v = Stmt($1.v as SequenceGeneratorDefinition) } -sql_schema_manipulation_statement: - drop_schema_statement { $$.v = $1.v as Stmt } -| drop_table_statement { $$.v = $1.v as Stmt } -| alter_sequence_generator_statement { $$.v = Stmt($1.v as AlterSequenceGeneratorStatement) } -| drop_sequence_generator_statement { $$.v = $1.v as Stmt } -sql_transaction_statement: - start_transaction_statement { $$.v = $1.v as Stmt } -| commit_statement { $$.v = $1.v as Stmt } -| rollback_statement { $$.v = $1.v as Stmt } +identifier_chain: + identifier { $$.v = $1.v as IdentifierChain } +| identifier period identifier { + $$.v = IdentifierChain{ + ($1.v as IdentifierChain).identifier + '.' + ($3.v as IdentifierChain).identifier + } + } -sql_session_statement: - set_schema_statement { $$.v = Stmt($1.v as SetSchemaStatement) } -| set_catalog_statement { $$.v = $1.v as Stmt } +basic_identifier_chain: + identifier_chain { $$.v = $1.v as IdentifierChain } -datetime_value_function: - current_date_value_function { - $$.v = DatetimeValueFunction($1.v as CurrentDate) - } -| current_time_value_function { - $$.v = DatetimeValueFunction($1.v as CurrentTime) - } -| current_timestamp_value_function { - $$.v = DatetimeValueFunction($1.v as CurrentTimestamp) - } -| current_local_time_value_function { - $$.v = DatetimeValueFunction($1.v as LocalTime) - } -| current_local_timestamp_value_function { - $$.v = DatetimeValueFunction($1.v as LocalTimestamp) - } -current_date_value_function: - CURRENT_DATE { $$.v = CurrentDate{} } -current_time_value_function: - CURRENT_TIME { $$.v = CurrentTime{default_time_precision} } -| CURRENT_TIME left_paren time_precision right_paren { - $$.v = CurrentTime{($3.v as string).int()} +column_reference: + basic_identifier_chain { + $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! } -current_local_time_value_function: - LOCALTIME { $$.v = LocalTime{0} } -| LOCALTIME left_paren time_precision right_paren { - $$.v = LocalTime{($3.v as string).int()} - } -current_timestamp_value_function: - CURRENT_TIMESTAMP { $$.v = CurrentTimestamp{default_timestamp_precision} } -| CURRENT_TIMESTAMP left_paren timestamp_precision right_paren { - $$.v = CurrentTimestamp{($3.v as string).int()} - } -current_local_timestamp_value_function: - LOCALTIMESTAMP { $$.v = LocalTimestamp{6} } -| LOCALTIMESTAMP left_paren timestamp_precision right_paren { - $$.v = LocalTimestamp{($3.v as string).int()} - } +set_function_specification: + aggregate_function { $$.v = $1.v as AggregateFunction } + + joined_table: qualified_join { $$.v = $1.v as QualifiedJoin } @@ -2413,24 +2431,81 @@ outer_join_type: LEFT { $$.v = $1.v as string } | RIGHT { $$.v = $1.v as string } -null_predicate: - row_value_predicand null_predicate_part_2 { - $$.v = NullPredicate{$1.v as RowValueConstructorPredicand, !($2.v as bool)} + + +where_clause: + WHERE search_condition { $$.v = $2.v as BooleanValueExpression } + + + +group_by_clause: + GROUP BY grouping_element_list { $$.v = $3.v } + +grouping_element_list: + grouping_element { $$.v = [$1.v as Identifier] } +| grouping_element_list comma grouping_element { + $$.v = append_list($1.v as []Identifier, $3.v as Identifier) } -null_predicate_part_2: - IS NULL { $$.v = true } -| IS NOT NULL { $$.v = false } +grouping_element: + ordinary_grouping_set { $$.v = $1.v as Identifier } + +ordinary_grouping_set: + grouping_column_reference { $$.v = $1.v as Identifier } + +grouping_column_reference: + column_reference { $$.v = $1.v as Identifier } + + + +query_specification: + SELECT select_list table_expression { + $$.v = QuerySpecification{ + exprs: $2.v as SelectList + table_expression: $3.v as TableExpression + } + } + +select_list: + asterisk { $$.v = SelectList(AsteriskExpr(true)) } +| select_sublist { $$.v = $1.v as SelectList } +| select_list comma select_sublist { + mut new_select_list := (($1.v as SelectList) as []DerivedColumn).clone() + new_select_list << (($3.v as SelectList) as []DerivedColumn)[0] + $$.v = SelectList(new_select_list) + } + +select_sublist: + derived_column { $$.v = SelectList([$1.v as DerivedColumn]) } +| qualified_asterisk { $$.v = SelectList($1.v as QualifiedAsteriskExpr) } + +// was: asterisked_identifier_chain period asterisk +qualified_asterisk: + asterisked_identifier_chain OPERATOR_PERIOD_ASTERISK { + $$.v = QualifiedAsteriskExpr{ + new_column_identifier(($1.v as IdentifierChain).identifier)! + } + } + +asterisked_identifier_chain: + asterisked_identifier { $$.v = $1.v as IdentifierChain } + +asterisked_identifier: + identifier { $$.v = $1.v as IdentifierChain } + +derived_column: + value_expression { + $$.v = DerivedColumn{$1.v as ValueExpression, Identifier{}} + } +| value_expression as_clause { + $$.v = DerivedColumn{$1.v as ValueExpression, $2.v as Identifier} + } + +as_clause: + AS column_name { $$.v = $2.v as Identifier } +| column_name { $$.v = $1.v as Identifier } -predicate: - comparison_predicate { $$.v = Predicate($1.v as ComparisonPredicate) } -| between_predicate { $$.v = Predicate($1.v as BetweenPredicate) } -| like_predicate { $$.v = Predicate($1.v as CharacterLikePredicate) } -| similar_predicate { $$.v = Predicate($1.v as SimilarPredicate) } -| null_predicate { $$.v = Predicate($1.v as NullPredicate) } -start_transaction_statement: - START TRANSACTION { $$.v = Stmt(StartTransactionStatement{}) } query_expression: query_expression_body { $$.v = QueryExpression{body: $1.v as SimpleTable} } @@ -2518,346 +2593,390 @@ row_or_rows: ROW | ROWS -similar_predicate: - row_value_predicand similar_predicate_part_2 { - like := $2.v as SimilarPredicate - $$.v = SimilarPredicate{$1.v as RowValueConstructorPredicand, like.right, like.not} + + +row_subquery: + subquery { $$.v = $1.v as QueryExpression } + +table_subquery: + subquery { $$.v = $1.v as TablePrimary } + +subquery: + left_paren query_expression right_paren { + $$.v = TablePrimary{ + body: $2.v as QueryExpression + } + } + + + +row_value_constructor: + common_value_expression { + $$.v = RowValueConstructor($1.v as CommonValueExpression) + } +| boolean_value_expression { + $$.v = RowValueConstructor($1.v as BooleanValueExpression) + } +| explicit_row_value_constructor { + $$.v = RowValueConstructor($1.v as ExplicitRowValueConstructor) + } + +explicit_row_value_constructor: + ROW left_paren row_value_constructor_element_list right_paren { + $$.v = ExplicitRowValueConstructor(ExplicitRowValueConstructorRow{$3.v as []ValueExpression}) + } +| row_subquery { $$.v = ExplicitRowValueConstructor($1.v as QueryExpression) } + +row_value_constructor_element_list: + row_value_constructor_element { $$.v = [$1.v as ValueExpression] } +| row_value_constructor_element_list comma row_value_constructor_element { + $$.v = append_list($1.v as []ValueExpression, $3.v as ValueExpression) + } + +row_value_constructor_element: + value_expression { $$.v = $1.v as ValueExpression } + +contextually_typed_row_value_constructor: + common_value_expression { + $$.v = ContextuallyTypedRowValueConstructor($1.v as CommonValueExpression) + } +| boolean_value_expression { + $$.v = ContextuallyTypedRowValueConstructor($1.v as BooleanValueExpression) + } +| contextually_typed_value_specification { + $$.v = ContextuallyTypedRowValueConstructor($1.v as NullSpecification) + } +| left_paren contextually_typed_value_specification right_paren { + $$.v = ContextuallyTypedRowValueConstructor($2.v as NullSpecification) + } +| left_paren contextually_typed_row_value_constructor_element comma + contextually_typed_row_value_constructor_element_list right_paren { + $$.v = ContextuallyTypedRowValueConstructor(push_list( + $2.v as ContextuallyTypedRowValueConstructorElement, + $4.v as []ContextuallyTypedRowValueConstructorElement)) + } + +contextually_typed_row_value_constructor_element_list: + contextually_typed_row_value_constructor_element { + $$.v = [$1.v as ContextuallyTypedRowValueConstructorElement] + } +| contextually_typed_row_value_constructor_element_list comma + contextually_typed_row_value_constructor_element { + $$.v = append_list($1.v as []ContextuallyTypedRowValueConstructorElement, + $3.v as ContextuallyTypedRowValueConstructorElement) } -similar_predicate_part_2: - SIMILAR TO similar_pattern { - $$.v = SimilarPredicate{none, $3.v as CharacterValueExpression, false} +contextually_typed_row_value_constructor_element: + value_expression { + $$.v = ContextuallyTypedRowValueConstructorElement($1.v as ValueExpression) } -| NOT SIMILAR TO similar_pattern { - $$.v = SimilarPredicate{none, $4.v as CharacterValueExpression, true} +| contextually_typed_value_specification { + $$.v = ContextuallyTypedRowValueConstructorElement($1.v as NullSpecification) } -similar_pattern: - character_value_expression { $$.v = $1.v as CharacterValueExpression } +row_value_constructor_predicand: + common_value_expression { + $$.v = RowValueConstructorPredicand($1.v as CommonValueExpression) + } +| boolean_predicand { + $$.v = RowValueConstructorPredicand($1.v as BooleanPredicand) + } -left_paren: OPERATOR_LEFT_PAREN -right_paren: OPERATOR_RIGHT_PAREN -asterisk: OPERATOR_ASTERISK { $$.v = $1.v as string } +table_row_value_expression: + row_value_constructor { $$.v = $1.v as RowValueConstructor } -plus_sign: OPERATOR_PLUS { $$.v = $1.v as string } +contextually_typed_row_value_expression: + contextually_typed_row_value_constructor { + $$.v = $1.v as ContextuallyTypedRowValueConstructor + } -comma: OPERATOR_COMMA +row_value_predicand: + row_value_constructor_predicand { + $$.v = $1.v as RowValueConstructorPredicand + } -minus_sign: OPERATOR_MINUS { $$.v = $1.v as string } -period: OPERATOR_PERIOD -solidus: OPERATOR_SOLIDUS { $$.v = $1.v as string } +table_value_constructor: + VALUES row_value_expression_list { + $$.v = SimpleTable($2.v as []RowValueConstructor) + } -colon: OPERATOR_COLON +row_value_expression_list: + table_row_value_expression { $$.v = [$1.v as RowValueConstructor] } +| row_value_expression_list comma table_row_value_expression { + $$.v = append_list($1.v as []RowValueConstructor, + $3.v as RowValueConstructor) + } -less_than_operator: OPERATOR_LESS_THAN +contextually_typed_table_value_constructor: + VALUES contextually_typed_row_value_expression_list { + $$.v = $2.v as []ContextuallyTypedRowValueConstructor + } -equals_operator: OPERATOR_EQUALS +contextually_typed_row_value_expression_list: + contextually_typed_row_value_expression { + $$.v = [$1.v as ContextuallyTypedRowValueConstructor] + } +| contextually_typed_row_value_expression_list comma + contextually_typed_row_value_expression { + $$.v = append_list($1.v as []ContextuallyTypedRowValueConstructor, + $3.v as ContextuallyTypedRowValueConstructor) + } -greater_than_operator: OPERATOR_GREATER_THAN -table_constraint_definition: - table_constraint { $$.v = $1.v as TableElement } -table_constraint: - unique_constraint_definition { - $$.v = TableElement($1.v as UniqueConstraintDefinition) +table_expression: + from_clause { + $$.v = TableExpression{$1.v as TableReference, none, []Identifier{}} } - -column_definition: - column_name data_type_or_domain_name { - $$.v = TableElement(Column{$1.v as Identifier, $2.v as Type, false}) +| from_clause where_clause { + $$.v = TableExpression{ + $1.v as TableReference + $2.v as BooleanValueExpression + []Identifier{} + } } -| column_name data_type_or_domain_name column_constraint_definition { - $$.v = TableElement(Column{$1.v as Identifier, $2.v as Type, $3.v as bool}) +| from_clause group_by_clause { + $$.v = TableExpression{$1.v as TableReference, none, $2.v as []Identifier} + } +| from_clause where_clause group_by_clause { + $$.v = TableExpression{ + $1.v as TableReference + $2.v as BooleanValueExpression + $3.v as []Identifier + } } -data_type_or_domain_name: - data_type { $$.v = $1.v as Type } -column_constraint_definition: - column_constraint { $$.v = $1.v as bool } -column_constraint: - NOT NULL { $$.v = true } +from_clause: + FROM table_reference_list { $$.v = $2.v as TableReference } -set_schema_statement: - SET schema_name_characteristic { - $$.v = SetSchemaStatement{$2.v as ValueSpecification} - } +table_reference_list: + table_reference { $$.v = $1.v as TableReference } -schema_name_characteristic: - SCHEMA value_specification { $$.v = $2.v } -// was: COUNT left_paren asterisk right_paren -aggregate_function: - COUNT OPERATOR_LEFT_PAREN_ASTERISK right_paren { - $$.v = AggregateFunction(AggregateFunctionCount{}) - } -| general_set_function { $$.v = $1.v as AggregateFunction } -general_set_function: - set_function_type left_paren value_expression right_paren { - $$.v = AggregateFunction(RoutineInvocation{ - $1.v as string, [$3.v as ValueExpression]}) +table_reference: + table_factor { $$.v = TableReference($1.v as TablePrimary) } +| joined_table { $$.v = TableReference($1.v as QualifiedJoin) } + +qualified_join: + table_reference JOIN table_reference join_specification { + $$.v = QualifiedJoin{ + $1.v as TableReference + 'INNER' + $3.v as TableReference + $4.v as BooleanValueExpression + } + } +| table_reference join_type JOIN table_reference join_specification { + $$.v = QualifiedJoin{ + $1.v as TableReference + $2.v as string + $4.v as TableReference + $5.v as BooleanValueExpression + } } -set_function_type: - computational_operation { $$.v = $1.v as string } +table_factor: + table_primary { $$.v = $1.v as TablePrimary } -computational_operation: - AVG { $$.v = $1.v as string } -| MAX { $$.v = $1.v as string } -| MIN { $$.v = $1.v as string } -| SUM { $$.v = $1.v as string } -| COUNT { $$.v = $1.v as string } +table_primary: + table_or_query_name { + $$.v = TablePrimary{ + body: $1.v as Identifier + } + } +| derived_table { $$.v = $1.v as TablePrimary } +| derived_table correlation_or_recognition { + $$.v = TablePrimary{ + body: ($1.v as TablePrimary).body + correlation: $2.v as Correlation + } + } -set_catalog_statement: - SET catalog_name_characteristic { - $$.v = Stmt(SetCatalogStatement{$2.v as ValueSpecification}) +correlation_or_recognition: + correlation_name { + $$.v = Correlation{ + name: $1.v as Identifier + } + } +| AS correlation_name { + $$.v = Correlation{ + name: $2.v as Identifier + } + } +| correlation_name parenthesized_derived_column_list { + $$.v = Correlation{ + name: $1.v as Identifier + columns: $2.v as []Identifier + } + } +| AS correlation_name parenthesized_derived_column_list { + $$.v = Correlation{ + name: $2.v as Identifier + columns: $3.v as []Identifier + } } -catalog_name_characteristic: - CATALOG value_specification { $$.v = $2.v as ValueSpecification } +derived_table: + table_subquery { $$.v = $1.v as TablePrimary } -drop_table_statement: - DROP TABLE table_name { $$.v = Stmt(DropTableStatement{$3.v as Identifier}) } +table_or_query_name: + table_name { $$.v = $1.v as Identifier } -value_specification: - literal { $$.v = ValueSpecification($1.v as Value) } -| general_value_specification { - $$.v = ValueSpecification($1.v as GeneralValueSpecification) - } +derived_column_list: + column_name_list { $$.v = $1.v as []Identifier } -unsigned_value_specification: - unsigned_literal { $$.v = ValueSpecification($1.v as Value) } -| general_value_specification { - $$.v = ValueSpecification($1.v as GeneralValueSpecification) +column_name_list: + column_name { $$.v = [$1.v as Identifier] } +| column_name_list comma column_name { + $$.v = append_list($1.v as []Identifier, $3.v as Identifier) } -general_value_specification: - host_parameter_specification { $$.v = $1.v as GeneralValueSpecification } -| CURRENT_CATALOG { $$.v = GeneralValueSpecification(CurrentCatalog{}) } -| CURRENT_SCHEMA { $$.v = GeneralValueSpecification(CurrentSchema{}) } +parenthesized_derived_column_list: + left_paren derived_column_list right_paren { $$.v = $2.v } -simple_value_specification: - literal { $$.v = ValueSpecification($1.v as Value) } -| host_parameter_name { - $$.v = ValueSpecification($1.v as GeneralValueSpecification) - } -host_parameter_specification: - host_parameter_name { $$.v = $1.v as GeneralValueSpecification } -insert_statement: - INSERT INTO insertion_target insert_columns_and_source { - stmt := $4.v as InsertStatement - $$.v = Stmt(InsertStatement{$3.v as Identifier, stmt.columns, stmt.values}) - } +predicate: + comparison_predicate { $$.v = Predicate($1.v as ComparisonPredicate) } +| between_predicate { $$.v = Predicate($1.v as BetweenPredicate) } +| like_predicate { $$.v = Predicate($1.v as CharacterLikePredicate) } +| similar_predicate { $$.v = Predicate($1.v as SimilarPredicate) } +| null_predicate { $$.v = Predicate($1.v as NullPredicate) } -insertion_target: - table_name { $$.v = $1.v as Identifier } -insert_columns_and_source: - from_constructor { $$.v = $1.v as InsertStatement } -from_constructor: - left_paren insert_column_list right_paren - contextually_typed_table_value_constructor { - $$.v = InsertStatement{ - columns: $2.v as []Identifier - values: $4.v as []ContextuallyTypedRowValueConstructor - } - } +search_condition: + boolean_value_expression { $$.v = $1.v as BooleanValueExpression } -insert_column_list: - column_name_list { $$.v = $1.v as []Identifier } -value_expression_primary: - parenthesized_value_expression { - $$.v = ValueExpressionPrimary($1.v as ParenthesizedValueExpression) - } -| nonparenthesized_value_expression_primary { - $$.v = ValueExpressionPrimary($1.v as NonparenthesizedValueExpressionPrimary) - } -parenthesized_value_expression: - left_paren value_expression right_paren { - $$.v = ParenthesizedValueExpression{$2.v as ValueExpression} +comparison_predicate: + row_value_predicand comparison_predicate_part_2 { + comp := $2.v as ComparisonPredicatePart2 + $$.v = ComparisonPredicate{ + $1.v as RowValueConstructorPredicand + comp.op + comp.expr + } } -nonparenthesized_value_expression_primary: - unsigned_value_specification { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as ValueSpecification) - } -| column_reference { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as Identifier) - } -| set_function_specification { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as AggregateFunction) - } -| routine_invocation { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as RoutineInvocation) - } -| case_expression { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as CaseExpression) - } -| cast_specification { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as CastSpecification) - } -| next_value_expression { - $$.v = NonparenthesizedValueExpressionPrimary($1.v as NextValueExpression) +comparison_predicate_part_2: + comp_op row_value_predicand { + $$.v = ComparisonPredicatePart2{ + $1.v as string + $2.v as RowValueConstructorPredicand + } } -string_value_function: - character_value_function { $$.v = $1.v as CharacterValueFunction } +comp_op: + equals_operator { $$.v = $1.v as string } +| not_equals_operator { $$.v = $1.v as string } +| less_than_operator { $$.v = $1.v as string } +| greater_than_operator { $$.v = $1.v as string } +| less_than_or_equals_operator { $$.v = $1.v as string } +| greater_than_or_equals_operator { $$.v = $1.v as string } -character_value_function: - character_substring_function { - $$.v = CharacterValueFunction($1.v as CharacterSubstringFunction) - } -| fold { $$.v = CharacterValueFunction($1.v as RoutineInvocation) } -| trim_function { $$.v = CharacterValueFunction($1.v as TrimFunction) } -character_substring_function: - SUBSTRING left_paren character_value_expression FROM start_position - right_paren { - $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, - $5.v as NumericValueExpression, none, 'CHARACTERS'} - } -| SUBSTRING left_paren character_value_expression FROM start_position FOR - string_length right_paren { - $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, - $5.v as NumericValueExpression, $7.v as NumericValueExpression, - 'CHARACTERS'} - } -| SUBSTRING left_paren character_value_expression FROM start_position USING - char_length_units right_paren { - $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, - $5.v as NumericValueExpression, none, $7.v as string} - } -| SUBSTRING left_paren character_value_expression FROM start_position FOR - string_length USING char_length_units right_paren { - $$.v = CharacterSubstringFunction{$3.v as CharacterValueExpression, - $5.v as NumericValueExpression, $7.v as NumericValueExpression, - $9.v as string} - } -fold: - UPPER left_paren character_value_expression right_paren { - $$.v = RoutineInvocation{'UPPER', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression))]} - } -| LOWER left_paren character_value_expression right_paren { - $$.v = RoutineInvocation{'LOWER', [ - ValueExpression(CommonValueExpression($3.v as CharacterValueExpression))]} +between_predicate: + row_value_predicand between_predicate_part_2 { + between := $2.v as BetweenPredicate + $$.v = BetweenPredicate{ + not: between.not + symmetric: between.symmetric + expr: $1.v as RowValueConstructorPredicand + left: between.left + right: between.right + } } -trim_function: - TRIM left_paren trim_operands right_paren { $$.v = $3.v as TrimFunction } - -trim_operands: - trim_source { - space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) - $$.v = TrimFunction{'BOTH', space, $1.v as CharacterValueExpression} - } -| FROM trim_source { - space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) - $$.v = TrimFunction{'BOTH', space, $2.v as CharacterValueExpression} - } -| trim_specification FROM trim_source { - space := CharacterValueExpression(CharacterPrimary(ValueExpressionPrimary(NonparenthesizedValueExpressionPrimary(ValueSpecification(new_varchar_value(' ')))))) - $$.v = TrimFunction{$1.v as string, space, $3.v as CharacterValueExpression} - } -| trim_character FROM trim_source { - $$.v = TrimFunction{'BOTH', $1.v as CharacterValueExpression, $3.v as CharacterValueExpression} +between_predicate_part_2: + between_predicate_part_1 row_value_predicand AND row_value_predicand { + $$.v = BetweenPredicate{ + not: !($1.v as bool) + symmetric: false + left: $2.v as RowValueConstructorPredicand + right: $4.v as RowValueConstructorPredicand + } } -| trim_specification trim_character FROM trim_source { - $$.v = TrimFunction{$1.v as string, $2.v as CharacterValueExpression, $4.v as CharacterValueExpression} +| between_predicate_part_1 is_symmetric row_value_predicand AND + row_value_predicand { + $$.v = BetweenPredicate{ + not: !($1.v as bool) + symmetric: $2.v as bool + left: $3.v as RowValueConstructorPredicand + right: $5.v as RowValueConstructorPredicand + } } -trim_source: - character_value_expression { $$.v = $1.v as CharacterValueExpression } +between_predicate_part_1: + BETWEEN { $$.v = true } +| NOT BETWEEN { $$.v = false } -trim_specification: - LEADING { $$.v = $1.v as string } -| TRAILING { $$.v = $1.v as string } -| BOTH { $$.v = $1.v as string } +is_symmetric: + SYMMETRIC { $$.v = true } +| ASYMMETRIC { $$.v = false } -trim_character: - character_value_expression { $$.v = $1.v as CharacterValueExpression } -start_position: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } -string_length: - numeric_value_expression { $$.v = $1.v as NumericValueExpression } +like_predicate: + character_like_predicate { $$.v = $1.v as CharacterLikePredicate } -numeric_value_expression: - term { $$.v = NumericValueExpression{term: $1.v as Term} } -| numeric_value_expression plus_sign term { - n := $1.v as NumericValueExpression - $$.v = NumericValueExpression{&n, '+', $3.v as Term} - } -| numeric_value_expression minus_sign term { - n := $1.v as NumericValueExpression - $$.v = NumericValueExpression{&n, '-', $3.v as Term} +character_like_predicate: + row_value_predicand character_like_predicate_part_2 { + like := $2.v as CharacterLikePredicate + $$.v = CharacterLikePredicate{ + $1.v as RowValueConstructorPredicand + like.right + like.not + } } -term: - factor { $$.v = Term{factor: $1.v as NumericPrimary} } -| term asterisk factor { - t := $1.v as Term - $$.v = Term{&t, '*', $3.v as NumericPrimary} +character_like_predicate_part_2: + LIKE character_pattern { + $$.v = CharacterLikePredicate{none, $2.v as CharacterValueExpression, false} } -| term solidus factor { - t := $1.v as Term - $$.v = Term{&t, '/', $3.v as NumericPrimary} +| NOT LIKE character_pattern { + $$.v = CharacterLikePredicate{none, $3.v as CharacterValueExpression, true} } -factor: - numeric_primary { $$.v = $1.v as NumericPrimary } -| sign numeric_primary { - $$.v = parse_factor_2($1.v as string, $2.v as NumericPrimary)! - } +character_pattern: + character_value_expression { $$.v = $1.v as CharacterValueExpression } -numeric_primary: - value_expression_primary { - $$.v = NumericPrimary($1.v as ValueExpressionPrimary) - } -| numeric_value_function { $$.v = NumericPrimary($1.v as RoutineInvocation) } -routine_invocation: - routine_name sql_argument_list { - $$.v = RoutineInvocation{($1.v as Identifier).entity_name, $2.v as []ValueExpression} - } -routine_name: - qualified_identifier { - $$.v = new_function_identifier(($1.v as IdentifierChain).identifier)! +similar_predicate: + row_value_predicand similar_predicate_part_2 { + like := $2.v as SimilarPredicate + $$.v = SimilarPredicate{$1.v as RowValueConstructorPredicand, like.right, like.not} } -sql_argument_list: - left_paren right_paren { $$.v = []ValueExpression{} } -| left_paren sql_argument right_paren { $$.v = [$2.v as ValueExpression] } -| left_paren sql_argument_list comma sql_argument right_paren { - $$.v = append_list($2.v as []ValueExpression, $4.v as ValueExpression) +similar_predicate_part_2: + SIMILAR TO similar_pattern { + $$.v = SimilarPredicate{none, $3.v as CharacterValueExpression, false} + } +| NOT SIMILAR TO similar_pattern { + $$.v = SimilarPredicate{none, $4.v as CharacterValueExpression, true} } -sql_argument: - value_expression { $$.v = $1.v as ValueExpression } +similar_pattern: + character_value_expression { $$.v = $1.v as CharacterValueExpression } -column_reference: - basic_identifier_chain { - $$.v = new_column_identifier(($1.v as IdentifierChain).identifier)! +null_predicate: + row_value_predicand null_predicate_part_2 { + $$.v = NullPredicate{$1.v as RowValueConstructorPredicand, !($2.v as bool)} } - +null_predicate_part_2: + IS NULL { $$.v = true } +| IS NOT NULL { $$.v = false } %% - -