##// END OF EJS Templates
Added ResetState to RunnableComponent to reset in case of failure...
Added ResetState to RunnableComponent to reset in case of failure Added StateChanged event to IRunnable Renamed Promise.SUCCESS -> Promise.Success Added Promise.FromException Renamed Bundle -> PromiseAll in PromiseExtensions

File last commit:

r178:d5c5db0335ee ref20160224
r205:8200ab154c8a v2
Show More
Token.cs
63 lines | 1.7 KiB | text/x-csharp | CSharpLexer
cin
DFA refactoring
r162 using Implab;
using System;
using System.Linq;
namespace Implab.Automaton.RegularExpressions {
cin
refactoring
r177 public abstract class Token {
public abstract void Accept(IVisitor visitor);
cin
DFA refactoring
r162
cin
working on JSON parser
r178 public Token End() {
cin
refactoring
r177 return Cat(new EndToken());
cin
DFA refactoring
r162 }
cin
refactoring
r177 public Token Tag<TTag>(TTag tag) {
cin
DFA refactoring
r162 return Cat(new EndToken<TTag>(tag));
}
cin
refactoring
r177 public Token Cat(Token right) {
return new CatToken(this, right);
cin
DFA refactoring
r162 }
cin
refactoring
r177 public Token Or(Token right) {
return new AltToken(this, right);
cin
DFA refactoring
r162 }
cin
refactoring
r177 public Token Optional() {
return Or(new EmptyToken());
cin
DFA refactoring
r162 }
cin
refactoring
r177 public Token EClosure() {
return new StarToken(this);
cin
DFA refactoring
r162 }
cin
refactoring
r177 public Token Closure() {
return Cat(new StarToken(this));
cin
DFA refactoring
r162 }
cin
refactoring
r177 public Token Repeat(int count) {
Token token = null;
cin
DFA refactoring
r162
for (int i = 0; i < count; i++)
token = token != null ? token.Cat(this) : this;
cin
refactoring
r177 return token ?? new EmptyToken();
cin
DFA refactoring
r162 }
cin
refactoring
r177 public Token Repeat(int min, int max) {
cin
DFA refactoring
r162 if (min > max || min < 1)
throw new ArgumentOutOfRangeException();
var token = Repeat(min);
for (int i = min; i < max; i++)
cin
DFA refactoring
r165 token = token.Cat( Optional() );
cin
DFA refactoring
r162 return token;
}
cin
refactoring
r177 public static Token New(params int[] set) {
cin
DFA refactoring
r162 Safe.ArgumentNotNull(set, "set");
cin
refactoring
r177 Token token = null;
cin
DFA refactoring
r162 foreach(var c in set.Distinct())
cin
refactoring
r177 token = token == null ? new SymbolToken(c) : token.Or(new SymbolToken(c));
cin
DFA refactoring
r162 return token;
}
}
}