-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f908a3
commit 7ccc1ae
Showing
2 changed files
with
63 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,55 @@ | ||
using System; | ||
using System.Collections; | ||
|
||
namespace Marionette.Parser { | ||
public class Parser { | ||
public class Parser<TRes, TEnv> : IEnumerator<IEvaluatable<TRes, TEnv>> { | ||
private string code; | ||
private Utils.Position position; | ||
private int pointer = -1; | ||
|
||
public delegate ResultList<TRes, TEnv> ListAllocator(IEvaluatable<TRes, TEnv>[] subterms); | ||
|
||
public delegate Literal<TRes, TEnv> LiteralAllocator(string text); | ||
|
||
public delegate Symbol<TRes, TEnv> SymbolAllocator(string name); | ||
|
||
public Parser(string code) { | ||
private ListAllocator allocateList; | ||
private LiteralAllocator allocateLiteral; | ||
private SymbolAllocator allocateSymbol; | ||
|
||
private IEvaluatable<TRes, TEnv>? curResult = null; | ||
|
||
public Parser(string code, ListAllocator allocateList, LiteralAllocator allocateLiteral, SymbolAllocator allocateSymbol) { | ||
this.code = code; | ||
this.position = new Utils.Position(0, 1); | ||
this.allocateList = allocateList; | ||
this.allocateLiteral = allocateLiteral; | ||
this.allocateSymbol = allocateSymbol; | ||
position = new Utils.Position(0, 1); | ||
} | ||
|
||
private IEvaluatable<TRes, TEnv> Parse() { | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IEvaluatable<TRes, TEnv> Current => curResult ?? (curResult = Parse()); | ||
|
||
object IEnumerator.Current => curResult ?? (curResult = Parse()); | ||
|
||
public void Dispose() {} | ||
|
||
public bool MoveNext() { | ||
if (pointer >= code.Length) { | ||
return false; | ||
} | ||
else { | ||
curResult = Parse(); | ||
return true; | ||
} | ||
} | ||
|
||
public void Reset() { | ||
position = new Utils.Position(0, 1); | ||
pointer = -1; | ||
} | ||
} | ||
} // namespace Marionette.Parser |