Class: Parslet::Atoms::Rule::Position

Inherits:
Struct
  • Object
show all
Includes:
Context
Defined in:
lib/parslet/atoms/rule/position.rb

Overview

Update/fetch parsed entry at a given position in source Eval rule body at a given position in source and cache the result

Defined Under Namespace

Modules: Context Classes: LR, MemoEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Context

#entry, #entry=, #head, #head=, #lr_stack

Instance Attribute Details

#contextObject

Returns the value of attribute context

Returns:

  • (Object)

    the current value of context



3
4
5
# File 'lib/parslet/atoms/rule/position.rb', line 3

def context
  @context
end

#posObject

Returns the value of attribute pos

Returns:

  • (Object)

    the current value of pos



3
4
5
# File 'lib/parslet/atoms/rule/position.rb', line 3

def pos
  @pos
end

#ruleObject

Returns the value of attribute rule

Returns:

  • (Object)

    the current value of rule



3
4
5
# File 'lib/parslet/atoms/rule/position.rb', line 3

def rule
  @rule
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



3
4
5
# File 'lib/parslet/atoms/rule/position.rb', line 3

def source
  @source
end

Instance Method Details

#apply_ruleObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/parslet/atoms/rule/position.rb', line 70

def apply_rule
  result = recall
  if result.nil?
    # Eval rule body with LR supported by
    # placing a LR flag before eval rule body
    # and growing LR seed after detected LR
    lr = LR.new(fail('left recursion detected'), self.rule, self.pos)
    lr_stack.push(lr)
    self.entry = lr
    self.entry = eval_rule_body
    lr_stack.pop
    if self.entry.first && lr.detected?
      grow_lr(lr.head)
    end
    result = self.entry
  elsif result.is_a?(LR)
    # Find out all involved lrs in stack
    # Collect rules of involved lrs
    # And set head of involved lrs for re-eval
    # rules in recall process
    result.setup_for_re_eval_involved_rules(lr_stack)
  end
  source.pos = result.pos
  a = result.answer
  if a.is_a? Parslet::Atoms::Rule::Position::MemoEntry
    a = a.answer
  end
  a
end