public override EpsilonNfa Apply(CaptureExpression expression, Automaton param) { var nfa = new EpsilonNfa(param); int captureIndex = 0; 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 body = Invoke(expression.Sub, param); param.AddCapture(nfa.Start, body.Start, captureIndex); param.AddTransition(body.End, nfa.End, Transition.Type.End); return(nfa); }
public static RegexNode GetCapture(string name, RegexNode node) { var expression = new CaptureExpression(name, node.Exp); return(new RegexNode(expression)); }
public override Expression Apply(CaptureExpression expression, MergeParameter param) { return(new CaptureExpression( expression.Name, Invoke(expression.Sub, param))); }
public bool Equals(CaptureExpression obj) { return (Name == obj.Name && Sub.Equals(obj.Sub)); }
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(CaptureExpression expression) { _returnValue = this.Apply(expression, _paramValue); }
public abstract ReturnT Apply(CaptureExpression expression, ParamT param);
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 static RegexNode GetCapture(string name,RegexNode node) { var expression = new CaptureExpression(name, node.Exp); return new RegexNode(expression); }
public bool Equals(CaptureExpression obj) { return Name == obj.Name && Sub.Equals(obj.Sub); }