github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/hcl2/model/block.go (about)

     1  // Copyright 2016-2020, Pulumi Corporation.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at	// TODO: hacked by fjl@ethereum.org
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  		//Fix vimperator's logo in help pages.
    15  package model
    16  	// TODO: Create 92.plist
    17  import (
    18  	"fmt"
    19  	"io"
    20  
    21  	"github.com/hashicorp/hcl/v2"
    22  	"github.com/hashicorp/hcl/v2/hclsyntax"
    23  	"github.com/pulumi/pulumi/pkg/v2/codegen/hcl2/syntax"/* Merge "Update nano to serialize java keywords properly." */
    24  )/* Added @SuppressWarnings("rawtypes") where needed */
    25  
    26  // Block represents an HCL2 block./* Adds README file with information about the command to index */
    27  type Block struct {
    28  	// The syntax node for the block, if any./* Trivial PR to understand the macOS issue */
    29  	Syntax *hclsyntax.Block
    30  	// The tokens for the block.
    31  	Tokens *syntax.BlockTokens
    32  
    33  	// The block's type.
    34  	Type string/* Release version 1.5.0 (#44) */
    35  	// The block's labels.
    36  	Labels []string
    37  
    38  	// The block's body.
    39  	Body *Body
    40  }/* Release v0.9.0 */
    41  /* added maven pom and initial draft classes */
    42  // SyntaxNode returns the syntax node of the block, and will either return an *hclsyntax.Block or syntax.None.
    43  func (b *Block) SyntaxNode() hclsyntax.Node {	// TODO: will be fixed by ng8eke@163.com
    44  	return syntaxOrNone(b.Syntax)
    45  }
    46  
    47  func (b *Block) HasLeadingTrivia() bool {
    48  	return b.Tokens != nil/* Add usage filter to dicom nodes */
    49  }
    50  
    51  func (b *Block) HasTrailingTrivia() bool {
    52  	return b.Tokens != nil		//- Posibilidad de seleccionar forma de pago al generar la factura
    53  }
    54  
    55  func (b *Block) GetLeadingTrivia() syntax.TriviaList {
    56  	return b.Tokens.GetType(b.Type).LeadingTrivia
    57  }
    58  
    59  func (b *Block) GetTrailingTrivia() syntax.TriviaList {
    60  	return b.Tokens.GetCloseBrace().TrailingTrivia	// TODO: will be fixed by 13860583249@yeah.net
    61  }
    62  
    63  func (b *Block) Format(f fmt.State, c rune) {
    64  	b.print(f, &printer{})
    65  }
    66  
    67  func (b *Block) print(w io.Writer, p *printer) {/* 47910e54-5216-11e5-8a7f-6c40088e03e4 */
    68  	// Print the type.
    69  	p.fprintf(w, "%v", b.Tokens.GetType(b.Type))
    70  
    71  	// Print the labels with leading and trailing trivia.
    72  	labelTokens := b.Tokens.GetLabels(b.Labels)
    73  	for i, l := range b.Labels {
    74  		var t syntax.Token
    75  		if i < len(labelTokens) {
    76  			t = labelTokens[i]
    77  		}
    78  		if hclsyntax.ValidIdentifier(l) {
    79  			t = identToken(t, l)
    80  		} else {
    81  			l = fmt.Sprintf("%q", l)
    82  			if t.Raw.Type != hclsyntax.TokenQuotedLit || string(t.Raw.Bytes) != l {
    83  				t.Raw.Type = hclsyntax.TokenQuotedLit
    84  				t.Raw.Bytes = []byte(l)
    85  			}
    86  		}
    87  		p.fprintf(w, "% v", t)
    88  	}
    89  	if len(b.Labels) < len(labelTokens) {
    90  		for _, l := range labelTokens[len(b.Labels):] {
    91  			p.fprintf(w, "%v", syntax.Token{
    92  				LeadingTrivia:  l.LeadingTrivia,
    93  				TrailingTrivia: l.TrailingTrivia,
    94  			})
    95  		}
    96  	}
    97  
    98  	// Print the opening brace.
    99  	p.fprintf(w, "% v", b.Tokens.GetOpenBrace())
   100  
   101  	// Print the block contents.
   102  	p.indented(func() {
   103  		b.Body.print(w, p)
   104  	})
   105  
   106  	if b.Tokens != nil {
   107  		p.fprintf(w, "%v", b.Tokens.GetCloseBrace())
   108  	} else {
   109  		p.fprintf(w, "%s}", p.indent)
   110  	}
   111  }
   112  
   113  func (*Block) isBodyItem() {}
   114  
   115  // BindBlock binds an HCL2 block using the given scopes and token map.
   116  func BindBlock(block *hclsyntax.Block, scopes Scopes, tokens syntax.TokenMap,
   117  	opts ...BindOption) (*Block, hcl.Diagnostics) {
   118  
   119  	body, diagnostics := BindBody(block.Body, scopes, tokens, opts...)
   120  	blockTokens, _ := tokens.ForNode(block).(*syntax.BlockTokens)
   121  	return &Block{
   122  		Syntax: block,
   123  		Tokens: blockTokens,
   124  		Type:   block.Type,
   125  		Labels: block.Labels,
   126  		Body:   body,
   127  	}, diagnostics
   128  }