Module: BEL::Completion
- Defined in:
- lib/bel/completion.rb,
lib/bel/completion_rule.rb
Defined Under Namespace
Modules: Rule Classes: MatchFunctionRule, MatchNamespacePrefixRule, MatchNamespaceValueRule
Constant Summary collapse
- SORTED_FUNCTIONS =
BEL::Language::FUNCTIONS.keys.sort.map(&:to_s)
- SORTED_NAMESPACES =
BEL::Namespace::NAMESPACE_LATEST.keys.sort.map(&:to_s)
- EMPTY_MATCH =
[]
Class Method Summary collapse
-
.complete(bel_expression, search = nil, position = nil) ⇒ Array<Completion>
Provides completions on BEL expressions.
- .rules ⇒ Object
- .run_rules(tokens, active_index, active_token, options = {}) ⇒ Object
Class Method Details
.complete(bel_expression, search = nil, position = nil) ⇒ Array<Completion>
Provides completions on BEL expressions.
If bel_expression
is nil
then its assumed to be the empty string otherwise the to_s
method is called. An empty bel_expression
will return all BEL functions as possible completions.
If search
is nil
then namespace values will not be provided as completion. search
is expected to implement IdentifierSearch.
If position
is nil
then its assumed to be the last index of bel_expression
otherwise the to_i
method is called.
If position
is negative or greater than the length of bel_expression
an IndexError
is raised.
complete on provide namespace value completions
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bel/completion.rb', line 30 def self.complete(bel_expression, search = nil, position = nil) bel_expression = (bel_expression || '').to_s position = (position || bel_expression.length).to_i if position < 0 or position > bel_expression.length msg = %Q{position #{position}, bel_expression "#{bel_expression}"} fail IndexError, msg end token_list = LibBEL::tokenize_term(bel_expression) active_token, active_index = token_list.token_at(position) # no active token indicates the position is out of # range of all tokens in the list. return [] unless active_token tokens = token_list.to_a = { :search => search } BEL::Completion::run_rules(tokens, active_index, active_token, ) end |
.rules ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/bel/completion_rule.rb', line 21 def self.rules [ MatchFunctionRule.new, MatchNamespacePrefixRule.new, MatchNamespaceValueRule.new ] end |
.run_rules(tokens, active_index, active_token, options = {}) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/bel/completion_rule.rb', line 13 def self.run_rules(tokens, active_index, active_token, = {}) self.rules.reduce([]) { |completion_results, rule| completion_results.concat( rule.apply(tokens, active_token, active_index, ) ) } end |