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

          var lxr = new LL(new StringSource(src));
          lxr.AnalyzeAll();
        }
예제 #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);
        }
예제 #4
0
        public void eUnterminatedString2()
        {
            var src = @"a: ""aaaa";

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

            lxr.AnalyzeAll();
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #9
0
        public void ePrematureEOF_Thrown()
        {
            var src = @"";

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

            lxr.AnalyzeAll();
        }
예제 #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);
        }
예제 #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) );
        }
예제 #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));
        }
예제 #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));
        }
예제 #14
0
        public void eUnterminatedString4_Verbatim()
        {
            var src = @"a: $'aa
          
          aa";

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

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

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

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

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

            Assert.AreEqual("comment text", lxr.ElementAt(2).Text);
        }
예제 #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);
        }
예제 #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));
        }
예제 #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);
        }
예제 #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));
        }
예제 #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));
        }
예제 #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);
        }
예제 #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();
        }
예제 #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));
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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();
        }
예제 #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) );
        }
예제 #33
0
        public void eUnterminatedComment1()
        {
          var src = @"a: /*aa
          
          aa";

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

          var lxr = new LL(new StringSource(src));
          lxr.AnalyzeAll();
        }
예제 #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;
 }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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);

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

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

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

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