示例#1
0
 public SqlGenerator(ISessionFactoryImplementor sfi, ITreeNodeStream input)
     : this(input)
 {
     parseErrorHandler = new ErrorCounter();
     sessionFactory = sfi;
     writer = new DefaultWriter(this);
 }
 private AlloyOutliningTaggerWalker(ITreeNodeStream input, ReadOnlyCollection<IToken> tokens, AlloyOutliningTaggerProvider provider, ITextSnapshot snapshot)
     : base(input, snapshot, provider.OutputWindowService)
 {
     _tokens = tokens;
     _provider = provider;
     _snapshot = snapshot;
 }
示例#3
0
 public CodeGenerator(ITreeNodeStream input, TemplateCompiler compiler, string name, string template, IToken templateToken)
     : this(input, new RecognizerSharedState())
 {
     this._compiler             = compiler;
     this.outermostTemplateName = name;
     this._template             = template;
     this.templateToken         = templateToken;
 }
示例#4
0
 public TreeRewriter( ITreeNodeStream input, RecognizerSharedState state )
     : base( input, state )
 {
     originalAdaptor = input.TreeAdaptor;
     originalTokenStream = input.TokenStream;
     topdown_func = () => Topdown();
     bottomup_func = () => Bottomup();
 }
示例#5
0
 public CodeGenerator(ITreeNodeStream input, TemplateCompiler compiler, string name, string template, IToken templateToken)
     : this(input, new RecognizerSharedState())
 {
     this._compiler = compiler;
     this.outermostTemplateName = name;
     this._template = template;
     this.templateToken = templateToken;
 }
示例#6
0
 public TreeRewriter(ITreeNodeStream input, RecognizerSharedState state)
     : base(input, state)
 {
     this.originalAdaptor     = input.TreeAdaptor;
     this.originalTokenStream = input.TokenStream;
     this.topdown_func        = (Func <IAstRuleReturnScope>)(() => this.Topdown());
     this.bottomup_func       = (Func <IAstRuleReturnScope>)(() => this.Bottomup());
 }
示例#7
0
 public TreeFilter(ITreeNodeStream input, RecognizerSharedState state)
     : base(input, state)
 {
     originalAdaptor     = input.TreeAdaptor;
     originalTokenStream = input.TokenStream;
     topdown_action      = () => Topdown();
     bottomup_action     = () => Bottomup();
 }
        public DebugExpressionEvaluatorWalker(ITreeNodeStream input, IStackFrame stackFrame)
            : this(input)
        {
            Contract.Requires <ArgumentNullException>(input != null, "input");
            Contract.Requires <ArgumentNullException>(stackFrame != null, "stackFrame");

            _stackFrame = stackFrame;
        }
示例#9
0
 public HqlSqlWalker(
     QueryTranslatorImpl qti,
     ISessionFactoryImplementor sfi,
     ITreeNodeStream input,
     IDictionary <string, string> tokenReplacements,
     string collectionRole)
     : this(qti, sfi, input, tokenReplacements, null, collectionRole)
 {
 }
示例#10
0
 public MismatchedTreeNodeException(
     string message,
     int expecting,
     ITreeNodeStream input,
     Exception innerException)
     : base(message, (IIntStream)input, innerException)
 {
     this._expecting = expecting;
 }
        private AlloyEditorNavigationSourceWalker(ITreeNodeStream input, ITextSnapshot snapshot, ReadOnlyCollection<IToken> tokens, IEditorNavigationTypeRegistryService editorNavigationTypeRegistryService, IGlyphService glyphService, IOutputWindowService outputWindowService)
            : base(input, snapshot, outputWindowService)
        {
            Contract.Requires<ArgumentNullException>(editorNavigationTypeRegistryService != null, "editorNavigationTypeRegistryService");
            Contract.Requires<ArgumentNullException>(glyphService != null, "glyphService");

            _tokens = tokens;
            _editorNavigationTypeRegistryService = editorNavigationTypeRegistryService;
            _glyphService = glyphService;
        }
示例#12
0
 public LeftRecursiveRuleAnalyzer(ITreeNodeStream input, Grammar g, string ruleName)
     : base(input)
 {
     this.g        = g;
     this.ruleName = ruleName;
     language      = (string)g.GetOption("language");
     generator     = new CodeGenerator(g.Tool, g, language);
     generator.LoadTemplates(language);
     recRuleTemplates = LoadPrecRuleTemplates(g.Tool);
 }
 public LeftRecursiveRuleAnalyzer(ITreeNodeStream input, Grammar g, string ruleName)
     : base(input)
 {
     this.g = g;
     this.ruleName = ruleName;
     language = (string)g.GetOption("language");
     generator = new CodeGenerator(g.Tool, g, language);
     generator.LoadTemplates(language);
     recRuleTemplates = LoadPrecRuleTemplates(g.Tool);
 }
        private AlloyEditorNavigationSourceWalker(ITreeNodeStream input, ITextSnapshot snapshot, ReadOnlyCollection <IToken> tokens, IEditorNavigationTypeRegistryService editorNavigationTypeRegistryService, IGlyphService glyphService, IOutputWindowService outputWindowService)
            : base(input, snapshot, outputWindowService)
        {
            Contract.Requires <ArgumentNullException>(editorNavigationTypeRegistryService != null, "editorNavigationTypeRegistryService");
            Contract.Requires <ArgumentNullException>(glyphService != null, "glyphService");

            _tokens = tokens;
            _editorNavigationTypeRegistryService = editorNavigationTypeRegistryService;
            _glyphService = glyphService;
        }
