Skip to content

Commit

Permalink
Add the capability to parse indented text.
Browse files Browse the repository at this point in the history
git-svn-id: https://piraha-peg.googlecode.com/svn/trunk@99 1a70d7c6-ffe7-ef14-4583-3269c1a2e543
  • Loading branch information
[email protected] committed Dec 10, 2014
1 parent faed3b1 commit 46b41a0
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="src" path="/util"/>
<classpathentry kind="output" path="bin"/>
</classpath>
12 changes: 12 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
5 changes: 5 additions & 0 deletions src/edu/lsu/cct/piraha/Matcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ public void addPackRat(PackRat pr,boolean b, int after,
pr.after = after;
}

// data for white space patterns
public StringBuilder white = new StringBuilder();
public List<Integer> whiteThresholds = new ArrayList<Integer>();

Expected expected;

public void expected(Expected ex) {
if(textPos == maxTextPos || ex.epos == maxTextPos) {
ex.build(maxTextPos);
Expand Down
6 changes: 6 additions & 0 deletions src/edu/lsu/cct/piraha/ReParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ Pattern compile(Group g,boolean ignCase,Grammar gram) {
String lookup = g.group(0).substring();
if("brk".equals(lookup))
return new Break();
else if("OpenWhite".equals(lookup))
return new OpenWhite();
else if("BodyWhite".equals(lookup))
return new BodyWhite();
else if("CloseWhite".equals(lookup))
return new CloseWhite();
return new Lookup(lookup, gram);
} else if("nothing".equals(pn)) {
return new Nothing();
Expand Down
10 changes: 10 additions & 0 deletions src/edu/lsu/cct/piraha/examples/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ public static void main(String[] args) throws Exception {
m = g.matcher("vector","1+2,(8+3)*9-4,4,9+7");
assert(m.matches());

g.compile("eol", "\n");
g.compile("line","line");
g.compile("line_eol","{line}{eol}");
m = g.matcher("line_eol","line\n");
assert(m.matches());

test("[\\a-c]+","abab",4);
test("[a-\\c]+","abab",4);
test("[\\a-\\c]+","acb",3);
Expand All @@ -164,6 +170,10 @@ 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}","",-1);
test("{OpenWhite}\n{BodyWhite}"," \n ",3);
test("{OpenWhite}\n{BodyWhite}\n{CloseWhite}[ \t]*"," \n \nx",6);

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

0 comments on commit 46b41a0

Please sign in to comment.