public FSM(LaconfigLexer lex) { lexer = lex; source = lexer.Source; tokens = lexer.m_Tokens; srcRef = lexer.SourceCodeReference; }
public void ePrematureEOF_Thrown() { var src = @""; var lxr = new LL(new StringSource(src)); lxr.AnalyzeAll(); }
public void String_Escapes2() { var src = @"{'str\'ing'}"; var lxr = new LL(new StringSource(src)); Aver.AreEqual(@"str'ing", lxr.ElementAt(2).Text); }
public void eUnterminatedString2() { var src = @"a: ""aaaa"; var lxr = new LL(new StringSource(src)); lxr.AnalyzeAll(); }
public void String_Escapes1() { var src = @"{""str\""ing""}"; var lxr = new LL(new StringSource(src)); Assert.AreEqual(@"str""ing", lxr.ElementAt(2).Text); }
public void String_Escapes2_2() { var src = @"a{ n = 'string\''}"; var lxr = new LL(new StringSource(src)); Assert.AreEqual(@"string'", lxr.ElementAt(5).Text); }
public void String_Escapes3() { var src = @"{'str\n\rring'}"; var lxr = new LL(new StringSource(src)); Assert.AreEqual("str\n\rring", lxr.ElementAt(2).Text); }
public void String_Escapes5_Unicode() { var src = @"{""str\u8978ring""}"; var lxr = new LL(new StringSource(src)); Assert.AreEqual("str\u8978ring", lxr.ElementAt(2).Text); }
public void String_Escapes4_Unicode() { var src = @"{'str\u8978ring'}"; var lxr = new LL(new StringSource(src)); Aver.AreEqual("str\u8978ring", lxr.ElementAt(2).Text); }
public void BOF_EOF() { var src = @"a"; var lxr = new LL(new StringSource(src)); var expected = new LaconfigTokenType[]{LaconfigTokenType.tBOF, LaconfigTokenType.tIdentifier, LaconfigTokenType.tEOF}; Assert.IsTrue( lxr.Select(t => t.Type).SequenceEqual(expected) ); }
public void String2() { var src = @"{""string""}"; var lxr = new LL(new StringSource(src)); var expected = new LaconfigTokenType[] { LaconfigTokenType.tBOF, LaconfigTokenType.tBraceOpen, LaconfigTokenType.tStringLiteral, LaconfigTokenType.tBraceClose, LaconfigTokenType.tEOF }; Assert.IsTrue(lxr.Select(t => t.Type).SequenceEqual(expected)); }
public void BOF_EOF() { var src = @"a"; var lxr = new LL(new StringSource(src)); var expected = new LaconfigTokenType[] { LaconfigTokenType.tBOF, LaconfigTokenType.tIdentifier, LaconfigTokenType.tEOF }; Assert.IsTrue(lxr.Select(t => t.Type).SequenceEqual(expected)); }
public void eUnterminatedString4_Verbatim() { var src = @"a: $'aa aa"; var lxr = new LL(new StringSource(src)); lxr.AnalyzeAll(); }
public void eUnterminatedComment1() { var src = @"a: /*aa aa"; var lxr = new LL(new StringSource(src)); lxr.AnalyzeAll(); }
public void Comments8() { var src = @"{ /* //comment text " + "\r\n" + @" */ } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual(" //comment text \r\n ", lxr.ElementAt(2).Text); }
public void Comments9() { var src = @"{ /* //comment text " + "\n\r" + @" */ } "; var lxr = new LL(new StringSource(src)); Aver.AreEqual(" //comment text \n\r ", lxr.ElementAt(2).Text); }
public void Comments4() { var src = @"{ //comment text } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual("comment text", lxr.ElementAt(2).Text); }
public void Comments10() { var src = @"{ |* /* //comment text " + "\n\r" + @" */ *| } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual(" /* //comment text \n\r */ ", lxr.ElementAt(2).Text); }
public void ePrematureEOF_CouldLogButThrown() { var src = @""; var msgs = new MessageList(); var lxr = new LL(new StringSource(src), msgs, throwErrors: true); lxr.AnalyzeAll(); Assert.IsNotNull(msgs.FirstOrDefault(m => m.Type == MessageType.Error && m.Code == (int)LaconfigMsgCode.ePrematureEOF)); }
public void Comments13withStrings() { var src = @"{ |*'aaaa /* //comment""text " + "\n\r" + @" */ *| } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual(LaconfigTokenType.tComment, lxr.ElementAt(2).Type); Assert.AreEqual("'aaaa /* //comment\"text \n\r */ ", lxr.ElementAt(2).Text); }
public void ePrematureEOF_Logged() { var src = @""; var msgs = new MessageList(); var lxr = new LL(new StringSource(src), msgs); lxr.AnalyzeAll(); Aver.IsNotNull(msgs.FirstOrDefault(m => m.Type == MessageType.Error && m.Code == (int)LaconfigMsgCode.ePrematureEOF)); }
public void Comments11withStrings() { var src = @"{ $'|* /* //comment text " + "\n\r" + @" */ *|' } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual(LaconfigTokenType.tStringLiteral, lxr.ElementAt(2).Type); Assert.AreEqual("|* /* //comment text \n\r */ *|", lxr.ElementAt(2).Text); }
public void Comments12withStrings() { //string is opened but line break var src = @"{ '|* /* //comment text " + "\n\r" + @" */ *|' } "; var lxr = new LL(new StringSource(src)); lxr.AnalyzeAll(); }
public void Comments2() { var src = @"{ /*'string'}*/ } "; var lxr = new LL(new StringSource(src)); var expected = new LaconfigTokenType[] { LaconfigTokenType.tBOF, LaconfigTokenType.tBraceOpen, LaconfigTokenType.tComment, LaconfigTokenType.tBraceClose, LaconfigTokenType.tEOF }; Assert.IsTrue(lxr.Select(t => t.Type).SequenceEqual(expected)); }
public void TokenClassifications() { var src = @"a 'string' = 12 {} //comment"; var tokens = new LL(new StringSource(src)).Tokens; Assert.IsTrue(tokens[0].IsBOF); Assert.IsTrue(tokens[0].IsNonLanguage); Assert.IsFalse(tokens[0].IsPrimary); Assert.AreEqual(TokenKind.BOF, tokens[0].Kind); Assert.AreEqual(LaconfigTokenType.tIdentifier, tokens[1].Type); Assert.IsFalse(tokens[1].IsNonLanguage); Assert.IsTrue(tokens[1].IsPrimary); Assert.AreEqual(TokenKind.Identifier, tokens[1].Kind); Assert.AreEqual(LaconfigTokenType.tStringLiteral, tokens[2].Type); Assert.IsFalse(tokens[2].IsNonLanguage); Assert.IsTrue(tokens[2].IsPrimary); Assert.IsTrue(tokens[2].IsTextualLiteral); Assert.AreEqual(TokenKind.Literal, tokens[2].Kind); Assert.AreEqual(LaconfigTokenType.tEQ, tokens[3].Type); Assert.IsFalse(tokens[3].IsNonLanguage); Assert.IsTrue(tokens[3].IsPrimary); Assert.IsTrue(tokens[3].IsOperator); Assert.AreEqual(TokenKind.Operator, tokens[3].Kind); Assert.AreEqual(LaconfigTokenType.tIdentifier, tokens[4].Type); Assert.IsFalse(tokens[4].IsNonLanguage); Assert.IsTrue(tokens[4].IsPrimary); Assert.AreEqual(TokenKind.Identifier, tokens[4].Kind); Assert.AreEqual(LaconfigTokenType.tBraceOpen, tokens[5].Type); Assert.IsFalse(tokens[5].IsNonLanguage); Assert.IsTrue(tokens[5].IsPrimary); Assert.AreEqual(TokenKind.Symbol, tokens[5].Kind); Assert.AreEqual(LaconfigTokenType.tBraceClose, tokens[6].Type); Assert.IsFalse(tokens[6].IsNonLanguage); Assert.IsTrue(tokens[6].IsPrimary); Assert.AreEqual(TokenKind.Symbol, tokens[6].Kind); Assert.AreEqual(LaconfigTokenType.tComment, tokens[7].Type); Assert.IsFalse(tokens[7].IsNonLanguage); Assert.IsFalse(tokens[7].IsPrimary); Assert.IsTrue(tokens[7].IsComment); Assert.AreEqual(TokenKind.Comment, tokens[7].Kind); }
public void Comments11withStrings() { var src = @"{ $'|* /* //comment text "+"\n\r"+@" */ *|' } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual(LaconfigTokenType.tStringLiteral, lxr.ElementAt(2).Type); Assert.AreEqual("|* /* //comment text \n\r */ *|", lxr.ElementAt(2).Text); }
public void Comments10() { var src = @"{ |* /* //comment text "+"\n\r"+@" */ *| } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual(" /* //comment text \n\r */ ", lxr.ElementAt(2).Text); }
public void Comments13withStrings() { var src = @"{ |*'aaaa /* //comment""text "+"\n\r"+@" */ *| } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual(LaconfigTokenType.tComment, lxr.ElementAt(2).Type); Assert.AreEqual("'aaaa /* //comment\"text \n\r */ ", lxr.ElementAt(2).Text); }
public void Comments12withStrings() { //string is opened but line break var src = @"{ '|* /* //comment text "+"\n\r"+@" */ *|' } "; var lxr = new LL(new StringSource(src)); lxr.AnalyzeAll(); }
public void String2() { var src = @"{""string""}"; var lxr = new LL(new StringSource(src)); var expected = new LaconfigTokenType[]{LaconfigTokenType.tBOF, LaconfigTokenType.tBraceOpen, LaconfigTokenType.tStringLiteral, LaconfigTokenType.tBraceClose, LaconfigTokenType.tEOF}; Assert.IsTrue( lxr.Select(t => t.Type).SequenceEqual(expected) ); }
public LaconfigToken(LaconfigLexer lexer, LaconfigTokenType type, SourcePosition startPos, SourcePosition endPos, string text, object value = null) : base(lexer, startPos, endPos, text, value) { Type = type; }
public void TokenClassifications() { var src = @"a 'string' = 12 {} //comment"; var tokens = new LL(new StringSource(src)).Tokens; Assert.IsTrue( tokens[0].IsBOF); Assert.IsTrue( tokens[0].IsNonLanguage); Assert.IsFalse( tokens[0].IsPrimary); Assert.AreEqual(TokenKind.BOF, tokens[0].Kind); Assert.AreEqual( LaconfigTokenType.tIdentifier, tokens[1].Type); Assert.IsFalse( tokens[1].IsNonLanguage); Assert.IsTrue( tokens[1].IsPrimary); Assert.AreEqual(TokenKind.Identifier, tokens[1].Kind); Assert.AreEqual( LaconfigTokenType.tStringLiteral, tokens[2].Type); Assert.IsFalse( tokens[2].IsNonLanguage); Assert.IsTrue( tokens[2].IsPrimary); Assert.IsTrue( tokens[2].IsTextualLiteral); Assert.AreEqual(TokenKind.Literal, tokens[2].Kind); Assert.AreEqual( LaconfigTokenType.tEQ, tokens[3].Type); Assert.IsFalse( tokens[3].IsNonLanguage); Assert.IsTrue( tokens[3].IsPrimary); Assert.IsTrue( tokens[3].IsOperator); Assert.AreEqual(TokenKind.Operator, tokens[3].Kind); Assert.AreEqual( LaconfigTokenType.tIdentifier, tokens[4].Type); Assert.IsFalse( tokens[4].IsNonLanguage); Assert.IsTrue( tokens[4].IsPrimary); Assert.AreEqual(TokenKind.Identifier, tokens[4].Kind); Assert.AreEqual( LaconfigTokenType.tBraceOpen, tokens[5].Type); Assert.IsFalse( tokens[5].IsNonLanguage); Assert.IsTrue( tokens[5].IsPrimary); Assert.AreEqual(TokenKind.Symbol, tokens[5].Kind); Assert.AreEqual( LaconfigTokenType.tBraceClose, tokens[6].Type); Assert.IsFalse( tokens[6].IsNonLanguage); Assert.IsTrue( tokens[6].IsPrimary); Assert.AreEqual(TokenKind.Symbol, tokens[6].Kind); Assert.AreEqual( LaconfigTokenType.tComment, tokens[7].Type); Assert.IsFalse( tokens[7].IsNonLanguage); Assert.IsFalse( tokens[7].IsPrimary); Assert.IsTrue( tokens[7].IsComment); Assert.AreEqual(TokenKind.Comment, tokens[7].Kind); }
public void Comments8() { var src = @"{ /* //comment text "+"\r\n"+@" */ } "; var lxr = new LL(new StringSource(src)); Assert.AreEqual(" //comment text \r\n ", lxr.ElementAt(2).Text); }
public void Comments3() { var src = @"{/* 'string //'}//inner */ } "; var lxr = new LL(new StringSource(src)); var expected = new LaconfigTokenType[]{LaconfigTokenType.tBOF, LaconfigTokenType.tBraceOpen, LaconfigTokenType.tComment, LaconfigTokenType.tBraceClose, LaconfigTokenType.tEOF}; Assert.IsTrue( lxr.Select(t => t.Type).SequenceEqual(expected) ); }