Class: Pione::Lang::DataExpr

Inherits:
Piece
  • Object
show all
Defined in:
lib/pione/lang/data-expr.rb

Overview

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

Direct Known Subclasses

DataExprNull

Instance Method Summary collapse

Methods inherited from Piece

piece_type_name, #textize

Methods included from Util::Positionable

#line_and_column, #pos, #set_source_position

Instance Method Details

#===(other) ⇒ Object

Pattern match.



68
69
70
# File 'lib/pione/lang/data-expr.rb', line 68

def ===(other)
  match(other) ? true : false
end

#=~(other) ⇒ Object

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



63
64
65
# File 'lib/pione/lang/data-expr.rb', line 63

def =~(other)
  match(other) ? 0 : nil
end

#accept_nonexistence?Boolean

Return if the expression accepts nonexistence of corresponding data.

Returns:

  • (Boolean)

    false because data expression needs corresponding data



58
59
60
# File 'lib/pione/lang/data-expr.rb', line 58

def accept_nonexistence?
  false
end

#eval(env) ⇒ Object

Evaluate exceptions and expand embeded expressions of data pattern.



39
40
41
42
43
# 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) ⇒ Object

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



46
47
48
49
50
51
52
# 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