Module: Textbringer::TreeSitter::NodeMaps
- Defined in:
- lib/textbringer/tree_sitter/node_maps.rb,
lib/textbringer/tree_sitter/node_maps/c.rb,
lib/textbringer/tree_sitter/node_maps/hcl.rb,
lib/textbringer/tree_sitter/node_maps/php.rb,
lib/textbringer/tree_sitter/node_maps/sql.rb,
lib/textbringer/tree_sitter/node_maps/bash.rb,
lib/textbringer/tree_sitter/node_maps/haml.rb,
lib/textbringer/tree_sitter/node_maps/html.rb,
lib/textbringer/tree_sitter/node_maps/java.rb,
lib/textbringer/tree_sitter/node_maps/json.rb,
lib/textbringer/tree_sitter/node_maps/ruby.rb,
lib/textbringer/tree_sitter/node_maps/rust.rb,
lib/textbringer/tree_sitter/node_maps/yaml.rb,
lib/textbringer/tree_sitter/node_maps/cobol.rb,
lib/textbringer/tree_sitter/node_maps/swift.rb,
lib/textbringer/tree_sitter/node_maps/csharp.rb,
lib/textbringer/tree_sitter/node_maps/elixir.rb,
lib/textbringer/tree_sitter/node_maps/groovy.rb,
lib/textbringer/tree_sitter/node_maps/pascal.rb,
lib/textbringer/tree_sitter/node_maps/python.rb,
lib/textbringer/tree_sitter/node_maps/crystal.rb,
lib/textbringer/tree_sitter/node_maps/javascript.rb
Constant Summary collapse
- C_FEATURES =
{ comment: %i[ comment block_comment line_comment ], string: %i[ string_literal string_content char_literal character system_lib_string concatenated_string escape_sequence ], keyword: %i[ if else for while do switch case default break continue return goto struct union enum typedef sizeof static extern const volatile inline register auto restrict long short signed unsigned void asm __asm __asm__ __attribute __attribute__ __extension__ __restrict__ __volatile__ __inline __inline__ __thread _Alignas _Alignof _Atomic _Generic _Nonnull _Noreturn _unaligned __alignof __alignof__ __based __cdecl __clrcall __declspec __except __fastcall __finally __forceinline __leave __stdcall __thiscall __try __unaligned __vectorcall alignas alignof constexpr noreturn thread_local true false nullptr ], number: %i[ number_literal binary_integer_literal octal_integer_literal decimal_integer_literal hex_integer_literal ], constant: %i[ null NULL ], function_name: %i[ function_declarator function_definition call_expression ], variable: %i[identifier], type: %i[ primitive_type type_identifier sized_type_specifier type_descriptor type_definition type_specifier type_qualifier storage_class_specifier pointer_type array_type struct_specifier union_specifier enum_specifier macro_type_specifier attributed_declarator ], operator: %i[ binary_expression unary_expression update_expression cast_expression pointer_expression assignment_expression conditional_expression comma_expression sizeof_expression alignof_expression offsetof_expression subscript_expression ], punctuation: %i[], builtin: %i[ offsetof defined ], property: %i[ field_identifier field_declaration field_declaration_list field_designator field_expression initializer_list initializer_pair compound_literal_expression declaration declaration_list init_declarator parameter_declaration parameter_list variadic_parameter abstract_array_declarator abstract_function_declarator abstract_parenthesized_declarator abstract_pointer_declarator array_declarator parenthesized_declarator pointer_declarator argument_list block_item compound_statement statement expression_statement labeled_statement if_statement switch_statement switch_block_statement_group case_statement do_statement while_statement for_statement break_statement continue_statement return_statement goto_statement expression parenthesized_expression attributed_statement linkage_specification preproc_call preproc_def preproc_function_def preproc_params preproc_arg preproc_directive preproc_if preproc_ifdef preproc_include preproc_elif preproc_elifdef preproc_else preproc_defined ms_based_modifier ms_call_modifier ms_declspec_modifier ms_pointer_modifier ms_restrict_modifier ms_signed_ptr_modifier ms_unaligned_ptr_modifier ms_unsigned_ptr_modifier seh_try_statement seh_except_clause seh_finally_clause seh_leave_statement gnu_asm_expression gnu_asm_qualifier gnu_asm_clobber_list gnu_asm_goto_list gnu_asm_input_operand gnu_asm_input_operand_list gnu_asm_output_operand gnu_asm_output_operand_list translation_unit statement_identifier attribute attribute_declaration attribute_specifier enumerator enumerator_list bitfield_clause subscript_designator subscript_range_designator ] }.freeze
- C =
C_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- HCL_FEATURES =
HCL (HashiCorp Configuration Language) feature-based node mapping Correctly handles for, in, function_call which Rouge's Terraform lexer fails to recognize
{ comment: %i[comment], string: %i[ string_literal quoted_template heredoc template_expr escape_sequence ], keyword: %i[ for in if true false null ], number: %i[numeric_literal], constant: %i[], function_name: %i[function_call], variable: %i[ identifier variable_expr ], type: %i[], operator: %i[ binary_op unary_op operation conditional ], punctuation: %i[], builtin: %i[], property: %i[ attribute block body one_line_block object object_elem collection_value tuple literal_value expr_term expression for_expr for_intro for_cond source_file get_attr index splat splat_attr splat_full ] }.freeze
- HCL =
Expand Feature -> Face mapping
HCL_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- PHP_FEATURES =
{ comment: %i[comment], string: %i[ string encapsed_string heredoc nowdoc shell_command_expression ], keyword: %i[ if else elseif endif for foreach endforeach while endwhile do switch case default endswitch break continue return throw try catch finally function fn class interface trait extends implements namespace use as const public private protected static final abstract readonly new clone instanceof insteadof global echo print include include_once require require_once goto yield match enum ], number: %i[ integer float ], constant: %i[], function_name: %i[], variable: %i[ variable_name name ], type: %i[ primitive_type named_type ], operator: %i[], punctuation: %i[], builtin: %i[ true false null ], property: %i[] }.freeze
- PHP =
PHP_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- SQL_FEATURES =
{ keyword: %i[ SELECT FROM WHERE JOIN LEFT RIGHT INNER OUTER FULL NATURAL CROSS ON AND OR NOT IN IS NULL BETWEEN INSERT INTO VALUES UPDATE SET DELETE CREATE DROP ALTER TABLE INDEX VIEW SCHEMA DATABASE PRIMARY_KEY UNIQUE CHECK CONSTRAINT REFERENCES GROUP_BY ORDER_BY HAVING LIMIT OFFSET FETCH UNION INTERSECT EXCEPT ALL DISTINCT AS ASC DESC NULLS FIRST LAST CASE WHEN THEN ELSE END BEGIN COMMIT ROLLBACK TRANSACTION IF EXISTS TRUE FALSE DEFAULT WITH RECURSIVE GRANT REVOKE PRIVILEGES RETURNS RETURN FUNCTION PROCEDURE FOR EACH ROW TRIGGER CASCADE RESTRICT VOLATILE STABLE IMMUTABLE DECLARE EXECUTE like ], comment: %i[comment line_comment block_comment], string: %i[content], number: %i[number], type: %i[], function_name: %i[], variable: %i[identifier], operator: %i[], punctuation: %i[], constant: %i[], builtin: %i[], property: %i[], }.freeze
- SQL =
SQL_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- BASH_FEATURES =
{ comment: %i[comment], string: %i[ string string_content raw_string heredoc_body heredoc_content heredoc_start heredoc_end ansi_c_string translated_string ], keyword: %i[ if then else elif fi for while until do done case esac in function select declare local readonly export unset unsetenv typeset ], number: %i[number], constant: %i[], function_name: %i[ function_definition command command_name ], variable: %i[ variable_name special_variable_name variable_assignment variable_assignments ], type: %i[], operator: %i[ file_redirect heredoc_redirect herestring_redirect test_operator binary_expression unary_expression ternary_expression postfix_expression ], punctuation: %i[], builtin: %i[ test_command command_substitution process_substitution expansion simple_expansion arithmetic_expansion brace_expression ], property: %i[ array program redirected_statement for_statement c_style_for_statement while_statement if_statement elif_clause else_clause case_statement case_item pipeline list negated_command declaration_command unset_command compound_statement subshell parenthesized_expression concatenation do_group word regex extglob_pattern subscript file_descriptor ] }.freeze
- BASH =
BASH_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- HAML_FEATURES =
{ comment: %i[comment], string: %i[ string string_content ], keyword: %i[doctype], number: %i[], constant: %i[], function_name: %i[], variable: %i[], type: %i[], operator: %i[], punctuation: %i[], builtin: %i[], property: %i[ tag_name id class attribute_name ] }.freeze
- HAML =
HAML_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- HTML_FEATURES =
{ comment: %i[comment], string: %i[ attribute_value quoted_attribute_value text raw_text ], keyword: %i[doctype], number: %i[], constant: %i[entity], function_name: %i[], variable: %i[], type: %i[], operator: %i[], punctuation: %i[], builtin: %i[], property: %i[ document element script_element style_element start_tag end_tag self_closing_tag erroneous_end_tag tag_name attribute attribute_name erroneous_end_tag_name ] }.freeze
- HTML =
HTML_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- JAVA_FEATURES =
{ comment: %i[ comment line_comment block_comment ], string: %i[ string_literal string_fragment multiline_string_fragment character_literal string_interpolation template_expression escape_sequence ], keyword: %i[ if else for while do switch case default break continue return throw try catch finally class interface enum record extends implements import package public private protected static final abstract synchronized native transient volatile strictfp new this super instanceof void assert throws permits sealed non var yield byte short int long char float double boolean when module open requires exports opens to uses provides with transitive ], number: %i[ decimal_integer_literal hex_integer_literal octal_integer_literal binary_integer_literal decimal_floating_point_literal hex_floating_point_literal _literal ], constant: %i[ null_literal boolean_literal ], function_name: %i[ method_declaration method_invocation constructor_declaration compact_constructor_declaration ], variable: %i[ identifier scoped_identifier ], type: %i[ type_identifier void_type integral_type floating_point_type boolean_type scoped_type_identifier generic_type array_type wildcard annotated_type _type _unannotated_type _simple_type ], operator: %i[ binary_expression unary_expression update_expression cast_expression instanceof_expression ternary_expression assignment_expression lambda_expression method_reference ], punctuation: %i[ asterisk ], builtin: %i[ true false null ], property: %i[ program package_declaration import_declaration asterisk class_declaration class_body modifiers type_parameters type_parameter type_bound superclass super_interfaces interface_body interface_declaration annotation_type_declaration annotation_type_body annotation_type_element_declaration enum_declaration enum_body enum_constant enum_body_declarations record_declaration field_declaration record_declaration annotation marker_annotation annotation_argument_list element_value_pair element_value_array_initializer method_declaration formal_parameters formal_parameter spread_parameter receiver_parameter local_variable_declaration variable_declarator dimensions block expression_statement labeled_statement assert_statement if_statement while_statement for_statement enhanced_for_statement break_statement continue_statement return_statement yield_statement synchronized_statement throw_statement try_statement catch_clause catch_formal_parameter catch_type finally_clause try_with_resources_statement resource_specification resource switch_statement switch_block switch_block_statement_group switch_rule switch_label switch_expression statement expression primary_expression array_creation_expression dimensions_expr parenthesized_expression class_literal object_creation_expression field_access array_access argument_list type_arguments wildcard_bounds inferred_parameters constant_declaration _declaration module_declaration module_body module_directive requires_module_directive requires_modifier exports_module_directive opens_module_directive uses_module_directive provides_module_directive type_list type_pattern guard pattern record_pattern record_pattern_body record_pattern_component underscore_pattern ] }.freeze
- JAVA =
JAVA_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- JSON_FEATURES =
JSON_LANG - named to avoid conflict with Ruby's JSON module
{ comment: %i[comment], string: %i[ string string_content escape_sequence ], keyword: %i[], number: %i[number], constant: %i[], function_name: %i[], variable: %i[], type: %i[], operator: %i[], punctuation: %i[], builtin: %i[ true false null ], property: %i[ pair array object document ] }.freeze
- JSON_LANG =
JSON_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- RUBY_FEATURES =
Feature-based node mapping Classified by feature, similar to Emacs treesit-font-lock-rules
{ comment: %i[comment], string: %i[ string_content heredoc_content heredoc_body heredoc_beginning heredoc_end simple_symbol delimited_symbol bare_symbol hash_key_symbol bare_string escape_sequence character regex uninterpreted ], keyword: %i[ def end class module if else elsif unless case when then while until for do break next redo retry return yield begin rescue ensure and or not in alias undef defined? self super BEGIN END lambda ], number: %i[integer float complex rational], constant: %i[ constant encoding file line ], function_name: %i[], variable: %i[ identifier instance_variable class_variable global_variable forward_argument forward_parameter ], type: %i[], operator: %i[ operator ], punctuation: %i[ empty_statement ], builtin: %i[nil true false hash_splat_nil], property: %i[] }.freeze
- RUBY =
Expand Feature -> Face mapping
RUBY_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- RUST_FEATURES =
{ comment: %i[ line_comment block_comment doc_comment inner_doc_comment_marker outer_doc_comment_marker shebang ], string: %i[ string_literal string_content char_literal raw_string_literal escape_sequence ], keyword: %i[ if else for while loop break continue return fn let mut const static struct enum union impl trait type mod use pub crate self super as in ref move dyn async await match where unsafe extern default try gen raw yield abstract become box do final macro override priv typeof unsized virtual ], number: %i[ integer_literal float_literal boolean_literal ], constant: %i[], function_name: %i[ function_item function_signature_item call_expression generic_function macro_invocation macro_definition ], variable: %i[ identifier ident shorthand_field_identifier ], type: %i[ type_identifier primitive_type generic_type generic_type_with_turbofish abstract_type array_type tuple_type unit_type reference_type pointer_type function_type never_type dynamic_type bounded_type scoped_type_identifier qualified_type removed_trait_bound type_cast_expression ], operator: %i[ binary_expression unary_expression assignment_expression compound_assignment_expr range_expression try_expression await_expression field_expression reference_expression ], punctuation: %i[], builtin: %i[ true false ], property: %i[ field_identifier field_declaration field_declaration_list field_expression field_initializer field_initializer_list field_pattern base_field_initializer shorthand_field_initializer ordered_field_declaration_list tuple_expression tuple_pattern tuple_struct_pattern struct_expression struct_item struct_pattern enum_item enum_variant enum_variant_list impl_item trait_item trait_bounds type_arguments type_binding type_item type_parameter type_parameters const_item const_parameter const_block static_item mod_item use_declaration use_as_clause use_list use_wildcard scoped_use_list use_bounds extern_crate_declaration foreign_mod_item visibility_modifier mutable_specifier extern_modifier function_modifiers lifetime lifetime_parameter where_clause where_predicate higher_ranked_trait_bound for_lifetimes bracketed_type arguments parameter parameters self_parameter variadic_parameter closure_expression closure_parameters block declaration_list match_expression match_block match_arm match_pattern if_expression if_let_expression loop_expression for_expression while_expression while_let_expression break_expression continue_expression return_expression yield_expression call_expression array_expression index_expression parenthesized_expression unit_expression let_declaration let_condition let_chain async_block gen_block unsafe_block try_block const_block labeled_statement empty_statement expression_statement attribute attribute_item inner_attribute_item meta metavariable token_tree token_tree_pattern token_binding_pattern token_repetition token_repetition_pattern fragment_specifier macro_rule pattern or_pattern range_pattern ref_pattern reference_pattern remaining_field_pattern mut_pattern slice_pattern captured_pattern literal_pattern negative_literal discard declaration declaration_statement source_file statement compound_statement item expression literal primary_expression lvalue_expression non_lvalue_expression ] }.freeze
- RUST =
RUST_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- YAML_FEATURES =
YAML_LANG - named to avoid conflict with Ruby's YAML module
{ comment: %i[comment], string: %i[ string_scalar double_quote_scalar single_quote_scalar block_scalar plain_scalar escape_sequence ], keyword: %i[ anchor anchor_name alias alias_name tag tag_handle tag_prefix ], number: %i[ integer_scalar float_scalar ], constant: %i[], function_name: %i[], variable: %i[], type: %i[], operator: %i[], punctuation: %i[], builtin: %i[ boolean_scalar null_scalar ], property: %i[ stream document block_node flow_node block_mapping block_mapping_pair block_sequence block_sequence_item flow_mapping flow_sequence flow_pair directive_name directive_parameter yaml_directive yaml_version tag_directive reserved_directive timestamp_scalar ] }.freeze
- YAML_LANG =
YAML_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- COBOL_FEATURES =
COBOL node types are mostly uppercase
{ comment: %i[comment], string: %i[string_literal], keyword: %i[ PERFORM IF ELSE END MOVE DISPLAY ACCEPT ADD SUBTRACT MULTIPLY DIVIDE COMPUTE EVALUATE WHEN CALL GO TO STOP RUN READ WRITE OPEN CLOSE SECTION DIVISION PROGRAM DATA WORKING STORAGE FILE PROCEDURE IDENTIFICATION ENVIRONMENT CONFIGURATION INPUT OUTPUT SELECT ASSIGN ORGANIZATION ACCESS RECORD PIC PICTURE VALUE OCCURS TIMES THRU THROUGH VARYING FROM BY UNTIL WITH TEST BEFORE AFTER RETURNING GIVING USING NOT AND OR GREATER LESS EQUAL THAN ], number: %i[number], constant: %i[], function_name: %i[], variable: %i[identifier], type: %i[], operator: %i[], punctuation: %i[], builtin: %i[ZERO ZEROS ZEROES SPACE SPACES LOW-VALUE HIGH-VALUE], property: %i[] }.freeze
- COBOL =
COBOL_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- SWIFT_FEATURES =
{ comment: %i[ comment line_comment block_comment multiline_comment ], string: %i[ line_string_literal multi_line_string_literal raw_string_literal string_literal interpolated_string_literal ], keyword: %i[ if else switch case default for while repeat break continue return func var let class struct enum protocol extension typealias import init deinit subscript static final override mutating nonmutating convenience required lazy private fileprivate internal public open weak unowned throws rethrows try catch guard defer do where in inout associatedtype precedencegroup operator prefix postfix infix indirect dynamic optional some any async await ], number: %i[ integer_literal float_literal hex_literal oct_literal bin_literal ], constant: %i[], function_name: %i[ function_declaration method_declaration ], variable: %i[ simple_identifier identifier parameter ], type: %i[ type_identifier class_declaration struct_declaration enum_declaration protocol_declaration ], operator: %i[ binary_expression prefix_expression postfix_expression ], punctuation: %i[], builtin: %i[ nil true false self super Self ], property: %i[ property_declaration computed_property ] }.freeze
- SWIFT =
SWIFT_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- CSHARP_FEATURES =
{ comment: %i[comment], string: %i[ string_literal string_content verbatim_string_literal interpolated_string_expression character_literal character_literal_content string_literal_content string_literal_encoding raw_string_literal raw_string_content raw_string_start raw_string_end escape_sequence interpolation interpolation_brace interpolation_start interpolation_quote interpolation_alignment_clause interpolation_format_clause ], keyword: %i[ if else for foreach while do switch case default break continue return goto throw try catch finally class struct interface enum namespace using public private protected internal static readonly const volatile virtual override abstract sealed new this base void var async await yield in out ref params where get set add remove partial extern unsafe fixed lock checked unchecked stackalloc sizeof typeof nameof is as null true false when global file required scoped managed unmanaged record init with and or not notnull delegate event explicit implicit operator assembly module field property method param type typevar from where select group into orderby join let ascending descending on equals by ], number: %i[ integer_literal real_literal float_literal ], constant: %i[ null_literal boolean_literal ], function_name: %i[ method_declaration local_function_statement constructor_declaration destructor_declaration operator_declaration conversion_operator_declaration invocation_expression ], variable: %i[ identifier discard ], type: %i[ predefined_type type_identifier generic_name nullable_type array_type pointer_type function_pointer_type tuple_type ref_type scoped_type implicit_type ], operator: %i[ binary_expression assignment_expression prefix_unary_expression postfix_unary_expression conditional_expression cast_expression as_expression is_expression throw_expression switch_expression with_expression range_expression await_expression default_expression sizeof_expression typeof_expression checked_expression makeref_expression reftype_expression refvalue_expression ], punctuation: %i[], builtin: %i[ __makeref __reftype __refvalue ], property: %i[ compilation_unit using_directive extern_alias_directive namespace_declaration file_scoped_namespace_declaration class_declaration struct_declaration interface_declaration enum_declaration delegate_declaration record_declaration type_parameter_list type_parameter type_parameter_constraints_clause type_parameter_constraint constructor_constraint type_declaration base_list enum_member_declaration_list enum_member_declaration field_declaration event_field_declaration event_declaration property_declaration indexer_declaration accessor_list accessor_declaration arrow_expression_clause attribute_list attribute attribute_argument_list attribute_argument attribute_target_specifier global_attribute declaration_list variable_declaration variable_declarator local_declaration_statement parameter_list parameter bracketed_parameter_list implicit_parameter argument_list argument bracketed_argument_list element_access_expression element_binding_expression member_access_expression conditional_access_expression invocation_expression object_creation_expression implicit_object_creation_expression array_creation_expression implicit_array_creation_expression stackalloc_expression implicit_stackalloc_expression tuple_expression tuple_element initializer_expression anonymous_object_creation_expression anonymous_method_expression lambda_expression parenthesized_lambda_expression anonymous_object_member_declarator declaration_expression declaration_pattern recursive_pattern property_pattern_clause subpattern positional_pattern_clause var_pattern discard_pattern list_pattern slice_pattern constant_pattern type_pattern relational_pattern negated_pattern and_pattern or_pattern is_pattern_expression parenthesized_pattern query_expression from_clause join_clause join_into_clause let_clause where_clause order_by_clause ordering select_clause group_clause query_continuation block statement expression_statement if_statement switch_statement switch_body switch_section switch_expression_arm switch_label case_switch_label default_switch_label while_statement do_statement for_statement foreach_statement break_statement continue_statement return_statement yield_statement goto_statement throw_statement try_statement catch_clause catch_declaration catch_filter_clause finally_clause lock_statement using_statement checked_statement unsafe_statement fixed_statement empty_statement labeled_statement expression primary_expression lvalue_expression non_lvalue_expression interpolated_string_text shebang_directive preproc_if preproc_if_in_attribute_list preproc_elif preproc_else preproc_define preproc_undef preproc_region preproc_endregion preproc_error preproc_warning preproc_line preproc_nullable preproc_pragma preproc_arg modifier primary_constructor_base_type literal with_initializer annotations ] }.freeze
- CSHARP =
CSHARP_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- ELIXIR_FEATURES =
Feature-based node mapping for Elixir
{ comment: %i[comment], string: %i[ string quoted_content charlist sigil atom quoted_atom interpolation escape_sequence ], keyword: %i[ do end def defp defmodule defmacro defmacrop defstruct defimpl defprotocol if else unless cond case when fn for with receive after rescue catch raise try quote unquote import require alias use ], number: %i[integer float], constant: %i[ boolean nil atom module ], function_name: %i[ call identifier ], variable: %i[ identifier ], operator: %i[ operator binary_operator unary_operator arrow pipe range stab_clause ], punctuation: %i[], builtin: %i[true false nil], property: %i[ list tuple map keyword_list struct bitstring ] }.freeze
- ELIXIR =
Expand Feature -> Face mapping
ELIXIR_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- GROOVY_FEATURES =
{ comment: %i[comment], string: %i[ string gstring string_content ], keyword: %i[ if else for while do switch case default break continue return throw try catch finally class interface enum trait extends implements import package def var public private protected static final abstract synchronized native transient volatile new this super instanceof in as assert ], number: %i[number_literal], constant: %i[], function_name: %i[], variable: %i[identifier], type: %i[type_identifier], operator: %i[], punctuation: %i[], builtin: %i[ true false null ], property: %i[] }.freeze
- GROOVY =
GROOVY_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- PASCAL_FEATURES =
Pascal tree-sitter node types often use the kXxx naming convention
{ comment: %i[comment], string: %i[ literalString literalChar declString ], keyword: %i[ kBegin kEnd kEndDot kIf kThen kElse kFor kTo kDownto kForeach kWhile kRepeat kUntil kDo kCase kOf kWith kFunction kProcedure kOperator kProgram kUnit kLibrary kInterface kImplementation kInitialization kFinalization kVar kThreadvar kConst kResourcestring kType kArray kRecord kSet kFile kClass kObject kConstructor kDestructor kProperty kInherited kPrivate kProtected kPublic kPublished kStrictPrivate kStrictProtected kVirtual kOverride kReintroduce kAbstract kSealed kStatic kDynamic kForward kExternal kExport kExports kUses kIn kOut kNil kNot kAnd kOr kXor kDiv kMod kFdiv kShl kShr kAs kIs kAt kTry kExcept kFinally kRaise kOn kGoto kLabel kBreak kContinue kExit kAsm kPacked kAbsolute kAssembler kCdecl kCppdecl kFar kNear kPascal kRegister kSafecall kStdcall kVarargs kLocal kMessage kDefault kIndex kName kRead kWrite kStored kImplements kNodefault kOverload kReintroduce kVirtual kAbstract kSealed kStatic kHelper kStrict kGeneric kSpecialize kReference kConstref kOperator kInline kInterrupt kIocheck kHardfloat kSoftfloat kNostackframe kNoreturn kAlias kDeprecated kExperimental kPlatform kUnimplemented kMs_abi_default kMs_abi_cdecl kSysv_abi_default kSysv_abi_cdecl kVectorcall kCvar kMwpascal kSaveregisters kWinapi kDelayed kDispId kDispInterface kObjcclass kObjccategory kObjcprotocol kOptional kRequired kString ], number: %i[ literalNumber ], constant: %i[ guid ], function_name: %i[ defProc declProc declProcRef exprCall ], variable: %i[ identifier operatorName ], type: %i[ type typeref typerefPtr typerefDot typerefTpl typerefArgs declType declTypes declMetaClass declClass declIntf declHelper declEnum declEnumValue declSet declArray declVariant declVariantClause ], operator: %i[ exprBinary exprUnary assignment kAdd kSub kMul kHat kAssign kAssignAdd kAssignDiv kAssignMul kAssignSub kEq kNeq kGt kGte kLt kLte ], punctuation: %i[ kDot ], builtin: %i[ kTrue kFalse ], property: %i[ root program library unit moduleName block blockTr declSection declUses declConst declVar declVars declField declArg declArgs declLabel declLabels declExport declExports declProp declPropArgs varDef varAssignDef defaultValue statement statements if ifElse case caseCase caseLabel for foreach while repeat with try exceptionHandler exceptionElse goto label raise asmBody procAttribute procExternal genericArg genericArgs genericDot genericTpl exprArgs exprParens exprBrackets exprSubscript exprDot exprTpl arrInitializer recInitializer recInitializerField lambda legacyFormat range inherited pp implementation interface initialization finalization ] }.freeze
- PASCAL =
PASCAL_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- PYTHON_FEATURES =
{ comment: %i[comment], string: %i[ string string_content string_start string_end concatenated_string escape_sequence escape_interpolation interpolation format_specifier format_expression type_conversion ], keyword: %i[ if elif else for while break continue return pass raise try except finally with as def class lambda import from global nonlocal assert yield del in not and or is async await match case type exec print __future__ ], number: %i[ integer float ], constant: %i[], function_name: %i[ function_definition call ], variable: %i[ identifier dotted_name ], type: %i[ type generic_type member_type union_type constrained_type splat_type ], operator: %i[ binary_operator unary_operator boolean_operator comparison_operator not_operator assignment augmented_assignment named_expression conditional_expression ], punctuation: %i[ chevron ellipsis line_continuation positional_separator ], builtin: %i[ true false none ], property: %i[ attribute argument_list keyword_argument keyword_separator default_parameter typed_default_parameter typed_parameter type_parameter list_splat dictionary_splat parameters lambda_parameters parenthesized_expression tuple tuple_pattern list list_pattern list_comprehension dictionary dict_pattern dictionary_comprehension set set_comprehension for_in_clause if_clause generator_expression parenthesized_list_splat expression_list pattern_list subscript slice expression_statement return_statement delete_statement raise_statement assert_statement print_statement pass_statement break_statement continue_statement if_statement elif_clause else_clause match_statement case_clause for_statement while_statement try_statement except_clause except_group_clause finally_clause with_statement with_clause with_item function_definition class_definition decorated_definition decorator block module import_statement import_from_statement import_prefix relative_import aliased_import future_import_statement wildcard_import global_statement nonlocal_statement exec_statement type_alias_statement as_pattern case_pattern keyword_pattern splat_pattern union_pattern complex_pattern dictionary_splat_pattern pair ] }.freeze
- PYTHON =
PYTHON_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- CRYSTAL_FEATURES =
Crystal language node mapping Based on crystal-lang-tools/tree-sitter-crystal Crystal has Ruby-like syntax with static typing
{ comment: %i[comment], string: %i[ string string_literal string_content heredoc_content heredoc_body symbol simple_symbol char_literal escape_sequence regex regex_literal command ], keyword: %i[ def end class module struct if else elsif unless case when then while until for do break next redo return yield begin rescue ensure and or not in alias abstract private protected getter setter property include extend require lib fun macro annotation self super nil true false typeof sizeof offsetof pointerof as is_a? responds_to? uninitialized out with ], number: %i[ integer float number_literal integer_literal float_literal ], constant: %i[ constant type_identifier class_name ], function_name: %i[ method method_name function_identifier call ], variable: %i[ identifier instance_variable class_variable global_variable parameter variable ], type: %i[ type generic_type union_type nilable_type proc_type tuple_type ], operator: %i[ binary unary assignment operator binary_operator unary_operator ], punctuation: %i[], builtin: %i[], property: %i[ hash array tuple named_tuple block attribute ] }.freeze
- CRYSTAL =
Expand Feature -> Face mapping
CRYSTAL_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
- JAVASCRIPT_FEATURES =
{ comment: %i[ comment html_comment hash_bang_line ], string: %i[ string string_fragment template_string template_substitution regex regex_pattern regex_flags escape_sequence html_character_reference jsx_text ], keyword: %i[ if else for while do switch case default break continue return throw try catch finally function class extends new this super import export from as const let var in of instanceof typeof void delete async await yield static get set debugger with target meta ], number: %i[number], constant: %i[], function_name: %i[ function_declaration function_expression generator_function generator_function_declaration arrow_function method_definition call_expression ], variable: %i[ identifier property_identifier shorthand_property_identifier shorthand_property_identifier_pattern private_property_identifier statement_identifier ], type: %i[], operator: %i[ binary_expression unary_expression update_expression ternary_expression assignment_expression augmented_assignment_expression optional_chain ], punctuation: %i[], builtin: %i[ true false null undefined arguments ], property: %i[ array object pair spread_element rest_pattern member_expression subscript_expression computed_property_name field_definition class_body class_declaration class_heritage class_static_block decorator statement_block expression_statement lexical_declaration variable_declaration variable_declarator parenthesized_expression sequence_expression formal_parameters assignment_pattern object_pattern array_pattern object_assignment_pattern pair_pattern if_statement else_clause switch_statement switch_body switch_case switch_default for_statement for_in_statement while_statement do_statement try_statement catch_clause finally_clause break_statement continue_statement return_statement throw_statement empty_statement labeled_statement with_statement debugger_statement export_statement export_clause export_specifier namespace_export import_statement import_clause import_specifier import_attribute namespace_import named_imports new_expression yield_expression await_expression meta_property program ] }.freeze
- JAVASCRIPT =
JAVASCRIPT_FEATURES.flat_map { |face, nodes| nodes.map { |node| [node, face] } }.to_h.freeze
Class Method Summary collapse
- .available_languages ⇒ Object
- .clear_custom_maps ⇒ Object
- .for(language) ⇒ Object
- .register(language, node_map) ⇒ Object
Class Method Details
.available_languages ⇒ Object
58 59 60 |
# File 'lib/textbringer/tree_sitter/node_maps.rb', line 58 def available_languages (default_maps.keys + (@custom_maps&.keys || [])).uniq end |
.clear_custom_maps ⇒ Object
54 55 56 |
# File 'lib/textbringer/tree_sitter/node_maps.rb', line 54 def clear_custom_maps @custom_maps = {} end |
.for(language) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/textbringer/tree_sitter/node_maps.rb', line 30 def for(language) # Normalize language name to handle aliases normalized = LanguageAliases.to_sym(language) # If a custom map is registered, merge it with defaults and return if @custom_maps&.key?(normalized) default_map = default_maps[normalized] if default_map default_map.merge(@custom_maps[normalized]) else @custom_maps[normalized] end else default_maps[normalized] end end |
.register(language, node_map) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/textbringer/tree_sitter/node_maps.rb', line 47 def register(language, node_map) # Normalize language name when registering normalized = LanguageAliases.to_sym(language) @custom_maps ||= {} @custom_maps[normalized] = node_map end |