class J2119::Parser

Constants

ROOT

Attributes

finder[R]

for debugging

root[R]

Public Class Methods

new(j2119_file) click to toggle source
# File lib/j2119/parser.rb, line 26
def initialize(j2119_file)

  have_root = false
  @failed = false
  @constraints = RoleConstraints.new
  @finder = RoleFinder.new
  @allowed_fields = AllowedFields.new
  
  j2119_file.each_line do |line|
    if line =~ ROOT
      if have_root
        fail "Only one root declaration"
      else
        @root = $1
        @matcher = Matcher.new(root)
        @assigner =
          Assigner.new(@constraints, @finder, @matcher, @allowed_fields)
        have_root = true
      end
    else
      if !have_root
        fail "Root declaration must come first"
      else
        proc_line(line)
      end
    end
  end
  if @failed
    raise "Could not create parser"
  end
end

Public Instance Methods

allows_any?(roles) click to toggle source
# File lib/j2119/parser.rb, line 101
def allows_any?(roles)
  @allowed_fields.any?(roles)
end
fail(message) click to toggle source
# File lib/j2119/parser.rb, line 76
def fail(message)
  @failed = true
  STDERR.puts message
end
field_allowed?(roles, child) click to toggle source
# File lib/j2119/parser.rb, line 97
def field_allowed?(roles, child)
  @allowed_fields.allowed?(roles, child)
end
find_child_roles(roles, name) click to toggle source
# File lib/j2119/parser.rb, line 89
def find_child_roles(roles, name)
  @finder.find_child_roles(roles, name)
end
find_grandchild_roles(roles, name) click to toggle source
# File lib/j2119/parser.rb, line 85
def find_grandchild_roles(roles, name)
  @finder.find_grandchild_roles(roles, name)
end
find_more_roles(node, roles) click to toggle source
# File lib/j2119/parser.rb, line 81
def find_more_roles(node, roles)
  @finder.find_more_roles(node, roles)
end
get_constraints(role) click to toggle source
# File lib/j2119/parser.rb, line 93
def get_constraints(role)
  @constraints.get_constraints(role)
end
proc_line(line) click to toggle source
# File lib/j2119/parser.rb, line 58
def proc_line(line)
  if @matcher.is_constraint_line(line)
    @assigner.assign_constraints @matcher.build_constraint(line)
  elsif @matcher.is_only_one_match_line(line)
    @assigner.assign_only_one_of(@matcher.build_only_one(line))
  elsif line =~ /^Each of a/
    eaches_line = @matcher.eachof_match.match(line)
    eaches = Oxford.break_role_list(@matcher, eaches_line['each_of'])
    eaches.each do |each|
      proc_line("A #{each} #{eaches_line['trailer']}")
    end
  elsif @matcher.is_role_def_line(line)
    @assigner.assign_roles @matcher.build_role_def(line)
  else
    fail "Unrecognized line: #{line}"
  end
end