public override Expr VisitRegExLitExpr([NotNull] JPathParser.RegExLitExprContext context) { try { var regex = new Regex(context.Value.Text.Trim('/', '!')); return(new RegexLit(regex)); } catch (ArgumentException e) { throw AstError(context.Value, $"Value '{context.Value}' is not a valid regex: {e.Message}"); } }
public override Expr VisitRegExLitExpr([NotNull] JPathParser.RegExLitExprContext context) { try { var regexStr = context.Value.Text.StartsWith("/") ? context.Value.Text.Trim('/') : context.Value.Text.StartsWith("!") ? context.Value.Text.Trim('!') : context.Value.Text; return(new RegexLit(new Regex(regexStr))); } catch (ArgumentException e) { throw AstError(context.Value, $"Value '{context.Value.Text}' is not a valid regex: {e.Message}"); } }
/// <summary> /// Visit a parse tree produced by the <c>RegExLitExpr</c> /// labeled alternative in <see cref="JPathParser.literal"/>. /// <para> /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/> /// on <paramref name="context"/>. /// </para> /// </summary> /// <param name="context">The parse tree.</param> /// <return>The visitor result.</return> public virtual Result VisitRegExLitExpr([NotNull] JPathParser.RegExLitExprContext context) { return(VisitChildren(context)); }
/// <summary> /// Exit a parse tree produced by the <c>RegExLitExpr</c> /// labeled alternative in <see cref="JPathParser.literal"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitRegExLitExpr([NotNull] JPathParser.RegExLitExprContext context) { }