/// <summary> /// Tries to parse a batch of similar lexical items with specified delimiter. /// </summary> public bool ParseMany(LexicalState state, LexicalItem part, LexicalItem delimiter) { int index = state.Position; if (!part.Parse(state)) { return(false); } while (true) { int lastIndex = state.Position; if (delimiter != null) { if (!delimiter.Parse(state)) { break; } } if (!part.Parse(state)) { state.Reset(lastIndex); break; } } state.AddBack(Key, index); return(true); }
/// <summary> /// Tries to parse all specified items except some others. /// </summary> public bool ParseExcept(LexicalState state, LexicalItem main, LexicalItem exception) { int index = state.Position; if (!main.Parse(state)) { return(false); } string parsed = state.Get(main.Key, index); LexicalState check = new LexicalState(parsed); if (exception.Parse(check)) { if (check.IsEndOfData) { state.Reset(index); return(false); } } state.AddBack(Key, index); return(true); }
/// <summary> /// Tries to parse any of specified lexical items. /// </summary> public bool ParseAny(LexicalState state, params LexicalItem[] parts) { int index = state.Position; foreach (LexicalItem part in parts) { if (part.Parse(state)) { state.AddBack(Key, index); return(true); } } return(false); }
/// <summary> /// Tries to parse any of specified lexical items. /// </summary> public bool ParseAny(LexicalState state, params LexicalItem[] parts) { int index = state.Position; foreach (LexicalItem part in parts) { if (part.Parse(state)) { state.AddBack(Key, index); return true; } } return false; }
public override bool Parse(LexicalState state) { int index = state.Position; if (!UnicodeEscapeSequence.S.Parse(state)) return false; string sequence = state.Get(UnicodeEscapeSequence.S.Key, index); char c = (char)Convert.ToInt32(sequence.Substring(2), 16); if (!m_categories.Contains(Char.GetUnicodeCategory(c))) { state.Reset(index); return false; } state.AddBack(Key, index); return true; }
/// <summary> /// Tries to parse a consequent number of specified lexical items. /// </summary> public bool ParseAll(LexicalState state, params LexicalItem[] parts) { int index = state.Position; bool parsed = true; foreach (LexicalItem part in parts) { if (!part.Parse(state)) { parsed = false; break; } } if (!parsed) { state.Reset(index); return false; } state.AddBack(Key, index); return true; }
/// <summary> /// Tries to parse a consequent number of specified lexical items. /// </summary> public bool ParseAll(LexicalState state, params LexicalItem[] parts) { int index = state.Position; bool parsed = true; foreach (LexicalItem part in parts) { if (!part.Parse(state)) { parsed = false; break; } } if (!parsed) { state.Reset(index); return(false); } state.AddBack(Key, index); return(true); }
/// <summary> /// Tries to parse all specified items except some others. /// </summary> public bool ParseExcept(LexicalState state, LexicalItem main, LexicalItem exception) { int index = state.Position; if (!main.Parse(state)) return false; string parsed = state.Get(main.Key, index); LexicalState check = new LexicalState(parsed); if (exception.Parse(check)) { if (check.IsEndOfData) { state.Reset(index); return false; } } state.AddBack(Key, index); return true; }
/// <summary> /// Tries to parse a batch of similar lexical items with specified delimiter. /// </summary> public bool ParseMany(LexicalState state, LexicalItem part, LexicalItem delimiter) { int index = state.Position; if (!part.Parse(state)) return false; while (true) { int lastIndex = state.Position; if (delimiter != null) { if (!delimiter.Parse(state)) break; } if (!part.Parse(state)) { state.Reset(lastIndex); break; } } state.AddBack(Key, index); return true; }