def make_symbol(cls, raw, seg_type, name=None): """Make a symbol segment.""" # For the name of the segment, we force the string to lowercase. symbol_seg = SymbolSegment.make(raw.lower(), name=name or seg_type, type=seg_type) # At the moment we let the rule dictate *case* here. return symbol_seg(raw=raw, pos_marker=None)
snowflake_dialect.sets("reserved_keywords").update([ "CLONE", "MASKING", "NOTIFICATION", "PIVOT", "SAMPLE", "TABLESAMPLE", "UNPIVOT", ]) snowflake_dialect.add( # In snowflake, these are case sensitive even though they're not quoted # so they need a different `name` and `type` so they're not picked up # by other rules. ParameterAssignerSegment=SymbolSegment.make("=>", name="parameter_assigner", type="parameter_assigner"), NakedSemiStructuredElementSegment=ReSegment.make( r"[A-Z0-9_]*", name="naked_semi_structured_element", type="semi_structured_element", ), QuotedSemiStructuredElementSegment=NamedSegment.make( "double_quote", name="quoted_semi_structured_element", type="semi_structured_element", ), ColumnIndexIdentifierSegment=ReSegment.make( r"\$[0-9]+", name="column_index_identifier_segment", type="identifier"), )
exasol_fs_dialect.add( FunctionScriptTerminatorSegment=NamedSegment.make( "function_script_terminator", type="statement_terminator" ), WalrusOperatorSegment=NamedSegment.make( "walrus_operator", type="assignment_operator" ), VariableNameSegment=ReSegment.make( r"[A-Z][A-Z0-9_]*", name="function_variable", type="variable", ), ) exasol_fs_dialect.replace( SemicolonSegment=SymbolSegment.make(";", name="semicolon", type="semicolon"), ) @exasol_fs_dialect.segment(replace=True) class StatementSegment(BaseSegment): """A generic segment, to any of its child subsegments.""" type = "statement" match_grammar = GreedyUntil(Ref("FunctionScriptTerminatorSegment")) parse_grammar = OneOf( Ref("CreateFunctionStatementSegment"), Ref("CreateScriptingLuaScriptStatementSegment"), Ref("CreateUDFScriptStatementSegment"), Ref("CreateAdapterScriptStatementSegment"),
), ] + exasol_fs_dialect.get_lexer_struct()) exasol_fs_dialect.add( FunctionScriptTerminatorSegment=NamedSegment.make( "function_script_terminator", type="statement_terminator"), WalrusOperatorSegment=NamedSegment.make("walrus_operator", type="assignment_operator"), VariableNameSegment=ReSegment.make( r"[A-Z][A-Z0-9_]*", name="function_variable", type="variable", ), ) exasol_fs_dialect.replace(SemicolonSegment=SymbolSegment.make( ";", name="semicolon", type="semicolon"), ) @exasol_fs_dialect.segment(replace=True) class StatementSegment(BaseSegment): """A generic segment, to any of its child subsegments.""" type = "statement" match_grammar = GreedyUntil(Ref("FunctionScriptTerminatorSegment")) parse_grammar = OneOf( Ref("CreateFunctionStatementSegment"), Ref("CreateScriptingLuaScriptStatementSegment"), Ref("CreateUDFScriptStatementSegment"), Ref("CreateAdapterScriptStatementSegment"), )