Class: ActiveFacts::CQL::Parser

Inherits:
CQLParser
  • Object
show all
Includes:
ActiveFacts
Defined in:
lib/activefacts/cql/parser.rb,
lib/activefacts/cql/parser.rb,
lib/activefacts/cql/parser/nodes.rb

Overview

Extend the generated parser:

Direct Known Subclasses

Compiler

Defined Under Namespace

Modules: ValueTypeParameterDefinition, ValueTypeParameterRestriction, ValueTypeParameterSetting Classes: Context, InputProxy, TermDefinitionNameNode, TermLANode, TermNode

Instance Method Summary collapse

Methods included from CQL

#_nt_alias_list, #_nt_alias_term, #_nt_constraint, #_nt_cql_file, #_nt_definition, #_nt_definition_body, #_nt_enforcement, #_nt_equality_constraint, #_nt_import_definition, #_nt_import_role, #_nt_informal_description, #_nt_informal_description_body, #_nt_informal_description_closer, #_nt_informal_description_subject, #_nt_presence_constraint, #_nt_schema_definition, #_nt_set_constraint, #_nt_subset_constraint, #_nt_transform_definition, #_nt_version_number, #_nt_version_number_string, #_nt_version_pattern, #_nt_version_pattern_string, #_nt_vocabulary_definition, #_nt_vocabulary_name, #root

Methods included from Context

#_nt_context_note, #_nt_context_type, #_nt_description, #_nt_who_says, #root

Methods included from TransformRules

#_nt_additive_op, #_nt_additive_texpr, #_nt_aggregate_op, #_nt_compound_matching, #_nt_equality_op, #_nt_equality_texpr, #_nt_logical_and_texpr, #_nt_logical_texpr, #_nt_multiplicative_op, #_nt_multiplicative_texpr, #_nt_primary_texpr, #_nt_relational_op, #_nt_relational_texpr, #_nt_simple_matching, #_nt_term_list, #_nt_transform_expr, #_nt_transform_matching, #_nt_transform_matchings, #_nt_transform_query, #_nt_transform_rule, #_nt_unary_op, #_nt_unary_texpr, #root

Methods included from FactTypes

#_nt_aggregate, #_nt_anonymous_fact_type, #_nt_certainty, #_nt_clauses, #_nt_clauses_list, #_nt_comparator, #_nt_comparison, #_nt_condition_contraction, #_nt_contracted_clauses, #_nt_contraction, #_nt_fact_type, #_nt_objectification_step, #_nt_phrase, #_nt_post_qualifier, #_nt_post_qualifiers, #_nt_qualified_clauses, #_nt_query, #_nt_query_clauses, #_nt_reading_contraction, #_nt_return, #_nt_returning_clause, #_nt_role, #_nt_role_name, #_nt_role_quantifier, #_nt_simple_role, #_nt_subscript, #root

Methods included from ValueTypes

#_nt_implicit_value_type_name, #_nt_in_units, #_nt_maybe_unit, #_nt_named_parameter, #_nt_non_unit, #_nt_ordered_parameter, #_nt_parameter, #_nt_parameter_literal, #_nt_parameter_name, #_nt_parameter_restriction, #_nt_range_list, #_nt_restricted_values, #_nt_type_parameter_list, #_nt_unit, #_nt_unit_coefficient, #_nt_unit_definition, #_nt_unit_name, #_nt_unit_offset, #_nt_units, #_nt_value_constraint, #_nt_value_type, #_nt_value_type_parameters, #root

Methods included from ObjectTypes

#_nt_basetype, #_nt_entity_clauses, #_nt_entity_type, #_nt_identification, #_nt_mapping_pragma, #_nt_mapping_pragmas, #_nt_object_type, #_nt_role_list, #_nt_subtype, #_nt_supertype_list, #_nt_term_or_unary, #_nt_unary_text, #root

Methods included from Terms

#_nt_derived_value_continuation, #_nt_entity_prefix, #_nt_global_term, #_nt_informal_description_subject_prescan, #_nt_informally_prescan, #_nt_lead_intervening, #_nt_new_adjective_term, #_nt_new_derived_value, #_nt_non_phrase, #_nt_non_term_def, #_nt_prescan, #_nt_prescan_aggregate, #_nt_prescan_rest, #_nt_term, #_nt_term_definition_name, #_nt_trail_intervening, #_nt_x, #root

Methods included from Expressions

#_nt_add_op, #_nt_derived_variable, #_nt_expression, #_nt_factor, #_nt_product, #_nt_sum, #root

Methods included from LexicalRules

#_nt_S, #_nt_alpha, #_nt_alphanumeric, #_nt_boolean_literal, #_nt_character_class, #_nt_character_classes, #_nt_comment_c_style, #_nt_comment_to_eol, #_nt_exponent, #_nt_fraction, #_nt_fractional_real, #_nt_hexnumber, #_nt_id, #_nt_literal, #_nt_mul_op, #_nt_number, #_nt_numeric_range, #_nt_octalnumber, #_nt_range, #_nt_real, #_nt_regular_expression, #_nt_regular_expression_alternate, #_nt_regular_expression_atom, #_nt_regular_expression_contents, #_nt_regular_expression_group, #_nt_regular_expression_group_extension, #_nt_regular_expression_multiplicity, #_nt_regular_expression_sequence, #_nt_s, #_nt_string, #_nt_string_char, #_nt_string_range, #_nt_url, #_nt_white, #root

Instance Method Details

#contextObject



237
238
239
# File 'lib/activefacts/cql/parser.rb', line 237

def context
  @context ||= Context.new(self)
end

#parse(input, options = {}) ⇒ Object



246
247
248
249
# File 'lib/activefacts/cql/parser.rb', line 246

def parse(input, options = {})
  input = InputProxy.new(input, context, self) unless input.respond_to?(:context)
  super(input, options)
end

#parse_all(input, rule_name = nil, &block) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/activefacts/cql/parser.rb', line 251

def parse_all(input, rule_name = nil, &block)
  self.root = rule_name if rule_name

  @index = 0  # Byte offset to start next parse
  @block = block
  self.consume_all_input = false
  nodes = []
  begin
    node = parse(InputProxy.new(input, context, self), :index => @index)
    unless node 
      raise failure_reason || "not all input was understood" unless @index == input.size
      return nil  # No input, or no more input
    end
    unless @vocabulary_seen || !node.ast
      @vocabulary_seen = Compiler::Vocabulary === node.ast
      raise "CQL files must begin with a vocabulary, schema or transform definition" unless @vocabulary_seen
    end
    if @block
      @block.call(node)
    else
      nodes << node
    end
  end until self.index == @input_length
  @block ? true : nodes
end

#unit?(s) ⇒ Boolean

Returns:

  • (Boolean)


241
242
243
244
# File 'lib/activefacts/cql/parser.rb', line 241

def unit?(s)
  # puts "Asking whether #{s.inspect} is a unit"
  true
end