-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for extrapolating expected input in
the case of match failure. git-svn-id: https://piraha-peg.googlecode.com/svn/trunk@85 1a70d7c6-ffe7-ef14-4583-3269c1a2e543
- Loading branch information
1 parent
20eca28
commit 4268cde
Showing
10 changed files
with
180 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package edu.lsu.cct.piraha; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
public class Expected { | ||
Seq seq; | ||
int n; | ||
Pattern pat; | ||
int pos; | ||
Set<String> possibilities = new HashSet<String>(); | ||
int epos; | ||
Or or; | ||
|
||
void build(int maxTextPos) { | ||
pos = maxTextPos; | ||
if(pat != null) { | ||
possibilities.add(pat.decompile()); | ||
} else if(seq != null) { | ||
StringBuffer sb = new StringBuffer(); | ||
for(int j=n;j<seq.patternList.size();j++) { | ||
Pattern x = seq.patternList.get(j); | ||
if(x instanceof Literal) | ||
sb.append(x.decompile()); | ||
else if(x instanceof ILiteral) | ||
sb.append(x.decompile()); | ||
else if(x instanceof Bracket) | ||
sb.append(x.decompile()); | ||
else | ||
break; | ||
} | ||
if(sb.length()>0) | ||
possibilities.add(sb.toString()); | ||
} | ||
} | ||
|
||
public Expected() { | ||
} | ||
|
||
public Expected(Pattern pat) { | ||
this.pat = pat; | ||
} | ||
|
||
public Expected(Seq seq,int n) { | ||
this.seq = seq; | ||
this.n = n; | ||
} | ||
|
||
public Expected(Or or,int pos) { | ||
this.or = or; | ||
this.epos = pos; | ||
} | ||
|
||
public String toString() { return possibilities.toString(); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
package edu.lsu.cct.piraha; | ||
|
||
|
||
public class Near { | ||
String text,rule; | ||
Expected expected; | ||
int lineNum=1, posInLine, startOfLine, endOfLine; | ||
Near() {} | ||
public String toString() { | ||
String line = text.substring(startOfLine,endOfLine); | ||
String str = line.substring(0,posInLine)+"|"+line.substring(posInLine); | ||
String base = ""; | ||
if(expected != null) { | ||
if(expected.possibilities.size()==1) { | ||
base = "Expected: "+expected+" "; | ||
} else { | ||
base = "Expected one of: "+expected+" "; | ||
} | ||
} | ||
if(rule != null) | ||
return ""+lineNum+" in {"+rule+"}: '"+str.trim()+"'"; | ||
return base+lineNum+" in {"+rule+"}: '"+str.trim()+"'"; | ||
else | ||
return ""+lineNum+": '"+str.trim()+"'"; | ||
return base+lineNum+": '"+str.trim()+"'"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters