Skip to content

Instantly share code, notes, and snippets.

@sehe
Last active December 13, 2015 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sehe/4994490 to your computer and use it in GitHub Desktop.
Save sehe/4994490 to your computer and use it in GitHub Desktop.
private T ParseOneOf<T>(params Func<T>[] fs) {
var oldLexer = Lexer.Clone();
foreach (var f in fs) {
try {
return f();
} catch (SyntaxErrorException) {
Lexer = oldLexer;
}
}
throw new SyntaxErrorException();
}
private IEnumerable<T> ParseMany<T>(Func<T> f) {
for (; ; ) {
var oldLexer = Lexer.Clone();
T v = default(T);
try {
v = f();
} catch (SyntaxErrorException) {
Lexer = oldLexer;
yield break;
}
yield return v;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment