Exemplo n.º 1
0
 public HereDocTestGrammar()
     : base(true) {
     var heredoc = new HereDocTerminal("HereDoc", "<<", HereDocOptions.None);
     heredoc.AddSubType("<<-", HereDocOptions.AllowIndentedEndToken);
     var @string = new StringLiteral("string", "\"");
     var program = new NonTerminal("program");
     program.Rule = heredoc + @"+" + @string + this.NewLine + @"+" + @string
         | heredoc + @"+" + heredoc + @"+" + @string + this.NewLine
         | heredoc + @"+" + @string + this.NewLine
         | heredoc + @"+" + @string + @"+" + heredoc
         | heredoc + @"+" + heredoc
         | heredoc;
     this.Root = program;
     this.MarkPunctuation("+");
 }
Exemplo n.º 2
0
        public void TestHereDocQuotedButUnused()
        {
            var quotes = new HashSet <string> {
                "'", "\""
            };
            var term = new HereDocTerminal("Heredoc", "<<-", HereDocOptions.RemoveBeginningNewLine);

            term.AddSubType("<<-", quotes, HereDocOptions.None);
            var parser = TestHelper.CreateParser(term);
            var token  = parser.ParseInput(@"<<-BEGIN
test
BEGIN");

            Assert.IsNotNull(token, "Failed to produce a token on valid string.");
            Assert.IsNotNull(token.Value, "Token Value field is null - should be string.");
            Assert.IsTrue((string)token.Value == "test", "Token Value is wrong, got {0} of type {1}", token.Value, token.Value.GetType());
        }
Exemplo n.º 3
0
        public void TestHereDocUndentedNotAllowedError()
        {
            var quotes = new HashSet <string> {
                "'", "\""
            };
            var term = new HereDocTerminal("Heredoc", "<<-", HereDocOptions.RemoveBeginningNewLine | HereDocOptions.RemoveIndents);

            term.AddSubType("<<-", quotes, HereDocOptions.None);
            var parser = TestHelper.CreateParser(term);
            var token  = parser.ParseInput(@"<<-BEGIN
test1
    test2
      test3
    BEGIN");

            Assert.IsNotNull(token, "Failed to produce a token on valid string.");
            Assert.IsTrue(token.IsError, "Failed to detect error on invalid heredoc.");
        }
Exemplo n.º 4
0
            public HereDocTestGrammar()
                : base(true)
            {
                var heredoc = new HereDocTerminal("HereDoc", "<<", HereDocOptions.None);

                heredoc.AddSubType("<<-", HereDocOptions.AllowIndentedEndToken);
                var @string = new StringLiteral("string", "\"");
                var program = new NonTerminal("program");

                program.Rule = heredoc + @"+" + @string + this.NewLine + @"+" + @string
                               | heredoc + @"+" + heredoc + @"+" + @string + this.NewLine
                               | heredoc + @"+" + @string + this.NewLine
                               | heredoc + @"+" + @string + @"+" + heredoc
                               | heredoc + @"+" + heredoc
                               | heredoc;
                this.Root = program;
                this.MarkPunctuation("+");
            }
Exemplo n.º 5
0
        public void TestHereDocUndented()
        {
            var quotes = new HashSet <string> {
                "'", "\""
            };
            var term = new HereDocTerminal("Heredoc", "<<-", HereDocOptions.RemoveBeginningNewLine | HereDocOptions.RemoveIndents | HereDocOptions.AllowIndentedEndToken);

            term.AddSubType("<<-", quotes, HereDocOptions.None);
            var parser = TestHelper.CreateParser(term);
            var token  = parser.ParseInput(@"<<-BEGIN
        test0
test1
    test2
      test3
    BEGIN");

            Assert.IsNotNull(token, "Failed to produce a token on valid string.");
            Assert.IsNotNull(token.Value, "Token Value field is null - should be string.");
            var nl = Environment.NewLine;

            Assert.IsTrue((string)token.Value == $"    test0{nl}test1{nl}test2{nl}  test3", "Token Value is wrong, got {0} of type {1}", token.Value, token.Value.GetType());
        }