Skip to content

Commit

Permalink
Minor touchups. Changed the name of a field in Near. Added a method to
Browse files Browse the repository at this point in the history
get line number in Group.



git-svn-id: https://piraha-peg.googlecode.com/svn/trunk@94 1a70d7c6-ffe7-ef14-4583-3269c1a2e543
  • Loading branch information
[email protected] committed May 7, 2013
1 parent ac6e8e7 commit 40cc7e2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/edu/lsu/cct/piraha/Group.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Near near() {
near.startOfLine = i;
}
}
near.posInLine = begin - near.startOfLine;
near.pos = begin - near.startOfLine;
near.endOfLine = begin;
//for(near.endOfLine = begin; near.endOfLine < text.length();near.endOfLine++)
for(int n = begin;n < text.length();n++) {
Expand Down Expand Up @@ -396,4 +396,13 @@ public boolean equals(Object o) {
}
return false;
}

public int getLine() {
int n = 1;
for(int i=0;i<begin;i++) {
if(text.charAt(i)=='\n')
n++;
}
return n;
}
}
3 changes: 1 addition & 2 deletions src/edu/lsu/cct/piraha/Lookup.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package edu.lsu.cct.piraha;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -65,7 +64,7 @@ public boolean match(Matcher m) {
}
m.savedMatches.push(m.subMatches);
m.subMatches = new LinkedList<Group>();
//String lookupSave = m.lookup;
//String lookupSave = m.lookup
m.lookStack.push(lookup);
try {
m.lookup = fullName;
Expand Down
2 changes: 1 addition & 1 deletion src/edu/lsu/cct/piraha/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Near near() {
near.startOfLine = i;
}
}
near.posInLine = maxTextPos - near.startOfLine;
near.pos = maxTextPos - near.startOfLine;
near.endOfLine = maxTextPos;
for(; near.endOfLine < text.length();near.endOfLine++)
if(text.charAt(near.endOfLine) == '\n')
Expand Down
4 changes: 2 additions & 2 deletions src/edu/lsu/cct/piraha/Near.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
public class Near {
public String text,rule;
public Expected expected;
public int lineNum=1, posInLine, startOfLine, endOfLine;
public int lineNum=1, pos, startOfLine, endOfLine;
public Near() {}
public String toString() {
String line = text.substring(startOfLine,endOfLine);
String str = line.substring(0,posInLine)+"|"+line.substring(posInLine);
String str = line.substring(0,pos)+"|"+line.substring(pos);
String base = "";
if(expected != null) {
if(expected.possibilities.size()==1) {
Expand Down
1 change: 1 addition & 0 deletions src/edu/lsu/cct/piraha/examples/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ public static void main(String[] args) throws Exception {
test("(b{brk}|.)*","aaabaaa",4);
test("[^ \t\r\n\b]+","abc",3);
test("(?i:ab(c|g)ef)","ABCEF",5);
test("[0-67-9]+","1234",4);

g = new Grammar();
g.compile("import", "import");
Expand Down

0 comments on commit 40cc7e2

Please sign in to comment.