public PatternUst VisitPatternLiterals([NotNull] DslParser.PatternLiteralsContext context) { IEnumerable <PatternUst> values = context.patternNotLiteral() .Select(literal => VisitPatternNotLiteral(literal)); var patternOr = values.Count() > 1 ? new PatternOr(values) : values.Count() == 1 ? values.First() : new PatternIdRegexToken(); PatternUst result; if (context.PatternVar() != null) { string id = context.PatternVar().GetText().Substring(1); if (values.Count() > 0 && patternVars.TryGetValue(id, out PatternVar existedPatternVar)) { LineColumnTextSpan lcTextSpan = Data.GetLineColumnTextSpan(existedPatternVar.TextSpan); throw new ConversionException( Data, message: $"DSL Error: PatternVar {id} with the same Id already defined earlier at {lcTextSpan}") { TextSpan = context.PatternVar().GetTextSpan() }; } var patternVar = new PatternVar(id, context.GetTextSpan()); patternVars[id] = patternVar; patternVar.Value = patternOr; result = patternVar; } else { result = patternOr; } return(result); }
public virtual T Visit(PatternVar patternVar) { return(VisitChildren(patternVar)); }