class Pione::Lang::DataExpr

DataExpr is a class for data name expressions of rule input and output.

Public Instance Methods

===(other) click to toggle source

Pattern match.

# File lib/pione/lang/data-expr.rb, line 68
def ===(other)
  match(other) ? true : false
end
=~(other) click to toggle source

Same as Regexp#=~ but return 0 if it matched.

# File lib/pione/lang/data-expr.rb, line 63
def =~(other)
  match(other) ? 0 : nil
end
accept_nonexistence?() click to toggle source

Return if the expression accepts nonexistence of corresponding data.

@return [Boolean]

false because data expression needs corresponding data
# File lib/pione/lang/data-expr.rb, line 58
def accept_nonexistence?
  false
end
eval(env) click to toggle source

Evaluate exceptions and expand embeded expressions of data pattern.

# File lib/pione/lang/data-expr.rb, line 39
def eval(env)
  new_pattern = Util::EmbededExprExpander.expand(env, pattern)
  new_exceptions = exceptions.eval(env)
  set(pattern: new_pattern, exceptions: new_exceptions)
end
match(name) click to toggle source

Return matched data if the name is matched with the expression.

# File lib/pione/lang/data-expr.rb, line 46
def match(name)
  # check exceptions
  return nil if exceptions.match?(name)

  # match test
  return DataExprCompiler.compile(pattern).match(name)
end