Changeset 290
- Timestamp:
- 05/19/08 22:00:34 (8 months ago)
- Files:
-
- lex/trunk/src/com/qwirx/lex/parser/Edge.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/parser/Parser.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/parser/Rule.java (modified) (2 diffs)
- lex/trunk/src/com/qwirx/lex/parser/RuleEdge.java (modified) (1 diff)
- lex/trunk/src/com/qwirx/lex/parser/WordEdge.java (modified) (1 diff)
- lex/trunk/test/com/qwirx/lex/ParserTest.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lex/trunk/src/com/qwirx/lex/parser/Edge.java
r125 r290 41 41 boolean isAt(int pos); 42 42 boolean includes(Edge other); 43 boolean uses(Rule rule); 43 44 TreeNode toTree(); 44 45 String getHtmlLabel(); lex/trunk/src/com/qwirx/lex/parser/MorphEdge.java
r259 r290 146 146 } 147 147 148 public boolean uses(Rule rule) 149 { 150 return false; 151 } 152 148 153 public String getHtmlLabel() 149 154 { lex/trunk/src/com/qwirx/lex/parser/Parser.java
r142 r290 90 90 } 91 91 */ 92 93 // Don't re-use a rule that's already been used 94 // somewhere in this edge. That could lead to 95 // infinite recursion and should not be necessary. 92 96 93 97 Rule rule = rules[r]; 94 List newEdges = rule.applyTo(chart, i); 95 inputCopy.addAll(i + 1, newEdges); 98 99 if (!inputEdge.uses(rule)) 100 { 101 List newEdges = rule.applyTo(chart, i); 102 inputCopy.addAll(i + 1, newEdges); 103 } 96 104 } 97 105 } lex/trunk/src/com/qwirx/lex/parser/Rule.java
r120 r290 688 688 } 689 689 690 private void continueParseWithNextPart(List newEdges)690 private void continueParseWithNextPart(List<Edge> newEdges) 691 691 { 692 692 boolean foundUnfinishedPart = false; … … 719 719 // and we should be ready to create a new edge. 720 720 721 // don't create new edges which don't contain any other edges :722 // we could keep doing that forever.721 // don't create new edges which don't contain any other edges 722 // (all parts optional and skipped): we could keep doing that forever. 723 723 724 724 int numEdges = 0; lex/trunk/src/com/qwirx/lex/parser/RuleEdge.java
r121 r290 459 459 return false; 460 460 } 461 461 462 public boolean uses(Rule rule) 463 { 464 if (this.rule == rule) 465 { 466 return true; 467 } 468 469 for (int i = 0; i < parts.length; i++) 470 { 471 if (parts[i].uses(rule)) 472 { 473 return true; 474 } 475 } 476 477 return false; 478 } 479 480 462 481 public void getLeavesInto(List leaves) 463 482 { lex/trunk/src/com/qwirx/lex/parser/WordEdge.java
r123 r290 139 139 } 140 140 141 public boolean uses(Rule rule) 142 { 143 return false; 144 } 145 141 146 public String getHtmlLabel() 142 147 { lex/trunk/test/com/qwirx/lex/ParserTest.java
r131 r290 2006 2006 } 2007 2007 2008 public void testInfiniteLoop() throws Exception 2009 { 2010 Rule[] rules = new Rule[]{ 2011 Rule.makeFromString2(1, "C", "{B}"), 2012 Rule.makeFromString2(2, "B", "x"), 2013 Rule.makeFromString2(3, "B", "{A}"), 2014 Rule.makeFromString2(4, "A", "{B}"), 2015 }; 2016 2017 Parser p = new Parser(rules); 2018 p.setVerbose(true); 2019 2020 List results = p.parseFor("x", "C"); 2021 assertEquals(2, results.size()); 2022 2023 Edge C = (Edge)(results.get(1)); 2024 assertEquals("C", C.symbol()); 2025 assertEquals("B", C.part(0).symbol()); 2026 assertEquals("x", C.part(0).part(0).symbol()); 2027 2028 C = (Edge)(results.get(0)); 2029 assertEquals("C", C.symbol()); 2030 assertEquals("B", C.part(0).symbol()); 2031 assertEquals("A", C.part(0).part(0).symbol()); 2032 assertEquals("B", C.part(0).part(0).part(0).symbol()); 2033 assertEquals("x", C.part(0).part(0).part(0).part(0).symbol()); 2034 } 2035 2008 2036 public static void main(String[] args) 2009 2037 {
