Ejemplo n.º 1
0
        public IASTNode HandleIdentifierError(IToken token, RecognitionException ex)
        {
            if (token is HqlToken)
            {
                HqlToken hqlToken = (HqlToken)token;

                // ... and the token could be an identifer and the error is
                // a mismatched token error ...
                if (hqlToken.PossibleId && (ex is MismatchedTokenException))
                {
                    MismatchedTokenException mte = (MismatchedTokenException)ex;

                    // ... and the expected token type was an identifier, then:
                    if (mte.Expecting == IDENT)
                    {
                        // Use the token as an identifier.
                        _parseErrorHandler.ReportWarning("Keyword  '"
                                                         + token.Text
                                                         + "' is being interpreted as an identifier due to: " + mte.Message);

                        // Add the token to the AST.

                        token.Type = WEIRD_IDENT;

                        input.Consume();
                        return((IASTNode)adaptor.Create(token));
                    }
                }
            }

            // Otherwise, handle the error normally.
            ReflectHelper.PreserveStackTrace(ex);
            throw ex;
        }
Ejemplo n.º 2
0
            public override object Create(IToken payload)
            {
                GrammarAST t = new GrammarAST(payload);

                if (_outer != null)
                {
                    t.enclosingRuleName = _outer.currentRuleName;
                }
                return(t);
            }
Ejemplo n.º 3
0
            public override object ErrorNode(ITokenStream input, IToken start, IToken stop, RecognitionException e)
            {
                GrammarAST t = new GrammarASTErrorNode(input, start, stop, e);

                if (_outer != null)
                {
                    t.enclosingRuleName = _outer.currentRuleName;
                }
                return(t);
            }
Ejemplo n.º 4
0
        public IASTNode ProcessMemberOf(IToken n, IASTNode p, IASTNode root)
        {
            ASTFactory factory = new ASTFactory(adaptor);

            return(factory.CreateNode(n == null ? IN : NOT_IN,
                                      n == null ? "in" : "not in",
                                      root.IsNil && root.ChildCount == 1 ? root.GetChild(0) : root,
                                      factory.CreateNode(IN_LIST, "inList",
                                                         CreateSubquery(p))));
        }
Ejemplo n.º 5
0
 public GrammarASTErrorNode(ITokenStream input, IToken start, IToken stop,
                            RecognitionException e)
 {
     //Console.Out.WriteLine( "start: " + start + ", stop: " + stop );
     if (stop == null ||
         (stop.TokenIndex < start.TokenIndex &&
          stop.Type != TokenTypes.EndOfFile))
     {
         // sometimes resync does not consume a token (when LT(1) is
         // in follow set.  So, stop will be 1 to left to start. adjust.
         // Also handle case where start is the first token and no token
         // is consumed during recovery; LT(-1) will return null.
         stop = start;
     }
     this.input            = input;
     this.start            = start;
     this.stop             = stop;
     this.trappedException = e;
 }
Ejemplo n.º 6
0
        public override void ReportError(RecognitionException ex)
        {
            //Token token = null;
            //try
            //{
            //    token = LT( 1 );
            //}
            //catch ( TokenStreamException tse )
            //{
            //    ErrorManager.internalError( "can't get token???", tse );
            //}
            IToken token = ex.Token;

            ErrorManager.SyntaxError(
                ErrorManager.MSG_SYNTAX_ERROR,
                Grammar,
                token,
                "antlr: " + ex.ToString(),
                ex);
        }
 public override Antlr4.StringTemplate.Compiler.CompiledTemplate Compile(string srcName, string name, List <Antlr4.StringTemplate.Compiler.FormalArgument> args, string template, Antlr.Runtime.IToken templateToken)
 {
     return(base.Compile(srcName, name, args, template, templateToken));
 }
Ejemplo n.º 8
0
 public override object ErrorNode( ITokenStream input, IToken start, IToken stop, RecognitionException e )
 {
     GrammarAST t = new GrammarASTErrorNode( input, start, stop, e );
     if ( _outer != null )
         t.enclosingRuleName = _outer.currentRuleName;
     return t;
 }
 public override void DefineTemplateOrRegion(string fullyQualifiedTemplateName, string regionSurroundingTemplateName, Antlr.Runtime.IToken templateToken, string template, Antlr.Runtime.IToken nameToken, List <Antlr4.StringTemplate.Compiler.FormalArgument> args)
 {
     base.DefineTemplateOrRegion(fullyQualifiedTemplateName, regionSurroundingTemplateName, templateToken, template, nameToken, args);
 }