示例#15
0
        private AlloyEditorNavigationSourceWalker(ITreeNodeStream input, ITextSnapshot snapshot, ReadOnlyCollection <IToken> tokens, [NotNull] IEditorNavigationTypeRegistryService editorNavigationTypeRegistryService, [NotNull] IGlyphService glyphService, IOutputWindowService outputWindowService)
            : base(input, snapshot, outputWindowService)
        {
            Requires.NotNull(editorNavigationTypeRegistryService, nameof(editorNavigationTypeRegistryService));
            Requires.NotNull(glyphService, nameof(glyphService));

            _tokens = tokens;
            _editorNavigationTypeRegistryService = editorNavigationTypeRegistryService;
            _glyphService = glyphService;
        }
        protected virtual void ExtractInformationFromTreeNodeStream(IIntStream input)
        {
            ITreeNodeStream nodes = (ITreeNodeStream)input;

            this.node = nodes.LT(1);
            ITreeAdaptor adaptor = nodes.TreeAdaptor;
            IToken       payload = adaptor.GetToken(node);

            if (payload != null)
            {
                this.token = payload;
                if (payload.Line <= 0)
                {
                    // imaginary node; no line/pos info; scan backwards
                    int    i         = -1;
                    object priorNode = nodes.LT(i);
                    while (priorNode != null)
                    {
                        IToken priorPayload = adaptor.GetToken(priorNode);
                        if (priorPayload != null && priorPayload.Line > 0)
                        {
                            // we found the most recent real line / pos info
                            this.line = priorPayload.Line;
                            this.charPositionInLine  = priorPayload.CharPositionInLine;
                            this.approximateLineInfo = true;
                            break;
                        }
                        --i;
                        priorNode = nodes.LT(i);
                    }
                }
                else
                { // node created from real token
                    this.line = payload.Line;
                    this.charPositionInLine = payload.CharPositionInLine;
                }
            }
            else if (this.node is Tree.ITree)
            {
                this.line = ((Tree.ITree) this.node).Line;
                this.charPositionInLine = ((Tree.ITree) this.node).CharPositionInLine;
                if (this.node is CommonTree)
                {
                    this.token = ((CommonTree)this.node).token;
                }
            }
            else
            {
                int    type = adaptor.GetType(this.node);
                string text = adaptor.GetText(this.node);
                this.token = new CommonToken(type, text);
            }
        }
示例#17
0
 public HqlSqlWalker(QueryTranslatorImpl qti,
                     ISessionFactoryImplementor sfi,
                     ITreeNodeStream input,
                     IDictionary <string, string> tokenReplacements,
                     string collectionRole)
     : this(input)
 {
     _sessionFactoryHelper = new SessionFactoryHelperExtensions(sfi);
     _qti = qti;
     _literalProcessor     = new LiteralProcessor(this);
     _tokenReplacements    = tokenReplacements;
     _collectionFilterRole = collectionRole;
 }
示例#18
0
		public HqlSqlWalker(QueryTranslatorImpl qti,
					  ISessionFactoryImplementor sfi,
					  ITreeNodeStream input, 
					  IDictionary<string, string> tokenReplacements,
					  string collectionRole)
			: this(input)
		{
			_sessionFactoryHelper = new SessionFactoryHelperExtensions(sfi);
			_qti = qti;
			_literalProcessor = new LiteralProcessor(this);
			_tokenReplacements = tokenReplacements;
			_collectionFilterRole = collectionRole;
		}
		public DebugTreeGrammar( ITreeNodeStream input, int port, RecognizerSharedState state )
			: base( input, state )
		{
			DebugEventSocketProxy proxy = new DebugEventSocketProxy( this, port, input.TreeAdaptor );
			DebugListener = proxy;
			try
			{
				proxy.Handshake();
			}
			catch ( IOException ioe )
			{
				ReportError( ioe );
			}
		}
示例#20
0
        public void TestSingleNode()
        {
            ITree t = new CommonTree(new CommonToken(101));

            ITreeNodeStream stream    = newStream(t);
            string          expecting = " 101";
            string          found     = ToNodesOnlyString(stream);

            assertEquals(expecting, found);

            expecting = " 101";
            found     = ToTokenTypeString(stream);
            assertEquals(expecting, found);
        }
