private LexicalToken ProcessRegEx(char ch) { if (_processState == null) { if (ch == '/') { ReadChar(); _processState = ConsumeBuffer(); return(null); } else if (!IsLineBreak(ch)) { _textBuffer.Append(ReadChar()); return(null); } throw new SyntaxException("Newline in constant"); } else { if (IsRegexOption(ch)) { _textBuffer.Append(ReadChar()); return(null); } LexicalToken t = new LexicalToken(LexicalTokenType.RegularExpression); t.Value = (string)_processState; t.Tag = ConsumeBuffer(); return(t); } }
/// <summary> /// Reads the next token from stream. /// </summary> /// <returns><c>true</c> if the next token was read successfully; otherwise, <c>false</c>.</returns> public virtual bool Read() { if (_state == State.Initial) { _textBuffer = new StringBuilder(16); _indentLevels = new Stack <int>(8); _newline = true; _current = new LexicalToken(); lastToken = new LexicalToken(); Line = 1; Column = 1; _state = State.Open; } if (_state == State.Closed) { throw new ObjectDisposedException("LexicalProcessor"); } while (_state != State.EndOfFile) { int c = sourceBuffer.Peek(); if (c < 0) { _state = State.EndOfFile; break; } LexicalToken result = null; char ch = (char)c; try { switch (_state) { case State.LineBreak: result = ProcessLineBreak(ch); break; case State.Whitespace: result = ProcessWhitespace(ch); break; case State.Comment: result = ProcessComment(ch); break; case State.Token: result = ProcessToken(ch); break; case State.Directive: result = ProcessDirective(ch); break; case State.RegularExpression: result = ProcessRegEx(ch); break; default: result = ProcessOpen(ch); break; } } catch { _state = State.Error; throw; } if (result != null) { _current = result; return(true); } } return(false); }