class MODL::Parser::Parsed::ParsedPrimitive

Class to represent a parsed grammar object

Attributes

constant[RW]
falseVal[RW]
nilVal[RW]
number[RW]
quoted[RW]
string[RW]
text[RW]
trueVal[RW]

Public Class Methods

new(global) click to toggle source
# File lib/modl/parser/parsed.rb, line 659
def initialize(global)
  @global = global
  @constant = false
end

Public Instance Methods

enterModl_primitive(ctx) click to toggle source
# File lib/modl/parser/parsed.rb, line 698
def enterModl_primitive(ctx)
  ctx_number = ctx.NUMBER
  ctx_string = ctx.STRING
  ctx_quoted = ctx.QUOTED
  ctx_null = ctx.NULL
  ctx_true = ctx.TRUE
  ctx_false = ctx.FALSE

  if !ctx_number.nil?
    @number = ParsedNumber.new(ctx_number.text)
    @text = @number.num
  elsif !ctx_string.nil?
    @text = ctx_string.text

    @constant = @text.start_with?('`') && !@text.include?('%') && !@text.include?('`.')
    @string = ParsedString.new(@text)
    @text = @string.string
  elsif !ctx_quoted.nil?
    @constant = true
    @text = Sutil.toptail ctx_quoted.text
    @quoted = ParsedQuoted.new(@text)
  elsif !ctx_null.nil?
    @nilVal = ParsedNull.instance
    @text = nil
  elsif !ctx_true.nil?
    @trueVal = ParsedTrue.instance
    @text = true
  elsif !ctx_false.nil?
    @falseVal = ParsedFalse.instance
    @text = false
  end
  # ignoring comments!
end
evaluate() click to toggle source
# File lib/modl/parser/parsed.rb, line 680
def evaluate
  return false if @nilVal
  return false if @falseVal

  true
end
extract_hash() click to toggle source
# File lib/modl/parser/parsed.rb, line 674
def extract_hash
  result, _ignore = RefProcessor.deref(@text, @global) unless @constant
  result = @text if @constant
  Substitutions.process UnicodeEscapes.process result
end
find_property(key) click to toggle source
# File lib/modl/parser/parsed.rb, line 664
def find_property(key)
  if @string
    user_method = @global.user_method(key)
    if user_method
      return user_method.run(@string.string)
    end
    StandardMethods.run_method(key, Substitutions.process(UnicodeEscapes.process(@string.string)))
  end
end
value_obj() click to toggle source
# File lib/modl/parser/parsed.rb, line 687
def value_obj
  return @quoted if @quoted
  return @number if @number
  return @trueVal if @trueVal
  return @falseVal if @falseVal
  return @nilVal if @nilVal
  return @string if @string

  @text
end