github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/text/template/parse/parse.go (about)

     1  // Copyright 2011 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // パッケージparseは、text/templateおよびhtml/templateで定義されているテンプレートのパースツリーを構築します。
     6  // クライアントは、一般的な使用を目的としていない共有内部データ構造を提供するこのパッケージではなく、
     7  // それらのパッケージを使用してテンプレートを構築する必要があります。
     8  package parse
     9  
    10  // Tree is the representation of a single parsed template.
    11  type Tree struct {
    12  	Name      string
    13  	ParseName string
    14  	Root      *ListNode
    15  	Mode      Mode
    16  	text      string
    17  	// Parsing only; cleared after parse.
    18  	funcs      []map[string]any
    19  	lex        *lexer
    20  	token      [3]item
    21  	peekCount  int
    22  	vars       []string
    23  	treeSet    map[string]*Tree
    24  	actionLine int
    25  	rangeDepth int
    26  }
    27  
    28  // mode値はフラグのセット(または0)です。モードはパーサの動作を制御します。
    29  type Mode uint
    30  
    31  const (
    32  	ParseComments Mode = 1 << iota
    33  	SkipFuncCheck
    34  )
    35  
    36  // Copyは [Tree] のコピーを返します。パース状態は破棄されます。
    37  func (t *Tree) Copy() *Tree
    38  
    39  // Parseは、引数の文字列で記述されたテンプレートを解析することで作成された、
    40  // テンプレート名から [Tree] へのマップを返します。トップレベルのテンプレートには
    41  // 指定された名前が付けられます。エラーが発生した場合、解析は停止し、
    42  // エラーと共に空のマップが返されます。
    43  func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]any) (map[string]*Tree, error)
    44  
    45  // Newは、指定された名前を持つ新しいパースツリーを割り当てます。
    46  func New(name string, funcs ...map[string]any) *Tree
    47  
    48  // ErrorContextは、入力テキスト内のノードの位置のテキスト表現を返します。
    49  // 受信者は、ノードが内部にツリーへのポインタを持っていない場合にのみ使用されます。
    50  // これは古いコードで発生する可能性があります。
    51  func (t *Tree) ErrorContext(n Node) (location, context string)
    52  
    53  // Parseは、テンプレート定義文字列を解析して、テンプレートの実行用の表現を構築します。
    54  // アクションデリミタ文字列のいずれかが空の場合、デフォルト("{{"または"}}")が使用されます。
    55  // 埋め込まれたテンプレート定義は、treeSetマップに追加されます。
    56  func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]any) (tree *Tree, err error)
    57  
    58  // IsEmptyTreeは、このツリー(ノード)がスペースまたはコメント以外のすべてが空であるかどうかを報告します。
    59  func IsEmptyTree(n Node) bool