Exemplo n.º 1
0
    public void TestRegExLiteral() {
      Parser parser; Token token;

      var term = new RegexLiteral("RegEx");
      parser = TestHelper.CreateParser(term);
      token = parser.ParseInput(@"/abc\\\/de/gm  ");
      Assert.IsNotNull(token, "Failed to produce a token on valid string.");
      Assert.AreEqual(term, token.Terminal, "Failed to scan a string - invalid Terminal in the returned token.");
      Assert.IsNotNull(token.Value, "Token Value field is null - should be Regex object.");
      var regex = token.Value as Regex;
      Assert.IsNotNull(regex, "Failed to create Regex object.");
      var match = regex.Match(@"00abc\/de00"); 
      Assert.AreEqual(match.Index, 2, "Failed to match a regular expression");
    }
Exemplo n.º 2
0
        public void TestRegExLiteral()
        {
            var term   = new RegexLiteral("RegEx");
            var parser = TestHelper.CreateParser(term);
            var token  = parser.ParseInput(@"/abc\\\/de/gm  ");

            Assert.IsNotNull(token, "Failed to produce a token on valid string.");
            Assert.AreEqual(term, token.Terminal, "Failed to scan a string - invalid Terminal in the returned token.");
            Assert.IsNotNull(token.Value, "Token Value field is null - should be Regex object.");
            var regex = token.Value as Regex;

            Assert.IsNotNull(regex, "Failed to create Regex object.");
            var match = regex.Match(@"00abc\/de00");

            Assert.AreEqual(match.Index, 2, "Failed to match a regular expression");
        }
Exemplo n.º 3
0
        /// <summary>
        /// 使うな
        /// </summary>
        public Kbtter3QueryGrammar()
            : base()
        {
            //コメント
            var comment = new CommentTerminal("Comment", "/*", "*/");
            NonGrammarTerminals.Add(comment);

            //リテラル
            var number = new NumberLiteral("Number", NumberOptions.AllowSign | NumberOptions.AllowStartEndDot);
            var str = new StringLiteral("String", "\"");
            var regex = new RegexLiteral("Regex", '/', '\\');
            var ident = new IdentifierTerminal("Identifer");

            //非終端
            var Value = new NonTerminal("Value");
            var Term = new NonTerminal("Term");
            var Expression = new NonTerminal("Expression");
            var BinExpression = new NonTerminal("BinExpression");
            var ParExpression = new NonTerminal("ParExpression");
            var PostfixExpression = new NonTerminal("PostfixExpression");
            var Operator = new NonTerminal("Operator");

            //非終端定義
            Value.Rule = number | str | ident | regex | "null" | "true" | "false";
            Term.Rule = Value | ParExpression;
            Operator.Rule = ToTerm("==") | "!=" | ">" | "<" | ">=" | "<=" | "match" | "&&" | "||" | "+" | "-" | "*" | "/" | "%" | "&" | "|" | "^" | ".";
            BinExpression.Rule = Expression + Operator + Expression;
            PostfixExpression.Rule = (ToTerm("+") + Term) | ("-" + Term) | ("!" + Term);
            Expression.Rule = BinExpression | Term | PostfixExpression;
            ParExpression.Rule = ToTerm("(") + Expression + ")";

            RegisterOperators(10, ".");
            RegisterOperators(9, "*", "/", "%");
            RegisterOperators(8, "+", "-");
            RegisterOperators(7, ">", "<", ">=", "<=", "match");
            RegisterOperators(6, "==", "!=");
            RegisterOperators(5, "&");
            RegisterOperators(4, "^");
            RegisterOperators(3, "|");
            RegisterOperators(2, "&&");
            RegisterOperators(1, "||");

            Root = Expression;
            MarkPunctuation("(", ")");
            MarkTransient(Expression, ParExpression, Value, Operator, Term);
        }
Exemplo n.º 4
0
        public Kbtter3QueryGrammar() : base(false)
        {
            //コメント
            var comment = new CommentTerminal("Comment", "/*", "*/");

            NonGrammarTerminals.Add(comment);

            //リテラル
            var number = new NumberLiteral("Number", NumberOptions.AllowSign | NumberOptions.AllowStartEndDot);
            var str    = new StringLiteral("String", "\"");
            var regex  = new RegexLiteral("Regex", '/', '\\');
            var ident  = new IdentifierTerminal("Identifer");

            //非終端
            var Value             = new NonTerminal("Value");
            var Term              = new NonTerminal("Term");
            var Expression        = new NonTerminal("Expression");
            var BinExpression     = new NonTerminal("BinExpression");
            var ParExpression     = new NonTerminal("ParExpression");
            var PostfixExpression = new NonTerminal("PostfixExpression");
            var Operator          = new NonTerminal("Operator");

            //非終端定義
            Value.Rule             = number | str | ident | regex | "null" | "true" | "false";
            Term.Rule              = Value | ParExpression;
            Operator.Rule          = ToTerm("==") | "!=" | ">" | "<" | ">=" | "<=" | "match" | "&&" | "||" | "+" | "-" | "*" | "/" | "%" | "&" | "|" | "^" | ".";
            BinExpression.Rule     = Expression + Operator + Expression;
            PostfixExpression.Rule = (ToTerm("+") + Term) | ("-" + Term) | ("!" + Term);
            Expression.Rule        = BinExpression | Term | PostfixExpression;
            ParExpression.Rule     = ToTerm("(") + Expression + ")";

            RegisterOperators(10, ".");
            RegisterOperators(9, "*", "/", "%");
            RegisterOperators(8, "+", "-");
            RegisterOperators(7, ">", "<", ">=", "<=", "match");
            RegisterOperators(6, "==", "!=");
            RegisterOperators(5, "&");
            RegisterOperators(4, "^");
            RegisterOperators(3, "|");
            RegisterOperators(2, "&&");
            RegisterOperators(1, "||");

            Root = Expression;
            MarkPunctuation("(", ")");
            MarkTransient(Expression, ParExpression, Value, Operator, Term);
        }
Exemplo n.º 5
0
        public void TestRegExLiteral()
        {
            Parser parser; Token token;

            var term = new RegexLiteral("RegEx");

            parser = TestHelper.CreateParser(term);
            token  = parser.ParseInput(@"/abc\\\/de/gm  ");
            Assert.False(token == null, "Failed to produce a token on valid string.");
            Assert.True(term == token.Terminal, "Failed to scan a string - invalid Terminal in the returned token.");
            Assert.False(token.Value == null, "Token Value field is null - should be Regex object.");
            var regex = token.Value as Regex;

            Assert.False(regex == null, "Failed to create Regex object.");
            var match = regex.Match(@"00abc\/de00");

            Assert.True(match.Index == 2, "Failed to match a regular expression");
        }
Exemplo n.º 6
0
 public static bool IsLiteral(char c) => RegexLiteral.IsMatch(c + "");
Exemplo n.º 7
0
 /// <summary>
 /// Visit operation called for regex literals.
 ///
 /// <param name="lit">a regex literal</param>
 /// </summary>
 public virtual void visit_regex_literal(RegexLiteral lit)
 {
 }