public override object VisitUndefined(CdeltaParser.UndefinedContext context)
        {
            object parentStructure = contextWithStructure[context.Parent];
            int    startIndex      = context.Start.StartIndex;

            if (context.children == null)
            {
                return(base.VisitUndefined(context));
            }

            int length = context.Stop.StopIndex - startIndex;

            string undefinedText = input.Substring(startIndex, length + 1);

            if (parentStructure is CodeFile)
            {
                if (context.Parent is CdeltaParser.PreAutomatonCodeContext)
                {
                    ((CodeFile)parentStructure).PreAutomatonCode = undefinedText;
                }
                else if (context.Parent is CdeltaParser.PostAutomatonCodeContext)
                {
                    ((CodeFile)parentStructure).PostAutomatonCode = undefinedText;
                }
                else
                {
                    throw new InvalidOperationException(String.Format("Unknown context for CSharp code. Expected {0} or {1}.",
                                                                      typeof(CdeltaParser.PreAutomatonCodeContext).Name,
                                                                      typeof(CdeltaParser.PostAutomatonCodeContext).Name));
                }
            }
            else if (parentStructure is State)
            {
                if (context.Parent is CdeltaParser.StateEntryContext)
                {
                    ((State)parentStructure).EntryCode = undefinedText;
                }
                else if (context.Parent is CdeltaParser.StateExitContext)
                {
                    ((State)parentStructure).ExitCode = undefinedText;
                }
                else
                {
                    throw new InvalidOperationException(String.Format("Unknown context for CSharp code. Expected {0} or {1}.",
                                                                      typeof(CdeltaParser.StateEntryContext).Name,
                                                                      typeof(CdeltaParser.StateExitContext).Name));
                }
            }
            else if (parentStructure is Transition)
            {
                if (context.Parent is CdeltaParser.TransitionDefinitionContext ||
                    context.Parent is CdeltaParser.TransitionConditionContext)
                {
                    ((Transition)parentStructure).ConditionCode = undefinedText;
                }
                else if (context.Parent is CdeltaParser.TransitionEntryContext)
                {
                    ((Transition)parentStructure).EntryCode = undefinedText;
                }
                else
                {
                    throw new InvalidOperationException(String.Format("Unknown context for CSharp code. Expected {0}, {1} or {2}.",
                                                                      typeof(CdeltaParser.TransitionDefinitionContext).Name,
                                                                      typeof(CdeltaParser.TransitionConditionContext).Name,
                                                                      typeof(CdeltaParser.TransitionEntryContext).Name));
                }
            }

            contextWithStructure.Add(context, parentStructure);

            return(base.VisitUndefined(context));
        }
Example #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="CdeltaParser.undefined"/>.
 /// <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 VisitUndefined([NotNull] CdeltaParser.UndefinedContext context)
 {
     return(VisitChildren(context));
 }
 /// <summary>
 /// Exit a parse tree produced by <see cref="CdeltaParser.undefined"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitUndefined([NotNull] CdeltaParser.UndefinedContext context)
 {
 }