public void op_MoveTo_LexiconSame_LexicalItem() { var obj = new LexicalCollection(NormalityComparer.Ordinal); var item = new LexicalItem(NormalityComparer.Ordinal, "Example"); Assert.Throws <InvalidOperationException>(() => obj.MoveTo(obj, item)); }
public void op_MoveTo_LexiconNull_LexicalItem() { var obj = new LexicalCollection(NormalityComparer.Ordinal); var item = new LexicalItem(NormalityComparer.Ordinal, "Example"); Assert.Throws <ArgumentNullException>(() => obj.MoveTo(null, item)); }
/// <summary> /// Performs tests for letter lexem. /// </summary> private void CheckLetter(LexicalItem item, string letter, bool canEscape) { string lower = letter.ToLowerInvariant(); string upper = letter.ToUpperInvariant(); string lowerHex = ((int)lower[0]).ToString("x"); string upperHex = ((int)upper[0]).ToString("x"); string lowerHex1 = lowerHex.Substring(0, 1); string lowerHex2 = lowerHex.Substring(1, 1); string upperHex1 = upperHex.Substring(0, 1); string upperHex2 = upperHex.Substring(1, 1); string[] hexVariants = new[] { lowerHex1.ToLower() + lowerHex2.ToLower(), lowerHex1.ToLower() + lowerHex2.ToUpper(), lowerHex1.ToUpper() + lowerHex2.ToLower(), lowerHex1.ToUpper() + lowerHex2.ToUpper(), upperHex1.ToLower() + upperHex2.ToLower(), upperHex1.ToLower() + upperHex2.ToUpper(), upperHex1.ToUpper() + upperHex2.ToLower(), upperHex1.ToUpper() + upperHex2.ToUpper(), }; Check(true, item, lower); Check(true, item, upper); Check(false, item, lower + " "); Check(false, item, " " + lower); Check(canEscape, item, "\\" + lower); Check(canEscape, item, "\\" + upper); Check(false, item, "\\\\" + lower); Check(false, item, lower + "\\"); foreach (string hexVariant in hexVariants) { Check(true, item, "\\" + hexVariant); Check(true, item, "\\0" + hexVariant); Check(true, item, "\\00" + hexVariant); Check(true, item, "\\000" + hexVariant); Check(true, item, "\\0000" + hexVariant); Check(false, item, "\\00000" + hexVariant); Check(true, item, "\\" + hexVariant + " "); Check(false, item, "\\" + hexVariant + " "); Check(true, item, "\\0" + hexVariant + "\r\n"); Check(false, item, "\\0" + hexVariant + "\n\r"); Check(true, item, "\\00" + hexVariant + "\r"); Check(true, item, "\\00" + hexVariant + "\n"); Check(true, item, "\\00" + hexVariant + "\t"); Check(true, item, "\\00" + hexVariant + "\f"); } }
/// <summary> /// Checks whether specified data string can be fully parsed to the lexical item. /// </summary> public void Check(bool expected, LexicalItem item, string data) { bool result = Parse(item, data); if (expected != result) { throw new AssertFailedException( String.Format( "Checking for [{0}] failed. Expected:<{1}>. Actual:<{2}>.", data.ToDisplay(), expected, !expected)); } }
private void NextToken() { LexicalItem item = new LexicalItem(); if (!_lexical.GetToken(out item)) { RaiseUnexpectedEndOfFileMessage(); } if (item.Error != null) { RaiseGeneralErrorMessage(item.Error.Message); } _token = item.Token; }
/// <summary> /// Returns true only if all input data has been successfully parsed. /// </summary> public static bool ParseFull(this LexicalItem item, LexicalState state) { bool parsed = item.Parse(state); if (!parsed) { return(false); } if (!state.IsEndOfData) { return(false); } return(true); }
/// <summary> /// Initializes a new instance. /// </summary> public Optional(LexicalItem item) : base(item, Empty.S) { }
protected SpecificIdentifier(params LexicalItem[] items) { m_check = new ParseAll(items); }
/// <summary> /// Tries to parses specified data string into lexical item. /// </summary> protected override bool Parse(LexicalItem item, string data) { LexicalState state = new LexicalState(data); return(item.ParseFull(state)); }
/// <summary> /// Initializes a new instance. /// </summary> public ParseMany(LexicalItem part, LexicalItem delimiter) { m_part = part; m_delimiter = delimiter; }
/// <summary> /// Initializes a new instance. /// </summary> public ParseMany(LexicalItem part) : this(part, null) { }
/// <summary> /// Tries to parses specified data string into lexical item. /// </summary> protected abstract bool Parse(LexicalItem item, string data);
/// <summary> /// Initializes a new instance. /// </summary> public ParseExcept(LexicalItem main, LexicalItem exception) { m_main = main; m_exception = exception; }
protected SpecificAtKeyword(params LexicalItem[] items) { m_check = new ParseAll(items); }
/// <summary> /// Initializes a new instance. /// </summary> public LexicalTerminal(LexicalItem item) { m_item = item; }