Module: TreeSitter::Mixins::Language
- Included in:
- TreeSitter, TreeStand::Parser
- Defined in:
- lib/tree_sitter/mixins/language.rb
Overview
Language Mixin.
Instance Method Summary collapse
-
#ext ⇒ String
The platform-specific extension of the parser.
-
#language(name) ⇒ TreeSitter:language
Load a language from configuration or default lookup paths.
Instance Method Details
#ext ⇒ String
The platform-specific extension of the parser.
100 101 102 103 104 105 |
# File 'lib/tree_sitter/mixins/language.rb', line 100 def ext case Gem::Platform.local.os in /darwin/ then 'dylib' else 'so' end end |
#language(name) ⇒ TreeSitter:language
Note:
the name is case sensitive, but library lookup is not: if your parser is defined as ‘COBOL`, then you have to call `language(’COBOL’)‘, but the parser can be `cobol.so/COBOL.so/…`.
Load a language from configuration or default lookup paths.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/tree_sitter/mixins/language.rb', line 82 def language(name) lib = search_for_lib(name) if lib.nil? raise ::TreeSitter::ParserNotFoundError, <<~MSG.chomp Failed to load a parser for #{name}. #{} MSG end # We know that the bindings will accept `lib`, but I don't know how to tell sorbet # the types in ext/tree_sitter where `load` is defined. TreeSitter::Language.load(name.tr('-', '_'), lib) end |