Ejemplo n.º 10
0
 public GrammarASTErrorNode( ITokenStream input, IToken start, IToken stop,
                        RecognitionException e )
     : base(stop)
 {
     //Console.Out.WriteLine( "start: " + start + ", stop: " + stop );
     if ( stop == null ||
          ( stop.TokenIndex < start.TokenIndex &&
           stop.Type != TokenTypes.EndOfFile ) )
     {
         // sometimes resync does not consume a token (when LT(1) is
         // in follow set.  So, stop will be 1 to left to start. adjust.
         // Also handle case where start is the first token and no token
         // is consumed during recovery; LT(-1) will return null.
         stop = start;
     }
     this.input = input;
     this.start = start;
     this.stop = stop;
     this.trappedException = e;
 }
Ejemplo n.º 11
0
 public override object Create( IToken payload )
 {
     GrammarAST t = new GrammarAST( payload );
     if ( _outer != null )
         t.enclosingRuleName = _outer.currentRuleName;
     return t;
 }
 public override Antlr4.StringTemplate.Compiler.CompiledTemplate DefineTemplateAlias(Antlr.Runtime.IToken aliasT, Antlr.Runtime.IToken targetT)
 {
     return(base.DefineTemplateAlias(aliasT, targetT));
 }
Ejemplo n.º 13
0
 public GrammarToken(Grammar g, IToken oldToken)
 {
     this.g = g;
     _token = new CommonToken(oldToken);
 }
Ejemplo n.º 14
0
		public IASTNode HandleIdentifierError(IToken token, RecognitionException ex)
		{
			if (token is HqlToken)
			{
				HqlToken hqlToken = (HqlToken)token;

				// ... and the token could be an identifer and the error is
				// a mismatched token error ...
				if (hqlToken.PossibleId && (ex is MismatchedTokenException))
				{
					MismatchedTokenException mte = (MismatchedTokenException)ex;

					// ... and the expected token type was an identifier, then:
					if (mte.Expecting == IDENT)
					{
						// Use the token as an identifier.
						_parseErrorHandler.ReportWarning("Keyword  '"
								+ token.Text
								+ "' is being interpreted as an identifier due to: " + mte.Message);

						// Add the token to the AST.

						token.Type = WEIRD_IDENT;

						input.Consume();
						return (IASTNode) adaptor.Create(token);
					}
				} 
			}
			
			// Otherwise, handle the error normally.
			throw ex;
		}
Ejemplo n.º 15
0
 public GrammarToken(Grammar g, IToken oldToken)
 {
     this.g = g;
     _token = new CommonToken(oldToken);
 }
 public override void SetDelimiters(Antlr.Runtime.IToken openDelimiter, Antlr.Runtime.IToken closeDelimiter)
 {
     base.SetDelimiters(openDelimiter, closeDelimiter);
 }
 public override void RawDefineTemplate(string name, Antlr4.StringTemplate.Compiler.CompiledTemplate code, Antlr.Runtime.IToken defT)
 {
     base.RawDefineTemplate(name, code, defT);
 }
 public override void ImportTemplates(Antlr.Runtime.IToken fileNameToken)
 {
     base.ImportTemplates(fileNameToken);
 }
Ejemplo n.º 19
0
 private void HandleDelegateGrammar(IToken grammarName, string label)
 {
     Grammar.ImportGrammar(grammarName, label);
 }
 public override Template CreateSingleton(Antlr.Runtime.IToken templateToken)
 {
     return(base.CreateSingleton(templateToken));
 }
 public override Antlr4.StringTemplate.Compiler.CompiledTemplate DefineRegion(string enclosingTemplateName, Antlr.Runtime.IToken regionT, string template, Antlr.Runtime.IToken templateToken)
 {
     return(base.DefineRegion(enclosingTemplateName, regionT, template, templateToken));
 }
Ejemplo n.º 22
0
		public IASTNode ProcessMemberOf(IToken n, IASTNode p, IASTNode root)
		{
			ASTFactory factory = new ASTFactory(adaptor);

			return factory.CreateNode(n == null ? IN : NOT_IN,
			                          n == null ? "in" : "not in",
			                          root.IsNil && root.ChildCount == 1 ? root.GetChild(0) : root,
			                          factory.CreateNode(IN_LIST, "inList",
			                                             CreateSubquery(p)));
		}
 public override Antlr4.StringTemplate.Compiler.CompiledTemplate DefineTemplate(string fullyQualifiedTemplateName, Antlr.Runtime.IToken nameT, List <Antlr4.StringTemplate.Compiler.FormalArgument> args, string template, Antlr.Runtime.IToken templateToken)
 {
     return(base.DefineTemplate(fullyQualifiedTemplateName, nameT, args, template, templateToken));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Override of base to track previous on channel token.
 /// This token is needed as input to decide whether regular expression or division expression recognition is enabled.
 /// </summary>
 public override IToken NextToken()
 {
     IToken result = base.NextToken();
     if (result.Channel == Token.DEFAULT_CHANNEL)
     {
         last = result;
     }
     return result;
 }
Ejemplo n.º 25
0
 private void HandleDelegateGrammar(IToken grammarName, string label)
 {
     Grammar.ImportGrammar(grammarName, label);
 }