Class: DDQL::TokenType::SubQueryAlias

Inherits:
DDQL::TokenType show all
Defined in:
lib/ddql/token_type.rb

Constant Summary

Constants inherited from DDQL::TokenType

ALL, CURRENCY_LITERAL, FACTOR, FACTOR_PATTERN, INFIXOPERATOR, INTEGER_LITERAL, LBRACE, LPAREN, NESTED_CLOSER, NESTED_CLOSE_PATTERN, NESTED_OPENER, NESTED_OPEN_PATTERN, NUMERIC_LITERAL, POSTFIXOPERATOR, PREFIXOPERATOR, RBRACE, RPAREN, SCI_NUM_LITERAL, SCREEN, SPECIAL_MARKER, STRING_LITERAL, SUB_Q_ALIAS, SUB_Q_EXPR, SUB_Q_FIELDS, SUB_Q_GROUP, SUB_Q_TYPE, WHITESPACE

Instance Attribute Summary

Attributes inherited from DDQL::TokenType

#label, #name, #pattern

Instance Method Summary collapse

Methods inherited from DDQL::TokenType

#==, all_types_pattern, #comparison?, #data_from, #expression?, #factor?, #group?, #infix?, #interpret, #interpreted_data_from, #literal?, #match?, #postfix?, #prefix?, #screen?, #skipping!, #trimming!

Constructor Details

#initializeSubQueryAlias

Returns a new instance of SubQueryAlias.



469
470
471
472
# File 'lib/ddql/token_type.rb', line 469

def initialize
  super(name: :sub_query_alias, pattern: /AS\s+(?<sub_query_alias>#{FACTOR_PATTERN})/)
  trimming!
end

Instance Method Details

#as_hash(data) ⇒ Object



474
475
476
477
478
# File 'lib/ddql/token_type.rb', line 474

def as_hash(data)
  factor, desc = data.split(':', 2)
  desc = factor unless desc
  {name => {factor: factor, desc: desc}}
end

#parse(parser, token, expression: nil) ⇒ Object



480
481
482
483
484
485
486
487
488
489
# File 'lib/ddql/token_type.rb', line 480

def parse(parser, token, expression: nil)
  if expression.nil?
    raise 'expected AS to be part of an ALIAS expression'
  end
  if expression && expression.key?(:sub_query_expression)
    expression[:sub_query] = parser.class.parse(expression[:sub_query_expression])
    expression.delete :sub_query_expression
  end
  expression.merge(as_hash(token.data))
end

#post_process(parser:, expression:) ⇒ Object



491
492
493
494
495
# File 'lib/ddql/token_type.rb', line 491

def post_process(parser:, expression:)
  token = parser.consume TokenType::SUB_Q_ALIAS
  new_expression = expression.merge!(token.parse(parser, expression: expression))
  [token, new_expression]
end

#supports_post_processing?Boolean

Returns:

  • (Boolean)


497
498
499
# File 'lib/ddql/token_type.rb', line 497

def supports_post_processing?
  true
end