示例#1
0
        public override EpsilonNfa Apply(MatchExpression expression, Automaton param)
        {
            int captureIndex = -1;

            if (expression.Name.Length != 0)
            {
                var names = param.CaptureNames;
                captureIndex = names.IndexOf(expression.Name);
                if (captureIndex == -1)
                {
                    captureIndex = names.Count;
                    names.Add(expression.Name);
                }
            }

            var res = new EpsilonNfa(param);

            param.AddMatch(res.Start, res.End, captureIndex, expression.Index);
            return(res);
        }
示例#2
0
        public static RegexNode GetMatch(int index)
        {
            var expression = new MatchExpression(index);

            return(new RegexNode(expression));
        }
示例#3
0
 public override Expression Apply(MatchExpression expression, MergeParameter param)
 {
     return(new MatchExpression(expression));
 }
示例#4
0
 public MatchExpression(MatchExpression expression)
 {
     Name  = expression.Name;
     Index = expression.Index;
 }
示例#5
0
 Expression ParseFunction()
 {
     if (_sourceWindow.AdvanceIfMatches("(="))
     {
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new PositiveExpression(sub);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(!"))
     {
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new NegativeExpression(sub);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(<&"))
     {
         //表达式引用
         string name;
         if (!_sourceWindow.AdvanceIfName(out name))
         {
             throw new ArgumentException("invalid name.");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost.");
         }
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost.");
         }
         var exp = new ReferenceExpression(name);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(<$"))
     {
         string name;
         int    index = -1;
         if (_sourceWindow.AdvanceIfName(out name))
         {
             if (_sourceWindow.AdvanceIfMatches(';'))
             {
                 if (!_sourceWindow.AdvanceIfPositiveInteger(out index))
                 {
                     throw new ArgumentException("Positive numbers required after ;");
                 }
             }
         }
         else if (!_sourceWindow.AdvanceIfPositiveInteger(out index))
         {
             throw new ArgumentException("Positive numbers required after (<$");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost.");
         }
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost.");
         }
         var exp = new MatchExpression(name, index);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(<"))
     {
         string name;
         if (!_sourceWindow.AdvanceIfName(out name))
         {
             throw new ArgumentException("Name lost");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost");
         }
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new CaptureExpression(name, sub);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches("(?"))
     {
         var sub = ParseExpression();
         if (_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new CaptureExpression(sub);
         return(exp);
     }
     else if (_sourceWindow.AdvanceIfMatches('('))//subexpression
     {
         var exp = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         return(exp);
     }
     else
     {
         return(null);
     }
 }
 public void Visit(MatchExpression expression)
 {
     _returnValue = this.Apply(expression, _paramValue);
 }
 public abstract ReturnT Apply(MatchExpression expression, ParamT param);
示例#8
0
 Expression ParseFunction()
 {
     if (_sourceWindow.AdvanceIfMatches("(="))
     {
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new PositiveExpression(sub);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(!"))
     {
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new NegativeExpression(sub);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(<&"))
     {
         //表达式引用
         string name;
         if (!_sourceWindow.AdvanceIfName(out name))
         {
             throw new ArgumentException("invalid name.");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost.");
         }
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost.");
         }
         var exp = new ReferenceExpression(name);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(<$"))
     {
         string name;
         int index = -1;
         if (_sourceWindow.AdvanceIfName(out name))
         {
             if (_sourceWindow.AdvanceIfMatches(';'))
             {
                 if (!_sourceWindow.AdvanceIfPositiveInteger(out index))
                 {
                     throw new ArgumentException("Positive numbers required after ;");
                 }
             }
         }
         else if (!_sourceWindow.AdvanceIfPositiveInteger(out index))
         {
             throw new ArgumentException("Positive numbers required after (<$");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost.");
         }
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost.");
         }
         var exp = new MatchExpression(name, index);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(<"))
     {
         string name;
         if (!_sourceWindow.AdvanceIfName(out name))
         {
             throw new ArgumentException("Name lost");
         }
         if (!_sourceWindow.AdvanceIfMatches('>'))
         {
             throw new ArgumentException("> lost");
         }
         var sub = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new CaptureExpression(name, sub);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches("(?"))
     {
         var sub = ParseExpression();
         if (_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         var exp = new CaptureExpression(sub);
         return exp;
     }
     else if (_sourceWindow.AdvanceIfMatches('('))//subexpression
     {
         var exp = ParseExpression();
         if (!_sourceWindow.AdvanceIfMatches(')'))
         {
             throw new ArgumentException(") lost");
         }
         return exp;
     }
     else return null;
 }
示例#9
0
 public static RegexNode GetMatch(int index)
 {
     var expression = new MatchExpression(index);
     return new RegexNode(expression);
 }
示例#10
0
 public MatchExpression(MatchExpression expression)
 {
     Name = expression.Name;
     Index = expression.Index;
 }