Example #1
0
 private string GetNamedPropertyBlockValueNameOrType(Antlr4.Runtime.ParserRuleContext context)
 {
     if (context.Start.Type == SBP.IDENTIFIER)
     {
         var stack      = m_expressionData.Peek();
         var identifier = stack.Pop();
         return((string)identifier.Value);
     }
     else if (context.Start.Type == SBP.STRING)
     {
         return(ParseStringLiteral(context.GetText(), context));
     }
     else
     {
         return(context.GetText());
     }
 }
Example #2
0
        /// <summary>
        /// Handles a .NET Exception that occurred during the interpretation of Synery code.
        /// </summary>
        /// <param name="exception">The thrown .NET Exception</param>
        /// <param name="context">The interpretation context that caused the Exception (e.g. used to print the line number).</param>
        /// <returns>
        /// false = Exception hasn't been handled, so please re-throw it.
        /// true = Exception handled. No further action is required. Continue interpretation.
        /// </returns>
        private bool HandleException(Exception exception, Antlr4.Runtime.ParserRuleContext context)
        {
            INestedScope nestedScope = Memory.Scopes.OfType <INestedScope>().FirstOrDefault();

            if (nestedScope != null && nestedScope.IsTerminated == true &&
                !(context is SyneryParser.ThrowStatementContext) &&
                !(exception is InterfaceBoosterException))
            {
                // The current block has already been terminated.
                // Therefore don't throw or create any new exceptions
                return(true);
            }
            else
            {
                if (context is SyneryParser.ObserveBlockContext)
                {
                    // We're now in an OBSERVE-block.
                    // Try to find a handle block that catches the exception.

                    ExecutionExceptionRecord executionException = new ExecutionExceptionRecord();
                    executionException.Message      = exception.Message;
                    executionException.Line         = context.Start.Line;
                    executionException.CharPosition = context.Start.Column;

                    this.HandleSyneryEvent(context, executionException.GetAsSyneryValue());

                    return(true);
                }
                if (exception is SyneryInterpretationException)
                {
                    // The exception already is an interpretation exception.
                    // Continue re-throwing it.
                    return(false);
                }

                /*
                 * It seems that the exception is not an interpretation exception.
                 * Create a new exception and enrich it with the parser-context and  a
                 * new message that contains all messages from the nested exceptions.
                 */

                string message = string.Format("An unexpected error occurred while interpreting '{1}' on line {2}: {0}{3}",
                                               Environment.NewLine,
                                               context.GetText(),
                                               context.Start.Line,
                                               ExceptionHelper.GetNestedExceptionMessages(exception));

                throw new SyneryInterpretationException(context, message, exception);
            }
        }
Example #3
0
        public override void EnterEveryRule([Antlr4.Runtime.Misc.NotNull] Antlr4.Runtime.ParserRuleContext context)
        {
            string s = context.GetText();

            System.Console.WriteLine(s);
        }