Example #1
0
        public UstNode VisitPatternLiterals([NotNull] DslParser.PatternLiteralsContext context)
        {
            Expression    result;
            PatternVarDef patternVarDef;

            if (context.patternNotLiteral().Length == 1)
            {
                result = (Expression)VisitPatternNotLiteral(context.patternNotLiteral().First());
                if (context.PatternVar() != null)
                {
                    string id = context.PatternVar().GetText().Substring(1);
                    if (!patternVarDefs.TryGetValue(id, out patternVarDef))
                    {
                        patternVarDef      = new PatternVarDef(id, new Expression[] { result }, context.GetTextSpan());
                        patternVarDefs[id] = patternVarDef;
                    }
                    else
                    {
                        if (context.patternNotLiteral().Length != 0)
                        {
                            var lcTextSpan = new LineColumnTextSpan(patternVarDef.TextSpan, Data);
                            throw new ConversionException(
                                      $"DSL Error: PatternVar {id} with matching Id already defined earlier at {lcTextSpan}")
                                  {
                                      TextSpan = context.PatternVar().GetTextSpan()
                                  };
                        }
                    }
                    result = new PatternVarRef(patternVarDef, context.GetTextSpan());
                }
            }
            else
            {
                List <Expression> values = context.patternNotLiteral()
                                           .Select(literal => (Expression)VisitPatternNotLiteral(literal)).ToList();
                if (values.Count == 0)
                {
                    values.Add(new PatternIdToken("", context.GetTextSpan()));
                }

                if (context.PatternVar() == null)
                {
                    result = new PatternVarDef(GetNewVarDefName(), values, context.GetTextSpan());
                }
                else
                {
                    string id = context.PatternVar().GetText().Substring(1);
                    if (!patternVarDefs.TryGetValue(id, out patternVarDef))
                    {
                        patternVarDef      = new PatternVarDef(id, values, context.GetTextSpan());
                        patternVarDefs[id] = patternVarDef;
                    }
                    else
                    {
                        if (context.patternNotLiteral().Length != 0)
                        {
                            var lcTextSpan = new LineColumnTextSpan(patternVarDef.TextSpan, Data);
                            throw new ConversionException(
                                      $"DSL Error: PatternVar {id} with matching Id already defined earlier at {lcTextSpan}")
                                  {
                                      TextSpan = context.PatternVar().GetTextSpan()
                                  };
                        }
                    }
                    result = new PatternVarRef(patternVarDef, context.GetTextSpan());
                }
            }
            return(result);
        }
Example #2
0
 public virtual void Exit(PatternVarRef patternVarRef)
 {
 }
Example #3
0
 public virtual UstNode Visit(PatternVarRef patternVarRef)
 {
     return(VisitChildren(patternVarRef));
 }
Example #4
0
 public virtual void Enter(PatternVarRef patternVarRef)
 {
 }