Skip to content

Commit

Permalink
Fix a bug in the new whitespace processing directive, and update and …
Browse files Browse the repository at this point in the history
…correct the test suite.

git-svn-id: https://piraha-peg.googlecode.com/svn/trunk@100 1a70d7c6-ffe7-ef14-4583-3269c1a2e543
  • Loading branch information
[email protected] committed Dec 11, 2014
1 parent 46b41a0 commit 98b4528
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/edu/lsu/cct/piraha/Or.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package edu.lsu.cct.piraha;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -29,13 +30,26 @@ public boolean match(Matcher m) {
int posSave = m.getTextPos();
int sz = m.subMatches.size();
List<Expected> expecteds = new ArrayList<Expected>();
StringBuilder whSave = new StringBuilder();
List<Integer> whListSave = new ArrayList<Integer>();
whSave.append(m.white);
for(int n : m.whiteThresholds)
whListSave.add(n);
for(int i=0;i<patterns.size();i++) {
m.setTextPos(posSave);
int nsz = m.subMatches.size();
while(nsz > sz) {
m.subMatches.removeLast();
nsz--;
}

// Possibly this can be optimized.
m.white.setLength(0);
m.white.append(whSave);
m.whiteThresholds.clear();
for(int n : whListSave)
m.whiteThresholds.add(n);

boolean b = Matcher.matchAll(patterns.get(i),m);
if(b)
return true;
Expand Down
8 changes: 5 additions & 3 deletions src/edu/lsu/cct/piraha/examples/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,12 @@ public static void main(String[] args) throws Exception {
test("[^ \t\r\n\b]+","abc",3);
test("(?i:ab(c|g)ef)","ABCEF",5);
test("[0-67-9]+","1234",4);
test("{OpenWhite}"," ",3);
test("{OpenWhite}"," ",0);
test("{OpenWhite}","",-1);
test("{OpenWhite}\n{BodyWhite}"," \n ",3);
test("{OpenWhite}\n{BodyWhite}\n{CloseWhite}[ \t]*"," \n \nx",6);
test("{OpenWhite}{BodyWhite}"," \n ",1);
test("{OpenWhite}{BodyWhite}\n{CloseWhite}x[ \t]*"," \nx",4);
test("{OpenWhite}({BodyWhite}y\n{OpenWhite}{BodyWhite}x|{BodyWhite}y)"," y\n z",2);
test("{OpenWhite}({BodyWhite}y\n{OpenWhite})*"," y\n y\n y\n",7);

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

0 comments on commit 98b4528

Please sign in to comment.