github.com/jhump/protocompile@v0.0.0-20221021153901-4f6f732835e8/ast/doc.go (about)

     1  // Package ast defines types for modeling the AST (Abstract Syntax
     2  // Tree) for the protocol buffers source language.
     3  //
     4  // All nodes of the tree implement the Node interface. Leaf nodes in the
     5  // tree implement TerminalNode and all others implement CompositeNode.
     6  // The root of the tree for a proto source file is a *FileNode.
     7  //
     8  // Position information is tracked using a *FileInfo, callings its various
     9  // Add* methods as the file is tokenized by the lexer. This allows AST
    10  // nodes to have a compact representation. To extract detailed position
    11  // information, you must use the nodeInfo method, available on either the
    12  // *FileInfo which produced the node's tokens or the *FileNode root of
    13  // the tree that contains the node.
    14  //
    15  // Comments are not represented as nodes in the tree. Instead, they are
    16  // attributed to terminal nodes in the tree. So, when lexing, comments
    17  // are accumulated until the next non-comment token is found. The AST
    18  // model in this package thus provides access to all comments in the
    19  // file, regardless of location (unlike the SourceCodeInfo present in
    20  // descriptor protos, which is lossy). The comments associated with a
    21  // a non-leaf/non-token node (i.e. a CompositeNode) come from the first
    22  // and last nodes in its sub-tree, for leading and trailing comments
    23  // respectively.
    24  //
    25  // Creation of AST nodes should use the factory functions in this
    26  // package instead of struct literals. Some factory functions accept
    27  // optional arguments, which means the arguments can be nil. If nil
    28  // values are provided for other (non-optional) arguments, the resulting
    29  // node may be invalid and cause panics later in the program.
    30  //
    31  // This package defines numerous interfaces. However, user code should
    32  // not attempt to implement any of them. Most consumers of an AST will
    33  // not work correctly if they encounter concrete implementations other
    34  // than the ones defined in this package.
    35  package ast