示例#21
0
        public RecognitionException(string message, IIntStream input, int k, Exception innerException)
            : base(message, innerException)
        {
            this._input = input;
            this._k     = k;
            if (input != null)
            {
                this._index = input.Index + k - 1;
                if (input is ITokenStream)
                {
                    this._token = ((ITokenStream)input).LT(k);
                    this._line  = _token.Line;
                    this._charPositionInLine = _token.CharPositionInLine;
                }

                ITreeNodeStream tns = input as ITreeNodeStream;
                if (tns != null)
                {
                    ExtractInformationFromTreeNodeStream(tns, k);
                }
                else
                {
                    ICharStream charStream = input as ICharStream;
                    if (charStream != null)
                    {
                        int mark = input.Mark();
                        try
                        {
                            for (int i = 0; i < k - 1; i++)
                            {
                                input.Consume();
                            }

                            this._c    = input.LA(1);
                            this._line = ((ICharStream)input).Line;
                            this._charPositionInLine = ((ICharStream)input).CharPositionInLine;
                        }
                        finally
                        {
                            input.Rewind(mark);
                        }
                    }
                    else
                    {
                        this._c = input.LA(k);
                    }
                }
            }
        }
示例#22
0
        public void TestMarkRewindInMiddle() /*throws Exception*/
        {
            // ^(101 ^(102 103 ^(106 107) ) 104 105)
            // stream has 7 real + 6 nav nodes
            // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
            ITree r0 = new CommonTree(new CommonToken(101));
            ITree r1 = new CommonTree(new CommonToken(102));

            r0.AddChild(r1);
            r1.AddChild(new CommonTree(new CommonToken(103)));
            ITree r2 = new CommonTree(new CommonToken(106));

            r2.AddChild(new CommonTree(new CommonToken(107)));
            r1.AddChild(r2);
            r0.AddChild(new CommonTree(new CommonToken(104)));
            r0.AddChild(new CommonTree(new CommonToken(105)));

            ITreeNodeStream stream = newStream(r0);

            for (int k = 1; k <= 7; k++)
            { // consume til middle
                //System.out.println(((Tree)stream.LT(1)).getType());
                stream.Consume();
            }
            assertEquals(107, ((ITree)stream.LT(1)).Type);
            stream.Mark();    // MARK
            stream.Consume(); // consume 107
            stream.Consume(); // consume UP
            stream.Consume(); // consume UP
            stream.Consume(); // consume 104
            stream.Rewind();  // REWIND
            stream.Mark();    // keep saving nodes though

            assertEquals(107, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(TokenTypes.Up, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(TokenTypes.Up, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(104, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            // now we're past rewind position
            assertEquals(105, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(TokenTypes.Up, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(TokenTypes.EndOfFile, ((ITree)stream.LT(1)).Type);
            assertEquals(TokenTypes.Up, ((ITree)stream.LT(-1)).Type);
        }
示例#23
0
    public DebugTreeGrammar(ITreeNodeStream input, int port, RecognizerSharedState state)
        : base(input, state)
    {
        DebugEventSocketProxy proxy = new DebugEventSocketProxy(this, port, input.TreeAdaptor);

        DebugListener = proxy;
        try
        {
            proxy.Handshake();
        }
        catch (IOException ioe)
        {
            ReportError(ioe);
        }
    }
示例#24
0
        public void TestAoverB() /*throws Exception*/
        {
            ITree t = new CommonTree(new CommonToken(101));

            t.AddChild(new CommonTree(new CommonToken(102)));

            ITreeNodeStream stream    = newStream(t);
            string          expecting = " 101 102";
            string          found     = ToNodesOnlyString(stream);

            assertEquals(expecting, found);

            expecting = " 101 2 102 3";
            found     = ToTokenTypeString(stream);
            assertEquals(expecting, found);
        }
示例#25
0
        public void TestListWithOneNode() /*throws Exception*/
        {
            ITree root = new CommonTree((IToken)null);

            root.AddChild(new CommonTree(new CommonToken(101)));

            ITreeNodeStream stream    = newStream(root);
            string          expecting = " 101";
            string          found     = ToNodesOnlyString(stream);

            assertEquals(expecting, found);

            expecting = " 101";
            found     = ToTokenTypeString(stream);
            assertEquals(expecting, found);
        }
        private void HandleWithFragment(FromElement fromElement, IASTNode hqlWithNode)
        {
            try
            {
                ITreeNodeStream old = input;
                input = new CommonTreeNodeStream(adaptor, hqlWithNode);

                IASTNode hqlSqlWithNode = (IASTNode)withClause().Tree;
                input = old;

                if (log.IsDebugEnabled())
                {
                    log.Debug("handleWithFragment() : {0}", _printer.ShowAsString(hqlSqlWithNode, "-- with clause --"));
                }
                WithClauseVisitor visitor   = new WithClauseVisitor(fromElement);
                NodeTraverser     traverser = new NodeTraverser(visitor);
                traverser.TraverseDepthFirst(hqlSqlWithNode);
                FromElement referencedFromElement = visitor.GetReferencedFromElement();
                if (referencedFromElement != fromElement)
                {
                    if (!referencedFromElement.IsEntityJoin() && !fromElement.IsEntityJoin())
                    {
                        throw new InvalidWithClauseException(
                                  "with-clause expressions did not reference from-clause element to which the with-clause was associated");
                    }
                }
                SqlGenerator sql = new SqlGenerator(_sessionFactoryHelper.Factory, new CommonTreeNodeStream(adaptor, hqlSqlWithNode.GetChild(0)));

                sql.whereExpr();

                var withClauseFragment = new SqlString("(", sql.GetSQL(), ")");
                fromElement.SetWithClauseFragment(visitor.GetJoinAlias(), withClauseFragment);
            }
            catch (SemanticException)
            {
                throw;
            }
            catch (InvalidWithClauseException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new SemanticException(e.Message, e);
            }
        }
 public TreeRewriter(ITreeNodeStream input, RecognizerSharedState state) : base(input, state)
 {
     Func<IAstRuleReturnScope> func = null;
     Func<IAstRuleReturnScope> func2 = null;
     this.originalAdaptor = input.TreeAdaptor;
     this.originalTokenStream = input.TokenStream;
     if (func == null)
     {
         func = () => this.Topdown();
     }
     this.topdown_func = func;
     if (func2 == null)
     {
         func2 = () => this.Bottomup();
     }
     this.bottomup_func = func2;
 }
示例#28
0
        public void TestFlatList() /*throws Exception*/
        {
            ITree root = new CommonTree((IToken)null);

            root.AddChild(new CommonTree(new CommonToken(101)));
            root.AddChild(new CommonTree(new CommonToken(102)));
            root.AddChild(new CommonTree(new CommonToken(103)));

            ITreeNodeStream stream    = newStream(root);
            string          expecting = " 101 102 103";
            string          found     = ToNodesOnlyString(stream);

            Assert.AreEqual(expecting, found);

            expecting = " 101 102 103";
            found     = ToTokenTypeString(stream);
            Assert.AreEqual(expecting, found);
        }
示例#29
0
        protected virtual void ExtractInformationFromTreeNodeStream(ITreeNodeStream input, int k)
        {
            int mark = input.Mark();

            try
            {
                for (int i = 0; i < k - 1; i++)
                {
                    input.Consume();
                }

                ExtractInformationFromTreeNodeStream(input);
            }
            finally
            {
                input.Rewind(mark);
            }
        }
示例#30
0
        public void TestMarkRewindNested() /*throws Exception*/
        {
            // ^(101 ^(102 103 ^(106 107) ) 104 105)
            // stream has 7 real + 6 nav nodes
            // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
            ITree r0 = new CommonTree(new CommonToken(101));
            ITree r1 = new CommonTree(new CommonToken(102));

            r0.AddChild(r1);
            r1.AddChild(new CommonTree(new CommonToken(103)));
            ITree r2 = new CommonTree(new CommonToken(106));

            r2.AddChild(new CommonTree(new CommonToken(107)));
            r1.AddChild(r2);
            r0.AddChild(new CommonTree(new CommonToken(104)));
            r0.AddChild(new CommonTree(new CommonToken(105)));

            ITreeNodeStream stream = newStream(r0);
            int             m      = stream.Mark(); // MARK at start

            stream.Consume();                       // consume 101
            stream.Consume();                       // consume DN
            int m2 = stream.Mark();                 // MARK on 102

            stream.Consume();                       // consume 102
            stream.Consume();                       // consume DN
            stream.Consume();                       // consume 103
            stream.Consume();                       // consume 106
            stream.Rewind(m2);                      // REWIND to 102
            assertEquals(102, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(TokenTypes.Down, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            // stop at 103 and rewind to start
            stream.Rewind(m);   // REWIND to 101
            assertEquals(101, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(TokenTypes.Down, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(102, ((ITree)stream.LT(1)).Type);
            stream.Consume();
            assertEquals(TokenTypes.Down, ((ITree)stream.LT(1)).Type);
        }
示例#31
0
        public void Test4Nodes() /*throws Exception*/
        {
            // ^(101 ^(102 103) 104)
            ITree t = new CommonTree(new CommonToken(101));

            t.AddChild(new CommonTree(new CommonToken(102)));
            t.GetChild(0).AddChild(new CommonTree(new CommonToken(103)));
            t.AddChild(new CommonTree(new CommonToken(104)));

            ITreeNodeStream stream    = newStream(t);
            string          expecting = " 101 102 103 104";
            string          found     = ToNodesOnlyString(stream);

            assertEquals(expecting, found);

            expecting = " 101 2 102 2 103 3 104 3";
            found     = ToTokenTypeString(stream);
            assertEquals(expecting, found);
        }
示例#32
0
        public string ToNodesOnlyString(ITreeNodeStream nodes)
        {
            ITreeAdaptor  adaptor = nodes.TreeAdaptor;
            StringBuilder buf     = new StringBuilder();
            object        o       = nodes.LT(1);
            int           type    = adaptor.GetType(o);

            while (o != null && type != TokenTypes.EndOfFile)
            {
                if (!(type == TokenTypes.Down || type == TokenTypes.Up))
                {
                    buf.Append(" ");
                    buf.Append(type);
                }
                nodes.Consume();
                o    = nodes.LT(1);
                type = adaptor.GetType(o);
            }
            return(buf.ToString());
        }
示例#33
0
        void PrepareFromClauseInputTree(IASTNode fromClauseInput, ITreeNodeStream input)
        {
            if (IsFilter())
            {
                // Handle collection-fiter compilation.
                // IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
                IQueryableCollection persister = _sessionFactoryHelper.GetCollectionPersister(_collectionFilterRole);
                IType collectionElementType    = persister.ElementType;
                if (!collectionElementType.IsEntityType)
                {
                    throw new QueryException("collection of values in filter: this");
                }

                string collectionElementEntityName = persister.ElementPersister.EntityName;

                IASTNode fromElement = (IASTNode)adaptor.Create(FILTER_ENTITY, collectionElementEntityName);
                IASTNode alias       = (IASTNode)adaptor.Create(ALIAS, "this");

                ((HqlSqlWalkerTreeNodeStream)input).InsertChild(fromClauseInput, fromElement);
                ((HqlSqlWalkerTreeNodeStream)input).InsertChild(fromClauseInput, alias);

//				fromClauseInput.AddChild(fromElement);
//				fromClauseInput.AddChild(alias);

                // Show the modified AST.
                if (log.IsDebugEnabled)
                {
                    log.Debug("prepareFromClauseInputTree() : Filter - Added 'this' as a from element...");
                }

                // Create a parameter specification for the collection filter...
                IType         collectionFilterKeyType      = _sessionFactoryHelper.RequireQueryableCollection(_collectionFilterRole).KeyType;
                ParameterNode collectionFilterKeyParameter = (ParameterNode)adaptor.Create(PARAM, "?");
                CollectionFilterKeyParameterSpecification collectionFilterKeyParameterSpec = new CollectionFilterKeyParameterSpecification(
                    _collectionFilterRole, collectionFilterKeyType, _positionalParameterCount++
                    );
                collectionFilterKeyParameter.HqlParameterSpecification = collectionFilterKeyParameterSpec;
                _parameters.Add(collectionFilterKeyParameterSpec);
            }
        }
示例#34
0
        public void TestDeepTree()
        {
            // ^(10 100 101 ^(20 ^(30 40 (50 (60 70)))) (80 90)))
            // stream has 8 real + 10 nav nodes
            int n = 9;

            CommonTree[] nodes = new CommonTree[n];
            for (int i = 0; i < n; i++)
            {
                nodes[i] = new CommonTree(new CommonToken((i + 1) * 10));
            }
            ITree g     = nodes[0];
            ITree rules = nodes[1];
            ITree rule1 = nodes[2];
            ITree id    = nodes[3];
            ITree block = nodes[4];
            ITree alt   = nodes[5];
            ITree s     = nodes[6];
            ITree rule2 = nodes[7];
            ITree id2   = nodes[8];

            g.AddChild(new CommonTree(new CommonToken(100)));
            g.AddChild(new CommonTree(new CommonToken(101)));
            g.AddChild(rules);
            rules.AddChild(rule1);
            rule1.AddChild(id);
            rule1.AddChild(block);
            block.AddChild(alt);
            alt.AddChild(s);
            rules.AddChild(rule2);
            rule2.AddChild(id2);

            ITreeNodeStream stream    = newStream(g);
            string          expecting = " 10 2 100 101 20 2 30 2 40 50 2 60 2 70 3 3 3 80 2 90 3 3 3";
            string          found     = ToTokenTypeString(stream);

            Assert.AreEqual(expecting, found);
        }
示例#35
0
        public void TestLT() /*throws Exception*/
        {
            // ^(101 ^(102 103) 104)
            ITree t = new CommonTree(new CommonToken(101));

            t.AddChild(new CommonTree(new CommonToken(102)));
            t.GetChild(0).AddChild(new CommonTree(new CommonToken(103)));
            t.AddChild(new CommonTree(new CommonToken(104)));

            ITreeNodeStream stream = newStream(t);

            assertEquals(101, ((ITree)stream.LT(1)).Type);
            assertEquals(TokenTypes.Down, ((ITree)stream.LT(2)).Type);
            assertEquals(102, ((ITree)stream.LT(3)).Type);
            assertEquals(TokenTypes.Down, ((ITree)stream.LT(4)).Type);
            assertEquals(103, ((ITree)stream.LT(5)).Type);
            assertEquals(TokenTypes.Up, ((ITree)stream.LT(6)).Type);
            assertEquals(104, ((ITree)stream.LT(7)).Type);
            assertEquals(TokenTypes.Up, ((ITree)stream.LT(8)).Type);
            assertEquals(TokenTypes.EndOfFile, ((ITree)stream.LT(9)).Type);
            // check way ahead
            assertEquals(TokenTypes.EndOfFile, ((ITree)stream.LT(100)).Type);
        }
示例#36
0
        private void HandleWithFragment(FromElement fromElement, IASTNode hqlWithNode)
        {
            try
            {
                ITreeNodeStream old = input;
                input = new CommonTreeNodeStream(adaptor, hqlWithNode);

                IASTNode hqlSqlWithNode = (IASTNode)withClause().Tree;
                input = old;

                if (log.IsDebugEnabled())
                {
                    log.Debug("handleWithFragment() : {0}", _printer.ShowAsString(hqlSqlWithNode, "-- with clause --"));
                }
                WithClauseVisitor visitor   = new WithClauseVisitor(fromElement);
                NodeTraverser     traverser = new NodeTraverser(visitor);
                traverser.TraverseDepthFirst(hqlSqlWithNode);
                SqlGenerator sql = new SqlGenerator(_sessionFactoryHelper.Factory, new CommonTreeNodeStream(adaptor, hqlSqlWithNode.GetChild(0)));

                sql.whereExpr();

                fromElement.WithClauseFragment = new SqlString("(", sql.GetSQL(), ")");
            }
            catch (SemanticException)
            {
                throw;
            }
            catch (InvalidWithClauseException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new SemanticException(e.Message, e);
            }
        }
示例#37
0
        /// <summary>
        /// Input an expression token in tree structure, return a single token representing the whole expression
        /// </summary>
        /// <param name="rootToken"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public static IToken GetExpressionToken(CommonTree rootToken, ITreeNodeStream input)
        {
            try
            {
                ITokenStream stream = ((Antlr.Runtime.Tree.CommonTreeNodeStream)(input)).TokenStream;

                int    start  = rootToken.TokenStartIndex;
                int    end    = rootToken.TokenStopIndex;
                IToken token1 = new CommonToken(); //(Token.DEFAULT_CHANNEL
                token1.CharPositionInLine = stream.Get(start).CharPositionInLine;
                token1.Line = stream.Get(start).Line;

                for (int i = start; i <= end; i++)
                {
                    token1.Text += stream.Get(i).Text;
                }
                return(token1);
            }
            catch (Exception)
            {
            }

            return(rootToken.Token);
        }
示例#38
0
        public void TestMarkRewindEntire() /*throws Exception*/
        {
            // ^(101 ^(102 103 ^(106 107) ) 104 105)
            // stream has 7 real + 6 nav nodes
            // Sequence of types: 101 DN 102 DN 103 106 DN 107 UP UP 104 105 UP EOF
            ITree r0 = new CommonTree(new CommonToken(101));
            ITree r1 = new CommonTree(new CommonToken(102));

            r0.AddChild(r1);
            r1.AddChild(new CommonTree(new CommonToken(103)));
            ITree r2 = new CommonTree(new CommonToken(106));

            r2.AddChild(new CommonTree(new CommonToken(107)));
            r1.AddChild(r2);
            r0.AddChild(new CommonTree(new CommonToken(104)));
            r0.AddChild(new CommonTree(new CommonToken(105)));

            ITreeNodeStream stream = newStream(r0);
            int             m      = stream.Mark(); // MARK

            for (int k = 1; k <= 13; k++)
            { // consume til end
                stream.LT(1);
                stream.Consume();
            }
            assertEquals(TokenTypes.EndOfFile, ((ITree)stream.LT(1)).Type);
            stream.Rewind(m);        // REWIND

            // consume til end again :)
            for (int k = 1; k <= 13; k++)
            { // consume til end
                stream.LT(1);
                stream.Consume();
            }
            assertEquals(TokenTypes.EndOfFile, ((ITree)stream.LT(1)).Type);
        }
示例#39
0
    // delegates
    // delegators



        public BonsaiTree(ITreeNodeStream input)
    		: this(input, new RecognizerSharedState()) {
        }
示例#40
0
 public virtual string ToTokenTypeString( ITreeNodeStream stream )
 {
     return ( (CommonTreeNodeStream)stream ).ToTokenTypeString();
 }
示例#41
0
 protected virtual void ExtractInformationFromTreeNodeStream(ITreeNodeStream input)
 {
     this._node = input.LT(1);
     ITokenStreamInformation streamInformation = input as ITokenStreamInformation;
     if (streamInformation != null)
     {
         IToken lastToken = streamInformation.LastToken;
         IToken lastRealToken = streamInformation.LastRealToken;
         if (lastRealToken != null)
         {
             this._token = lastRealToken;
             this._line = lastRealToken.Line;
             this._charPositionInLine = lastRealToken.CharPositionInLine;
             this._approximateLineInfo = lastRealToken.Equals(lastToken);
         }
     }
     else
     {
         ITreeAdaptor adaptor = input.TreeAdaptor;
         IToken payload = adaptor.GetToken(_node);
         if (payload != null)
         {
             this._token = payload;
             if (payload.Line <= 0)
             {
                 // imaginary node; no line/pos info; scan backwards
                 int i = -1;
                 object priorNode = input.LT(i);
                 while (priorNode != null)
                 {
                     IToken priorPayload = adaptor.GetToken(priorNode);
                     if (priorPayload != null && priorPayload.Line > 0)
                     {
                         // we found the most recent real line / pos info
                         this._line = priorPayload.Line;
                         this._charPositionInLine = priorPayload.CharPositionInLine;
                         this._approximateLineInfo = true;
                         break;
                     }
                     --i;
                     try
                     {
                         priorNode = input.LT(i);
                     }
                     catch (ArgumentException)
                     {
                         priorNode = null;
                     }
                 }
             }
             else
             {
                 // node created from real token
                 this._line = payload.Line;
                 this._charPositionInLine = payload.CharPositionInLine;
             }
         }
         else if (this._node is Tree.ITree)
         {
             this._line = ((Tree.ITree)this._node).Line;
             this._charPositionInLine = ((Tree.ITree)this._node).CharPositionInLine;
             if (this._node is CommonTree)
             {
                 this._token = ((CommonTree)this._node).Token;
             }
         }
         else
         {
             int type = adaptor.GetType(this._node);
             string text = adaptor.GetText(this._node);
             this._token = new CommonToken(type, text);
         }
     }
 }
示例#42
0
    ///////////////////////////////////////////
    //
    // Construction
    //
    ///////////////////////////////////////////

    public NadirTreePatternMatcher(ITreeNodeStream input, RecognizerSharedState state) : base(input, state)
        {
        originalAdaptor     = (ITreeAdaptor)input.TreeAdaptor;
        originalTokenStream = input.TokenStream;
        }
示例#43
0
 public NadirTreeFilter(ITreeNodeStream input, RecognizerSharedState state) : base(input, state)
     {
     }
示例#44
0
 public FKVMGen(ITreeNodeStream input)
     : base(input)
 {
     InitializeCyclicDFAs();
 }
示例#45
0
        public NadirASTOptimizer(ITreeNodeStream input, RecognizerSharedState state)
    		: base(input, state) {
            InitializeCyclicDFAs();

             
        }
示例#46
0
		void PrepareFromClauseInputTree(IASTNode fromClauseInput, ITreeNodeStream input)
		{
			if (IsFilter())
			{
				// Handle collection-fiter compilation.
				// IMPORTANT NOTE: This is modifying the INPUT (HQL) tree, not the output tree!
				IQueryableCollection persister = _sessionFactoryHelper.GetCollectionPersister(_collectionFilterRole);
				IType collectionElementType = persister.ElementType;
				if (!collectionElementType.IsEntityType)
				{
					throw new QueryException("collection of values in filter: this");
				}

				string collectionElementEntityName = persister.ElementPersister.EntityName;

				IASTNode fromElement = (IASTNode)adaptor.Create(FILTER_ENTITY, collectionElementEntityName);
				IASTNode alias = (IASTNode)adaptor.Create(ALIAS, "this");

                ((HqlSqlWalkerTreeNodeStream)input).InsertChild(fromClauseInput, fromElement);
                ((HqlSqlWalkerTreeNodeStream)input).InsertChild(fromClauseInput, alias);

//				fromClauseInput.AddChild(fromElement);
//				fromClauseInput.AddChild(alias);

				// Show the modified AST.
				if (log.IsDebugEnabled)
				{
					log.Debug("prepareFromClauseInputTree() : Filter - Added 'this' as a from element...");
				}
				
				// Create a parameter specification for the collection filter...
				IType collectionFilterKeyType = _sessionFactoryHelper.RequireQueryableCollection(_collectionFilterRole).KeyType;
				ParameterNode collectionFilterKeyParameter = (ParameterNode)adaptor.Create(PARAM, "?");
				CollectionFilterKeyParameterSpecification collectionFilterKeyParameterSpec = new CollectionFilterKeyParameterSpecification(
						_collectionFilterRole, collectionFilterKeyType, _positionalParameterCount++
				);
				collectionFilterKeyParameter.HqlParameterSpecification = collectionFilterKeyParameterSpec;
				_parameters.Add(collectionFilterKeyParameterSpec);
			}
		}
	public SimpleCTreeWalker(ITreeNodeStream input, RecognizerSharedState state)
		: base(input, state)
	{
		OnCreated();
	}
示例#48
0
        public SqlGenerator(ITreeNodeStream input, RecognizerSharedState state)
    		: base(input, state) {
            InitializeCyclicDFAs();

             
        }
示例#49
0
    // delegates
    // delegators



        public SqlGenerator(ITreeNodeStream input)
    		: this(input, new RecognizerSharedState()) {
        }
示例#50
0
        protected virtual void ExtractInformationFromTreeNodeStream(ITreeNodeStream input, int k)
        {
            int mark = input.Mark();
            try
            {
                for (int i = 0; i < k - 1; i++)
                    input.Consume();

                ExtractInformationFromTreeNodeStream(input);
            }
            finally
            {
                input.Rewind(mark);
            }
        }
示例#51
0
    // delegates
    // delegators



        public NadirASTOptimizer(ITreeNodeStream input)
    		: this(input, new RecognizerSharedState()) {
        }
 public override string ToTokenTypeString( ITreeNodeStream stream )
 {
     return ( (BufferedTreeNodeStream)stream ).ToTokenTypeString();
 }
示例#53
0
 public NadirTreeParserBase(ITreeNodeStream input, RecognizerSharedState state) : base(input, state)
     {
     }
示例#54
0
		public TreeParser(ITreeNodeStream input, RecognizerSharedState state)
			: base(state) // share the state object with another parser
		{
			TreeNodeStream = input;
		}
示例#55
0
    ///////////////////////////////////////////
    //
    // Construction
    //
    ///////////////////////////////////////////

    public NadirTreeFilter(ITreeNodeStream input) 
        : this(input, new RecognizerSharedState())
        {
        }
示例#56
0
		public TreeParser(ITreeNodeStream input)
			: base() // highlight that we go to super to set state object
		{
			TreeNodeStream = input;
		}
        protected virtual void ExtractInformationFromTreeNodeStream(ITreeNodeStream input)
        {
            this._node = input.LT(1);
            ITokenStreamInformation streamInformation = input as ITokenStreamInformation;

            if (streamInformation != null)
            {
                IToken lastToken     = streamInformation.LastToken;
                IToken lastRealToken = streamInformation.LastRealToken;
                if (lastRealToken != null)
                {
                    this._token = lastRealToken;
                    this._line  = lastRealToken.Line;
                    this._charPositionInLine  = lastRealToken.CharPositionInLine;
                    this._approximateLineInfo = lastRealToken.Equals(lastToken);
                }
            }
            else
            {
                ITreeAdaptor adaptor = input.TreeAdaptor;
                IToken       payload = adaptor.GetToken(_node);
                if (payload != null)
                {
                    this._token = payload;
                    if (payload.Line <= 0)
                    {
                        // imaginary node; no line/pos info; scan backwards
                        int    i         = -1;
                        object priorNode = input.LT(i);
                        while (priorNode != null)
                        {
                            IToken priorPayload = adaptor.GetToken(priorNode);
                            if (priorPayload != null && priorPayload.Line > 0)
                            {
                                // we found the most recent real line / pos info
                                this._line = priorPayload.Line;
                                this._charPositionInLine  = priorPayload.CharPositionInLine;
                                this._approximateLineInfo = true;
                                break;
                            }
                            --i;
                            try
                            {
                                priorNode = input.LT(i);
                            }
                            catch (ArgumentException)
                            {
                                priorNode = null;
                            }
                        }
                    }
                    else
                    {
                        // node created from real token
                        this._line = payload.Line;
                        this._charPositionInLine = payload.CharPositionInLine;
                    }
                }
                else if (this._node is Tree.ITree)
                {
                    this._line = ((Tree.ITree) this._node).Line;
                    this._charPositionInLine = ((Tree.ITree) this._node).CharPositionInLine;
                    if (this._node is CommonTree)
                    {
                        this._token = ((CommonTree)this._node).Token;
                    }
                }
                else
                {
                    int    type = adaptor.GetType(this._node);
                    string text = adaptor.GetText(this._node);
                    this._token = new CommonToken(type, text);
                }
            }
        }
示例#58
0
 public string ToNodesOnlyString( ITreeNodeStream nodes )
 {
     ITreeAdaptor adaptor = nodes.TreeAdaptor;
     StringBuilder buf = new StringBuilder();
     object o = nodes.LT( 1 );
     int type = adaptor.GetType( o );
     while ( o != null && type != TokenTypes.EndOfFile )
     {
         if ( !( type == TokenTypes.Down || type == TokenTypes.Up ) )
         {
             buf.Append( " " );
             buf.Append( type );
         }
         nodes.Consume();
         o = nodes.LT( 1 );
         type = adaptor.GetType( o );
     }
     return buf.ToString();
 }
示例#59
0
        public BonsaiTree(ITreeNodeStream input, RecognizerSharedState state)
    		: base(input, state) {
            InitializeCyclicDFAs();

             
        }
	public SimpleCTreeWalker(ITreeNodeStream input)
		: this(input, new RecognizerSharedState())
	{
	}