Exemple #1
0
 public FSM(LaconfigLexer lex)
 {
     lexer  = lex;
     source = lexer.Source;
     tokens = lexer.m_Tokens;
     srcRef = lexer.SourceCodeReference;
 }
Exemple #2
0
        public void ePrematureEOF_Thrown()
        {
          var src = @"";

          var lxr = new LL(new StringSource(src));
          lxr.AnalyzeAll();
        }
Exemple #3
0
        public void String_Escapes2()
        {
            var src = @"{'str\'ing'}";

            var lxr = new LL(new StringSource(src));

            Aver.AreEqual(@"str'ing", lxr.ElementAt(2).Text);
        }
Exemple #4
0
        public void eUnterminatedString2()
        {
            var src = @"a: ""aaaa";

            var lxr = new LL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemple #5
0
        public void String_Escapes1()
        {
            var src = @"{""str\""ing""}";

            var lxr = new LL(new StringSource(src));

            Assert.AreEqual(@"str""ing", lxr.ElementAt(2).Text);
        }
Exemple #6
0
        public void String_Escapes2_2()
        {
            var src = @"a{ n = 'string\''}";

            var lxr = new LL(new StringSource(src));

            Assert.AreEqual(@"string'", lxr.ElementAt(5).Text);
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        public void String_Escapes5_Unicode()
        {
            var src = @"{""str\u8978ring""}";

            var lxr = new LL(new StringSource(src));

            Assert.AreEqual("str\u8978ring", lxr.ElementAt(2).Text);
        }
Exemple #9
0
        public void ePrematureEOF_Thrown()
        {
            var src = @"";

            var lxr = new LL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemple #10
0
        public void String_Escapes4_Unicode()
        {
            var src = @"{'str\u8978ring'}";

            var lxr = new LL(new StringSource(src));

            Aver.AreEqual("str\u8978ring", lxr.ElementAt(2).Text);
        }
Exemple #11
0
        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) );
        }
Exemple #12
0
        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));
        }
Exemple #13
0
        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));
        }
Exemple #14
0
        public void eUnterminatedString4_Verbatim()
        {
            var src = @"a: $'aa
          
          aa";

            var lxr = new LL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemple #15
0
        public void eUnterminatedComment1()
        {
            var src = @"a: /*aa
          
          aa";

            var lxr = new LL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemple #16
0
        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);
        }
Exemple #17
0
        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);
        }
Exemple #18
0
        public void Comments4()
        {
            var src = @"{
           //comment text
          }
          ";

            var lxr = new LL(new StringSource(src));

            Assert.AreEqual("comment text", lxr.ElementAt(2).Text);
        }
Exemple #19
0
        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);
        }
Exemple #20
0
        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));
        }
Exemple #21
0
        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);
        }
Exemple #22
0
        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));
        }
Exemple #23
0
        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));
        }
Exemple #24
0
        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);
        }
Exemple #25
0
        public void Comments12withStrings()
        {
            //string is opened but line break
            var src = @"{       
          '|* /* //comment text " + "\n\r" + @" */ *|'
          }
          ";

            var lxr = new LL(new StringSource(src));

            lxr.AnalyzeAll();
        }
Exemple #26
0
        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));
        }
Exemple #27
0
        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);
        }
Exemple #28
0
        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);
        }
Exemple #29
0
        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);
        }
Exemple #30
0
        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);
        }
Exemple #31
0
        public void Comments12withStrings()
        {
          //string is opened but line break
          var src = @"{       
          '|* /* //comment text "+"\n\r"+@" */ *|'
          }
          ";

          var lxr = new LL(new StringSource(src));

          lxr.AnalyzeAll();
        }
Exemple #32
0
        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) );
        }
Exemple #33
0
        public void eUnterminatedComment1()
        {
          var src = @"a: /*aa
          
          aa";

          var lxr = new LL(new StringSource(src));
          lxr.AnalyzeAll();
        }
Exemple #34
0
        public void eUnterminatedString4_Verbatim()
        {
          var src = @"a: $'aa
          
          aa";

          var lxr = new LL(new StringSource(src));
          lxr.AnalyzeAll();
        }
Exemple #35
0
 public LaconfigToken(LaconfigLexer lexer, LaconfigTokenType type, SourcePosition startPos, SourcePosition endPos, string text, object value = null) :
     base(lexer, startPos, endPos, text, value)
 {
     Type = type;
 }
Exemple #36
0
        public void String_Escapes2_2()
        {
          var src = @"a{ n = 'string\''}";
                                               
          var lxr = new LL(new StringSource(src));

          Assert.AreEqual(@"string'", lxr.ElementAt(5).Text);
        }
Exemple #37
0
        public void String_Escapes1()
        {
          var src = @"{""str\""ing""}";
                                              
          var lxr = new LL(new StringSource(src));

          Assert.AreEqual(@"str""ing", lxr.ElementAt(2).Text);
        }
Exemple #38
0
        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);
        }
Exemple #39
0
        public void String_Escapes5_Unicode()
        {
          var src = @"{""str\u8978ring""}";
                                               
          var lxr = new LL(new StringSource(src));

          Assert.AreEqual("str\u8978ring", lxr.ElementAt(2).Text);
        }
Exemple #40
0
        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);

        }
Exemple #41
0
        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);
        }
Exemple #42
0
        public void eUnterminatedString2()
        {
          var src = @"a: ""aaaa";

          var lxr = new LL(new StringSource(src));
          lxr.AnalyzeAll();
        }
Exemple #43
0
        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) );
        }
Exemple #44
0
        public void Comments4()
        {
          var src = @"{
           //comment text
          }
          ";

          var lxr = new LL(new StringSource(src));

          Assert.AreEqual("comment text", lxr.ElementAt(2).Text);
        }