Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert Cursor into a low-level type
This will make interfacing it with the LTM engine much easier.
- Loading branch information
Showing
5 changed files
with
66 additions
and
34 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
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,25 +1,45 @@ | ||
// this exists to allow O(1) addition, since additions (esp. in the presence | ||
// of backtracking) dominate lookups | ||
public class Matched { | ||
Matched prev; | ||
string name; | ||
Variable val; | ||
bool listify_sentinel; | ||
} | ||
|
||
public class Match { | ||
public string backing; | ||
public int from; | ||
public int to; | ||
public Dictionary<string,Variable> captures; | ||
} | ||
|
||
public class Xact { | ||
|
||
//public class Matched { | ||
// Matched prev; | ||
// string name; | ||
// Variable val; | ||
// bool listify_sentinel; | ||
//} | ||
// | ||
//public class Match { | ||
// public string backing; | ||
// public int from; | ||
// public int to; | ||
// public Dictionary<string,Variable> captures; | ||
//} | ||
// | ||
//public class Xact { | ||
// | ||
|
||
public class Cursor { | ||
// TODO: use a mutable form, for <cut> | ||
// XXX It's a bit wrong that we ref the string both from the cursor and | ||
// from $*ORIG. | ||
public string backing; | ||
public int pos; | ||
public Matched captures; | ||
|
||
public Cursor(string backing, int pos) { | ||
this.backing = backing; | ||
this.pos = pos; | ||
} | ||
|
||
public Cursor(string backing) : this(backing, 0) { } | ||
|
||
public Cursor At(int npos) { | ||
return new Cursor(backing, npos); | ||
} | ||
|
||
public Cursor Exact(string what) { | ||
if (backing.Length - what.Length >= pos && | ||
backing.Substring(pos, what.Length) == what) { | ||
return At(pos + what.Length); | ||
} else { | ||
return null; | ||
} | ||
} | ||
} |
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