github.com/vescale/zgraph@v0.0.0-20230410094002-959c02d50f95/parser/ast/base.go (about)

     1  // Copyright 2022 zGraph Authors. All rights reserved.
     2  //
     3  // Copyright 2015 PingCAP, Inc.
     4  //
     5  // Licensed under the Apache License, Version 2.0 (the "License");
     6  // you may not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  
    16  package ast
    17  
    18  // node is the struct implements Node interface except for Accept method.
    19  // Node implementations should embed it in.
    20  type node struct {
    21  	text   string
    22  	offset int
    23  }
    24  
    25  // SetOriginTextPosition implements Node interface.
    26  func (n *node) SetOriginTextPosition(offset int) {
    27  	n.offset = offset
    28  }
    29  
    30  // OriginTextPosition implements Node interface.
    31  func (n *node) OriginTextPosition() int {
    32  	return n.offset
    33  }
    34  
    35  // SetText implements Node interface.
    36  func (n *node) SetText(text string) {
    37  	n.text = text
    38  }
    39  
    40  // Text implements Node interface.
    41  func (n *node) Text() string {
    42  	return n.text
    43  }
    44  
    45  // stmtNode implements StmtNode interface.
    46  // Statement implementations should embed it in.
    47  type stmtNode struct {
    48  	node
    49  }
    50  
    51  // statement implements StmtNode interface.
    52  func (sn *stmtNode) statement() {}
    53  
    54  // ddlNode implements DDLNode interface.
    55  // DDL implementations should embed it in.
    56  type ddlNode struct {
    57  	stmtNode
    58  }
    59  
    60  // ddlStatement implements DDLNode interface.
    61  func (dn *ddlNode) ddlStatement() {}
    62  
    63  // dmlNode is the struct implements DMLNode interface.
    64  // DML implementations should embed it in.
    65  type dmlNode struct {
    66  	stmtNode
    67  }
    68  
    69  // dmlStatement implements DMLNode interface.
    70  func (dn *dmlNode) dmlStatement() {}
    71  
    72  // exprNode is the struct implements Expression interface.
    73  // Expression implementations should embed it in.
    74  type exprNode struct {
    75  	node
    76  }
    77  
    78  // expression implements ExprNode interface.
    79  func (en *exprNode) expression() {}