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); }
public static RegexNode GetMatch(int index) { var expression = new MatchExpression(index); return(new RegexNode(expression)); }
public override Expression Apply(MatchExpression expression, MergeParameter param) { return(new MatchExpression(expression)); }
public MatchExpression(MatchExpression expression) { Name = expression.Name; Index = expression.Index; }
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);
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 GetMatch(int index) { var expression = new MatchExpression(index); return new RegexNode(expression); }