-
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.
Add parsing for parsing indentation.
git-svn-id: https://piraha-peg.googlecode.com/svn/trunk@101 1a70d7c6-ffe7-ef14-4583-3269c1a2e543
- Loading branch information
1 parent
98b4528
commit c5ad6aa
Showing
3 changed files
with
144 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package edu.lsu.cct.piraha; | ||
|
||
import edu.lsu.cct.util.Here; | ||
|
||
public class BodyWhite extends Pattern { | ||
|
||
@Override | ||
public boolean match(Matcher m) { | ||
int pos = m.getTextPos(); | ||
if(pos==0 || m.text.charAt(pos-1)=='\n') { | ||
int newPos = pos; | ||
for(;newPos<m.text.length();newPos++) { | ||
char c = m.text.charAt(newPos); | ||
if(c == ' '||c == '\t') { | ||
int n = newPos - pos; | ||
if(n < m.white.length()) { | ||
if(c != m.white.charAt(n)) { | ||
return false; | ||
} | ||
if(n+1 == m.white.length()) { | ||
m.setTextPos(newPos+1); | ||
return true; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public String decompile() { | ||
return "{BodyWhite}"; | ||
} | ||
|
||
@Override | ||
public boolean eq(Object obj) { | ||
return obj instanceof BodyWhite; | ||
} | ||
|
||
} |
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,51 @@ | ||
package edu.lsu.cct.piraha; | ||
|
||
import edu.lsu.cct.util.Here; | ||
|
||
|
||
public class CloseWhite extends Pattern { | ||
|
||
@Override | ||
public boolean match(Matcher m) { | ||
int pos = m.getTextPos(); | ||
if(pos==0 || m.text.charAt(pos-1)=='\n') { | ||
int thresh = 0; | ||
int nt = m.whiteThresholds.size(); | ||
if(nt > 0) { | ||
thresh = m.whiteThresholds.get(nt-1); | ||
} | ||
int newPos = pos; | ||
for(;newPos<m.text.length();newPos++) { | ||
char c = m.text.charAt(newPos); | ||
if(c == ' '||c == '\t') { | ||
; | ||
} else { | ||
break; | ||
} | ||
} | ||
if(newPos-pos <= thresh) { | ||
int n = m.whiteThresholds.remove(nt-1); | ||
if(nt == 1) | ||
m.white.setLength(0); | ||
else | ||
m.white.setLength(m.whiteThresholds.get(nt-2)); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public String decompile() { | ||
return "{CloseWhite}"; | ||
} | ||
|
||
@Override | ||
public boolean eq(Object obj) { | ||
return obj instanceof CloseWhite; | ||
} | ||
|
||
} |
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,48 @@ | ||
package edu.lsu.cct.piraha; | ||
|
||
public class OpenWhite extends Pattern { | ||
|
||
@Override | ||
public boolean match(Matcher m) { | ||
int pos = m.getTextPos(); | ||
if(pos==0 || m.text.charAt(pos-1)=='\n') { | ||
int newPos = pos; | ||
boolean newWhite = false; | ||
StringBuilder saveWhite = new StringBuilder(); | ||
for(;newPos<m.text.length();newPos++) { | ||
char c = m.text.charAt(newPos); | ||
if(c == ' '||c == '\t') { | ||
int n = newPos - pos; | ||
if(n < m.white.length()) { | ||
if(c != m.white.charAt(n)) { | ||
return false; | ||
} | ||
} else { | ||
saveWhite.append(c); | ||
newWhite = true; | ||
} | ||
} else { | ||
break; | ||
} | ||
} | ||
if(newWhite) { | ||
m.whiteThresholds.add(newPos-pos); | ||
m.white.append(saveWhite); | ||
} | ||
return newWhite; | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
@Override | ||
public String decompile() { | ||
return "{OpenWhite}"; | ||
} | ||
|
||
@Override | ||
public boolean eq(Object obj) { | ||
return obj instanceof OpenWhite; | ||
} | ||
|
||
} |