상속: Irony.Parsing.DataLiteralBase
예제 #1
0
        public NTermName()
        {
            this.GrammarComments = @"Test Seq grammar";
            //Terminals
            var term1 = new DsvLiteral("<", TypeCode.String);

            var MyNonTerm = new NonTerminal("MyNonTerm");

            //Rules
            MyNonTerm.Rule = term1;
            this.Root = MyNonTerm;
            this.LanguageFlags |= LanguageFlags.NewLineBeforeEOF;            

        }//constructor
예제 #2
0
        public GSeq()
        {
            this.GrammarComments = @"Test Seq grammar";
            //Terminals
            var term1 = new DsvLiteral("MULT", TypeCode.String);
            var term2 = new DsvLiteral("PLUS", TypeCode.String);

            var s = new NonTerminal("S");

            //Rules
            s.Rule = term1 + term2;
            this.Root = s;
            this.LanguageFlags |= LanguageFlags.NewLineBeforeEOF;

        }//constructor
        public void TestDataLiterals()
        {
            Parser parser; Token token;
            Terminal term;

            // FixedLengthLiteral ---------------------------------------------------------
            term = new FixedLengthLiteral("fixedLengthInteger", 2, TypeCode.Int32);
            parser = TestHelper.CreateParser(term, null);

            token = parser.ParseInput("1200");
            Assert.True(token.Value != null, "Failed to parse fixed-length integer.");
            Assert.True((int)token.Value == 12, "Failed to parse fixed-length integer - result value does not match.");

            term = new FixedLengthLiteral("fixedLengthString", 2, TypeCode.String);
            parser = TestHelper.CreateParser(term);
            token = parser.ParseInput("abcd", useTerminator: false);
            Assert.True(token != null && token.Value != null, "Failed to parse fixed-length string.");
            Assert.True((string)token.Value == "ab", "Failed to parse fixed-length string - result value does not match");

            // DsvLiteral ----------------------------------------------------------------
            term = new DsvLiteral("DsvInteger", TypeCode.Int32, ",");
            parser = TestHelper.CreateParser(term);
            token = parser.ParseInput("12,");
            Assert.True(token != null && token.Value != null, "Failed to parse CSV integer.");
            Assert.True((int)token.Value == 12, "Failed to parse CSV integer - result value does not match.");

            term = new DsvLiteral("DsvInteger", TypeCode.String, ",");
            parser = TestHelper.CreateParser(term);
            token = parser.ParseInput("ab,");
            Assert.True(token != null && token.Value != null, "Failed to parse CSV string.");
            Assert.True((string)token.Value == "ab", "Failed to parse CSV string - result value does not match.");

            // QuotedValueLiteral ----------------------------------------------------------------
            term = new QuotedValueLiteral("QVDate", "#", TypeCode.DateTime);
            parser = TestHelper.CreateParser(term);
            token = parser.ParseInput("#11/15/2009#");
            Assert.True(token != null && token.Value != null, "Failed to parse quoted date.");
            Assert.True((DateTime)token.Value == new DateTime(2009, 11, 15), "Failed to parse quoted date - result value does not match.");

        }//method
    public void TestDataLiterals() {
      Terminal term;

      // FixedLengthLiteral ---------------------------------------------------------
      term = new FixedLengthLiteral("fixedLengthInteger", 2, TypeCode.Int32);
      SetTerminal(term);
      
      TryMatch("1200");
      Assert.IsTrue(_token != null && _token.Value != null, "Failed to parse fixed-length integer.");
      Assert.IsTrue((int)_token.Value == 12, "Failed to parse fixed-length integer - result value does not match.");

      term = new FixedLengthLiteral("fixedLengthString", 2, TypeCode.String);
      SetTerminal(term);
      TryMatch("abcd");
      Assert.IsTrue(_token != null && _token.Value != null, "Failed to parse fixed-length string.");
      Assert.IsTrue((string)_token.Value == "ab", "Failed to parse fixed-length string - result value does not match");

      // DsvLiteral ----------------------------------------------------------------
      term = new DsvLiteral("DsvInteger", TypeCode.Int32, ",");
      SetTerminal(term);
      TryMatch("12,");
      Assert.IsTrue(_token != null && _token.Value != null, "Failed to parse CSV integer.");
      Assert.IsTrue((int)_token.Value == 12, "Failed to parse CSV integer - result value does not match.");

      term = new DsvLiteral("DsvInteger", TypeCode.String, ",");
      SetTerminal(term);
      TryMatch("ab,");
      Assert.IsTrue(_token != null && _token.Value != null, "Failed to parse CSV string.");
      Assert.IsTrue((string)_token.Value == "ab", "Failed to parse CSV string - result value does not match.");
    
      // QuotedValueLiteral ----------------------------------------------------------------
      term = new QuotedValueLiteral ("QVDate", "#", TypeCode.DateTime);
      SetTerminal(term);
      TryMatch("#11/15/2009#");
      Assert.IsTrue(_token != null && _token.Value != null, "Failed to parse quoted date.");
      Assert.IsTrue((DateTime)_token.Value == new DateTime(2009, 11, 15), "Failed to parse quoted date - result value does not match.");

    }//method
예제 #5
0
    public SampleCsvGrammar() {
      this.GrammarComments = 
@"A sample grammar for reading comma-separated file containing cars information
Demonstrates use of DsvLiteral. Use sample data file DataFiles\CarModels.csv.";
      //Terminals
      var year = new DsvLiteral("Year", TypeCode.Int16);  // comma is default separator
      var maker = new DsvLiteral("Maker", TypeCode.String);
      var model = new DsvLiteral("Model", TypeCode.String);
      var comment = new DsvLiteral("Comment", TypeCode.String);
      var price = new DsvLiteral("Price", TypeCode.Double, null);  //null means no terminator, look for NewLine 

      var line = new NonTerminal("Line");
      var lines = new NonTerminal("Lines"); 
      var data = new NonTerminal("data"); 

      //Rules
      line.Rule = year + maker + model + comment + price + NewLine; //we don't specify comma between fields, because our terminals consume separator automatically
      lines.Rule = MakeStarRule(lines, line); 
      data.Rule = lines + NewLineStar; //to allow empty lines after
      this.Root =  data; 
      this.LanguageFlags |= LanguageFlags.NewLineBeforeEOF; 

    }//constructor