コード例 #1
0
 public override Expression Apply(ReferenceExpression expression, MergeParameter keysHasCollected)
 {
     if (keysHasCollected.Definitions.ContainsKey(expression.Name))
     {
         var ret = keysHasCollected.Definitions[expression.Name];
         if (ret != null)
         {
             return(ret);
         }
         else
         {
             throw new ArgumentException("loop reference");
         }
     }
     else if (keysHasCollected.Main.Definitions.ContainsKey(expression.Name))
     {
         keysHasCollected.Definitions.Add(expression.Name, null);
         var ret = Invoke(keysHasCollected.Main.Definitions[expression.Name], keysHasCollected);
         keysHasCollected.Definitions[expression.Name] = ret;
         return(ret);
     }
     else
     {
         throw new ArgumentException($"Cannot find the referenced expression {expression.Name}.");
     }
 }
コード例 #2
0
 public override EpsilonNfa Apply(ReferenceExpression expression, Automaton param)
 {
     throw new NotImplementedException();
 }
コード例 #3
0
        public static RegexNode GetReference(string name)
        {
            var expression = new ReferenceExpression(name);

            return(new RegexNode(expression));
        }
コード例 #4
0
ファイル: Parser.cs プロジェクト: LYP951018/FunnyThings
 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);
     }
 }
コード例 #5
0
 public void Visit(ReferenceExpression expression)
 {
     _returnValue = this.Apply(expression, _paramValue);
 }
コード例 #6
0
 public abstract ReturnT Apply(ReferenceExpression expression, ParamT param);
コード例 #7
0
ファイル: Parser.cs プロジェクト: LYP951018/FunnyThings
 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;
 }
コード例 #8
0
ファイル: RegexNode.cs プロジェクト: LYP951018/FunnyThings
 public static RegexNode GetReference(string name)
 {
     var expression = new ReferenceExpression(name);
     return new RegexNode(expression);
 }