class DDQL::TokenType

Constants

ALL
CURRENCY_LITERAL

LCAPTURE = new(name: :lcapture, pattern: /(%/) RCAPTURE = new(name: :rcapture, pattern: /%)/)

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

Attributes

label[R]
name[R]
pattern[R]

Public Class Methods

all_types_pattern() click to toggle source
# File lib/ddql/token_type.rb, line 11
def self.all_types_pattern
  @pattern ||= Regexp.compile(ALL.map { |tt| "(?<#{tt.name}>#{tt.pattern})" }.join('|'))
end
new(name:, pattern:, &block) click to toggle source
# File lib/ddql/token_type.rb, line 15
def initialize(name:, pattern:, &block)
  @label             = name.to_s
  @name              = name
  @pattern           = pattern
  @skipping          = false
  @data_range        = 0..-1
  @value_transformer = block
end

Public Instance Methods

==(other) click to toggle source
# File lib/ddql/token_type.rb, line 24
def ==(other)
  name == other.name
end
as_hash(data) click to toggle source
# File lib/ddql/token_type.rb, line 28
def as_hash(data)
  raise "subclass responsibility name[#{name}] data[#{data}]"
end
comparison?(data) click to toggle source
# File lib/ddql/token_type.rb, line 32
def comparison?(data)
  false
end
data_from(match_data:) click to toggle source
# File lib/ddql/token_type.rb, line 36
def data_from(match_data:)
  match_data.named_captures[label]
end
expression?() click to toggle source
# File lib/ddql/token_type.rb, line 40
def expression?
  false
end
factor?() click to toggle source
# File lib/ddql/token_type.rb, line 44
def factor?
  false
end
group?() click to toggle source
# File lib/ddql/token_type.rb, line 48
def group?
  false
end
infix?() click to toggle source
# File lib/ddql/token_type.rb, line 52
def infix?
  false
end
interpret(data) click to toggle source
# File lib/ddql/token_type.rb, line 56
def interpret(data)
  return nil if data.nil?
  return data[@data_range] if @value_transformer.nil?
  @value_transformer.call(data[@data_range])
end
interpreted_data_from(match_data:) click to toggle source
# File lib/ddql/token_type.rb, line 62
def interpreted_data_from(match_data:)
  data = data_from match_data: match_data
  return nil if data.nil?
  interpret data
end
literal?() click to toggle source
# File lib/ddql/token_type.rb, line 68
def literal?
  false
end
match?(match_data:) click to toggle source
# File lib/ddql/token_type.rb, line 72
def match?(match_data:)
  data_from(match_data: match_data).nil? || @skipping ? false : true
end
parse(parser, token, expression: nil) click to toggle source
# File lib/ddql/token_type.rb, line 76
def parse(parser, token, expression: nil)
  as_hash(token.data)
end
postfix?() click to toggle source
# File lib/ddql/token_type.rb, line 80
def postfix?
  false
end
prefix?() click to toggle source
# File lib/ddql/token_type.rb, line 84
def prefix?
  false
end
screen?() click to toggle source
# File lib/ddql/token_type.rb, line 88
def screen?
  false
end
skipping!() click to toggle source
# File lib/ddql/token_type.rb, line 92
def skipping!
  @skipping = true
  self
end
supports_post_processing?() click to toggle source
# File lib/ddql/token_type.rb, line 97
def supports_post_processing?
  false
end
trimming!(range=(1..-2)) click to toggle source
# File lib/ddql/token_type.rb, line 101
def trimming!(range=(1..-2))
  @data_range = range
  self
end