Exception: AmbigousParseException
- Defined in:
- lib/rpdf2txt-rockit/parsing_ambiguities.rb
Instance Attribute Summary collapse
-
#alternatives ⇒ Object
readonly
Returns the value of attribute alternatives.
-
#substring ⇒ Object
readonly
Returns the value of attribute substring.
Instance Method Summary collapse
- #difference_description(i, j, str0, o1, o2, childPath = "") ⇒ Object
-
#initialize(stringBeingParsed, fullTree, *alternativeTrees) ⇒ AmbigousParseException
constructor
A new instance of AmbigousParseException.
- #inspect(prettyPrinter = nil) ⇒ Object
- #report_on_tree_differences(t1, t2, i, j, childPath = "") ⇒ Object
Constructor Details
#initialize(stringBeingParsed, fullTree, *alternativeTrees) ⇒ AmbigousParseException
Returns a new instance of AmbigousParseException.
17 18 19 20 21 |
# File 'lib/rpdf2txt-rockit/parsing_ambiguities.rb', line 17 def initialize(stringBeingParsed, fullTree, *alternativeTrees) super("Ambigous parse") @alternatives, @full_tree = alternativeTrees, fullTree init_substring(stringBeingParsed) end |
Instance Attribute Details
#alternatives ⇒ Object (readonly)
Returns the value of attribute alternatives.
15 16 17 |
# File 'lib/rpdf2txt-rockit/parsing_ambiguities.rb', line 15 def alternatives @alternatives end |
#substring ⇒ Object (readonly)
Returns the value of attribute substring.
15 16 17 |
# File 'lib/rpdf2txt-rockit/parsing_ambiguities.rb', line 15 def substring @substring end |
Instance Method Details
#difference_description(i, j, str0, o1, o2, childPath = "") ⇒ Object
47 48 49 50 51 52 |
# File 'lib/rpdf2txt-rockit/parsing_ambiguities.rb', line 47 def difference_description(i, j, str0, o1, o2, childPath = "") child_str = childPath.length > 0 ? "in the childrens '#{childPath[1..-1]}'" : "" " Alternatives #{i+1} and #{j+1} differ #{child_str} by not having" + " the same #{str0} (#{o1.inspect} and #{o2.inspect})" end |
#inspect(prettyPrinter = nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rpdf2txt-rockit/parsing_ambiguities.rb', line 23 def inspect(prettyPrinter = nil) str = "Ambiguity: The substring '#{substring}' can be parsed as:\n" #return str + report_on_tree_differences(alternatives[0], alternatives[1], 0, 1) strings_to_show, same_strings = Array.new, Array.new alternatives.each_with_index {|alt, i| s = prettyPrinter ? prettyPrinter.print(alt) : alt.inspect if (j = strings_to_show.index(s)) same_strings.push [j,i] end strings_to_show.push s } alternatives.each_with_index do |alt,i| str << " Alternative #{i+1}: #{strings_to_show[i]}" str << ", or" if i < alternatives.length-1 str << "\n" end same_strings.each do |i,j| str += report_on_tree_differences(alternatives[i], alternatives[j], i, j) end @full_tree.compact! str + "The full tree looks like:\n" + @full_tree.inspect end |
#report_on_tree_differences(t1, t2, i, j, childPath = "") ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rpdf2txt-rockit/parsing_ambiguities.rb', line 54 def report_on_tree_differences(t1, t2, i, j, childPath = "") if t1.class != t2.class difference_description(i, j, "type", t1.class, t2.class, childPath) elsif not t1.kind_of?(SyntaxTree) if t1 != t2 " Alternatives #{i} and #{j} are not SyntaxTree's and differ" else "" end elsif t1.name != t2.name difference_description(i, j, "name", t1.name, t2.name, childPath) elsif t1.children_names != t2.children_names difference_description(i, j, "children_names",t1.children_names, t2.children_names, childPath) else t1.childrens.each_with_index do |child, k| report = report_on_tree_differences(child, t2[k], i, j, childPath + "." + t1.children_names[k]) return report if report.length > 0 end return "" end end |