private Lexer(string text, TextReader reader, LexerBehavior behavior, LexerSettings settings) { if (settings == null) { settings = LexerSettings.Default; } else { settings = settings.Clone(); } this.text = text; this.reader = reader; this.behavior = behavior; this.settings = settings; if (settings.Symbols != null) { foreach (KeyValuePair <string, int> entry in settings.Symbols) { int len = entry.Key.Length; if (len > maxSymLen) { maxSymLen = len; } } } Reset(); }
public Parser() { LB = LexerBehavior.SkipComments | LexerBehavior.SkipWhiteSpaces | LexerBehavior.Default; LS = LexerSettings.Default; LS.Options = LexerOptions.StringDoubleQuote | LexerOptions.StringEscaping; LS.Keywords = new Dictionary <string, int>(); string[] KeywordNames = Enum.GetNames(typeof(Keyword)); for (int i = 0; i < KeywordNames.Length; i++) { if (KeywordNames[i].StartsWith("_")) { continue; } LS.Keywords.Add(KeywordNames[i].ToLower(), (int)(Keyword)Enum.Parse(typeof(Keyword), KeywordNames[i])); } LS.Symbols = new Dictionary <string, int>(); LS.Symbols.Add("(", (int)Symbol.LParen); LS.Symbols.Add(")", (int)Symbol.RParen); LS.Symbols.Add("{", (int)Symbol.LCurvy); LS.Symbols.Add("}", (int)Symbol.RCurvy); LS.Symbols.Add(",", (int)Symbol.Comma); LS.Symbols.Add(";", (int)Symbol.Semicolon); LS.Symbols.Add("=", (int)Symbol.Assign); }
public Token PeekNextToken(LexerBehavior behavior) { LexerBehavior saveBehavior = this.behavior; this.behavior = behavior; try { return(PeekNextToken()); } finally { this.behavior = saveBehavior; } }
public Lexer(string text, LexerBehavior behavior) : this(text, null, behavior, null) { }
public Lexer(string text, LexerBehavior behavior, LexerSettings settings) : this(text, null, behavior, settings) { }
public Lexer(TextReader reader, LexerBehavior behavior) : this(null, reader, behavior, null) { }
public Lexer(TextReader reader, LexerBehavior behavior, LexerSettings settings) : this(null, reader, behavior, settings) { }