| 1 | package printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ |
| 2 | |
| 3 | import ( |
| 4 | "fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/" |
| 5 | "mathscip-go gomod github.com/golang/go/src go1.21.0 math/" |
| 6 | "stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/" |
| 7 | |
| 8 | "github.com/goccy/go-yaml/astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/" |
| 9 | "github.com/goccy/go-yaml/tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/" |
| 10 | ) |
| 11 | |
| 12 | // Property additional property set for each the token |
| 13 | type Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# struct { |
| 14 | Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix. string |
| 15 | Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix. string |
| 16 | } |
| 17 | |
| 18 | // PrintFunc returns property instance |
| 19 | type PrintFuncscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/PrintFunc# func() *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# |
| 20 | |
| 21 | // Printer create text from token collection or ast |
| 22 | type Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer# struct { |
| 23 | LineNumberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumber. bool |
| 24 | LineNumberFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumberFormat. func(num int) string |
| 25 | MapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#MapKey. PrintFuncscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/PrintFunc# |
| 26 | Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Anchor. PrintFuncscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/PrintFunc# |
| 27 | Aliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Alias. PrintFuncscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/PrintFunc# |
| 28 | Boolscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Bool. PrintFuncscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/PrintFunc# |
| 29 | Stringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#String. PrintFuncscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/PrintFunc# |
| 30 | Numberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Number. PrintFuncscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/PrintFunc# |
| 31 | Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Comment. PrintFuncscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/PrintFunc# |
| 32 | } |
| 33 | |
| 34 | func defaultLineNumberFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/defaultLineNumberFormat().(num int) string { |
| 35 | return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%2d | ", num) |
| 36 | } |
| 37 | |
| 38 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#property().(tk *tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#) *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# { |
| 39 | prop := &Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#{} |
| 40 | switch tk.PreviousTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#PreviousType().() { |
| 41 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.AnchorTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/AnchorType.: |
| 42 | if p.Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Anchor. != nil { |
| 43 | return p.Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Anchor.() |
| 44 | } |
| 45 | return prop |
| 46 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.AliasTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/AliasType.: |
| 47 | if p.Aliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Alias. != nil { |
| 48 | return p.Aliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Alias.() |
| 49 | } |
| 50 | return prop |
| 51 | } |
| 52 | switch tk.NextTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#NextType().() { |
| 53 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.MappingValueTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/MappingValueType.: |
| 54 | if p.MapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#MapKey. != nil { |
| 55 | return p.MapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#MapKey.() |
| 56 | } |
| 57 | return prop |
| 58 | } |
| 59 | switch tk.Typescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Type. { |
| 60 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.BoolTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/BoolType.: |
| 61 | if p.Boolscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Bool. != nil { |
| 62 | return p.Boolscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Bool.() |
| 63 | } |
| 64 | return prop |
| 65 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.AnchorTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/AnchorType.: |
| 66 | if p.Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Anchor. != nil { |
| 67 | return p.Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Anchor.() |
| 68 | } |
| 69 | return prop |
| 70 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.AliasTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/AliasType.: |
| 71 | if p.Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Anchor. != nil { |
| 72 | return p.Aliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Alias.() |
| 73 | } |
| 74 | return prop |
| 75 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.StringTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/StringType., tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.SingleQuoteTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/SingleQuoteType., tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.DoubleQuoteTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/DoubleQuoteType.: |
| 76 | if p.Stringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#String. != nil { |
| 77 | return p.Stringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#String.() |
| 78 | } |
| 79 | return prop |
| 80 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.IntegerTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/IntegerType., tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.FloatTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/FloatType.: |
| 81 | if p.Numberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Number. != nil { |
| 82 | return p.Numberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Number.() |
| 83 | } |
| 84 | return prop |
| 85 | case tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.CommentTypescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/CommentType.: |
| 86 | if p.Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Comment. != nil { |
| 87 | return p.Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Comment.() |
| 88 | } |
| 89 | return prop |
| 90 | default: |
| 91 | } |
| 92 | return prop |
| 93 | } |
| 94 | |
| 95 | // PrintTokens create text from token collection |
| 96 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) PrintTokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintTokens().(tokens tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#) string { |
| 97 | if len(tokens) == 0 { |
| 98 | return "" |
| 99 | } |
| 100 | if p.LineNumberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumber. { |
| 101 | if p.LineNumberFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumberFormat. == nil { |
| 102 | p.LineNumberFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumberFormat. = defaultLineNumberFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/defaultLineNumberFormat(). |
| 103 | } |
| 104 | } |
| 105 | texts := []string{} |
| 106 | lineNumber := tokens[0].Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Position..Linescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Position#Line. |
| 107 | for _, tk := range tokens { |
| 108 | lines := stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Splitscip-go gomod github.com/golang/go/src go1.21.0 strings/Split().(tk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin., "\n") |
| 109 | prop := p.propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#property().(tk) |
| 110 | header := "" |
| 111 | if p.LineNumberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumber. { |
| 112 | header = p.LineNumberFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumberFormat.(lineNumber) |
| 113 | } |
| 114 | if len(lines) == 1 { |
| 115 | line := prop.Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix. + lines[0] + prop.Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix. |
| 116 | if len(texts) == 0 { |
| 117 | texts = append(texts, header+line) |
| 118 | lineNumber++ |
| 119 | } else { |
| 120 | text := texts[len(texts)-1] |
| 121 | texts[len(texts)-1] = text + line |
| 122 | } |
| 123 | } else { |
| 124 | for idx, src := range lines { |
| 125 | if p.LineNumberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumber. { |
| 126 | header = p.LineNumberFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumberFormat.(lineNumber) |
| 127 | } |
| 128 | line := prop.Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix. + src + prop.Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix. |
| 129 | if idx == 0 { |
| 130 | if len(texts) == 0 { |
| 131 | texts = append(texts, header+line) |
| 132 | lineNumber++ |
| 133 | } else { |
| 134 | text := texts[len(texts)-1] |
| 135 | texts[len(texts)-1] = text + line |
| 136 | } |
| 137 | } else { |
| 138 | texts = append(texts, fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%s%s", header, line)) |
| 139 | lineNumber++ |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | return stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Joinscip-go gomod github.com/golang/go/src go1.21.0 strings/Join().(texts, "\n") |
| 145 | } |
| 146 | |
| 147 | // PrintNode create text from ast.Node |
| 148 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) PrintNodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintNode().(node astscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/.Nodescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/ast`/Node#) []byte { |
| 149 | return []byte(fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%+v\n", node)) |
| 150 | } |
| 151 | |
| 152 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) setDefaultColorSetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#setDefaultColorSet().() { |
| 153 | p.Boolscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Bool. = func() *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# { |
| 154 | return &Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#{ |
| 155 | Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorFgHiMagentascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiMagenta.), |
| 156 | Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.), |
| 157 | } |
| 158 | } |
| 159 | p.Numberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Number. = func() *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# { |
| 160 | return &Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#{ |
| 161 | Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorFgHiMagentascip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiMagenta.), |
| 162 | Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.), |
| 163 | } |
| 164 | } |
| 165 | p.MapKeyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#MapKey. = func() *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# { |
| 166 | return &Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#{ |
| 167 | Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorFgHiCyanscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiCyan.), |
| 168 | Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.), |
| 169 | } |
| 170 | } |
| 171 | p.Anchorscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Anchor. = func() *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# { |
| 172 | return &Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#{ |
| 173 | Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorFgHiYellowscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiYellow.), |
| 174 | Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.), |
| 175 | } |
| 176 | } |
| 177 | p.Aliasscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Alias. = func() *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# { |
| 178 | return &Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#{ |
| 179 | Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorFgHiYellowscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiYellow.), |
| 180 | Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.), |
| 181 | } |
| 182 | } |
| 183 | p.Stringscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#String. = func() *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# { |
| 184 | return &Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#{ |
| 185 | Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorFgHiGreenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiGreen.), |
| 186 | Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.), |
| 187 | } |
| 188 | } |
| 189 | p.Commentscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#Comment. = func() *Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property# { |
| 190 | return &Propertyscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#{ |
| 191 | Prefixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Prefix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorFgHiBlackscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiBlack.), |
| 192 | Suffixscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Property#Suffix.: formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.), |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) PrintErrorMessagescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorMessage().(msg string, isColored bool) string { |
| 198 | if isColored { |
| 199 | return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%s%s%s", |
| 200 | formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorFgHiRedscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiRed.), |
| 201 | msg, |
| 202 | formatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/format().(ColorResetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorReset.), |
| 203 | ) |
| 204 | } |
| 205 | return msg |
| 206 | } |
| 207 | |
| 208 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) removeLeftSideNewLineCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#removeLeftSideNewLineChar().(src string) string { |
| 209 | return stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimLeftscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimLeft().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimLeftscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimLeft().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimLeftscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimLeft().(src, "\r"), "\n"), "\r\n") |
| 210 | } |
| 211 | |
| 212 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) removeRightSideNewLineCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#removeRightSideNewLineChar().(src string) string { |
| 213 | return stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimRightscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimRight().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimRightscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimRight().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimRightscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimRight().(src, "\r"), "\n"), "\r\n") |
| 214 | } |
| 215 | |
| 216 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) removeRightSideWhiteSpaceCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#removeRightSideWhiteSpaceChar().(src string) string { |
| 217 | return p.removeRightSideNewLineCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#removeRightSideNewLineChar().(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimRightscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimRight().(src, " ")) |
| 218 | } |
| 219 | |
| 220 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) newLineCountscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#newLineCount().(s string) int { |
| 221 | src := []rune(s) |
| 222 | size := len(src) |
| 223 | cnt := 0 |
| 224 | for i := 0; i < size; i++ { |
| 225 | c := src[i] |
| 226 | switch c { |
| 227 | case '\r': |
| 228 | if i+1 < size && src[i+1] == '\n' { |
| 229 | i++ |
| 230 | } |
| 231 | cnt++ |
| 232 | case '\n': |
| 233 | cnt++ |
| 234 | } |
| 235 | } |
| 236 | return cnt |
| 237 | } |
| 238 | |
| 239 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) isNewLineLastCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#isNewLineLastChar().(s string) bool { |
| 240 | for i := len(s) - 1; i > 0; i-- { |
| 241 | c := s[i] |
| 242 | switch c { |
| 243 | case ' ': |
| 244 | continue |
| 245 | case '\n', '\r': |
| 246 | return true |
| 247 | } |
| 248 | break |
| 249 | } |
| 250 | return false |
| 251 | } |
| 252 | |
| 253 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) printBeforeTokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#printBeforeTokens().(tk *tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#, minLine, extLine int) tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens# { |
| 254 | for tk.Prevscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Prev. != nil { |
| 255 | if tk.Prevscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Prev..Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Position..Linescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Position#Line. < minLine { |
| 256 | break |
| 257 | } |
| 258 | tk = tk.Prevscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Prev. |
| 259 | } |
| 260 | minTk := tk.Clonescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Clone().() |
| 261 | if minTk.Prevscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Prev. != nil { |
| 262 | // add white spaces to minTk by prev token |
| 263 | prev := minTk.Prevscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Prev. |
| 264 | whiteSpaceLen := len(prev.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin.) - len(stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.TrimRightscip-go gomod github.com/golang/go/src go1.21.0 strings/TrimRight().(prev.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin., " ")) |
| 265 | minTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin. = stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21.0 strings/Repeat().(" ", whiteSpaceLen) + minTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin. |
| 266 | } |
| 267 | minTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin. = p.removeLeftSideNewLineCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#removeLeftSideNewLineChar().(minTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin.) |
| 268 | tokens := tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#{minTk} |
| 269 | tk = minTk.Nextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Next. |
| 270 | for tk != nil && tk.Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Position..Linescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Position#Line. <= extLine { |
| 271 | clonedTk := tk.Clonescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Clone().() |
| 272 | tokens.Addscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#Add().(clonedTk) |
| 273 | tk = clonedTk.Nextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Next. |
| 274 | } |
| 275 | lastTk := tokens[len(tokens)-1] |
| 276 | trimmedOrigin := p.removeRightSideWhiteSpaceCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#removeRightSideWhiteSpaceChar().(lastTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin.) |
| 277 | suffix := lastTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin.[len(trimmedOrigin):] |
| 278 | lastTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin. = trimmedOrigin |
| 279 | |
| 280 | if lastTk.Nextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Next. != nil && len(suffix) > 1 { |
| 281 | next := lastTk.Nextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Next..Clonescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Clone().() |
| 282 | // add suffix to header of next token |
| 283 | if suffix[0] == '\n' || suffix[0] == '\r' { |
| 284 | suffix = suffix[1:] |
| 285 | } |
| 286 | next.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin. = suffix + next.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin. |
| 287 | lastTk.Nextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Next. = next |
| 288 | } |
| 289 | return tokens |
| 290 | } |
| 291 | |
| 292 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) printAfterTokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#printAfterTokens().(tk *tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#, maxLine int) tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens# { |
| 293 | tokens := tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#{} |
| 294 | if tk == nil { |
| 295 | return tokens |
| 296 | } |
| 297 | if tk.Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Position..Linescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Position#Line. > maxLine { |
| 298 | return tokens |
| 299 | } |
| 300 | minTk := tk.Clonescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Clone().() |
| 301 | minTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin. = p.removeLeftSideNewLineCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#removeLeftSideNewLineChar().(minTk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin.) |
| 302 | tokens.Addscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#Add().(minTk) |
| 303 | tk = minTk.Nextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Next. |
| 304 | for tk != nil && tk.Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Position..Linescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Position#Line. <= maxLine { |
| 305 | clonedTk := tk.Clonescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Clone().() |
| 306 | tokens.Addscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Tokens#Add().(clonedTk) |
| 307 | tk = clonedTk.Nextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Next. |
| 308 | } |
| 309 | return tokens |
| 310 | } |
| 311 | |
| 312 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) setupErrorTokenFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#setupErrorTokenFormat().(annotateLine int, isColored bool) { |
| 313 | prefix := func(annotateLine, num int) string { |
| 314 | if annotateLine == num { |
| 315 | return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("> %2d | ", num) |
| 316 | } |
| 317 | return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().(" %2d | ", num) |
| 318 | } |
| 319 | p.LineNumberscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumber. = true |
| 320 | p.LineNumberFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#LineNumberFormat. = func(num int) string { |
| 321 | if isColored { |
| 322 | return colorizescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/colorize().(prefix(annotateLine, num), ColorBoldscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorBold., ColorFgHiWhitescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/ColorFgHiWhite.) |
| 323 | } |
| 324 | return prefix(annotateLine, num) |
| 325 | } |
| 326 | if isColored { |
| 327 | p.setDefaultColorSetscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#setDefaultColorSet().() |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | func (p *Printerscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#) PrintErrorTokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintErrorToken().(tk *tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/.Tokenscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#, isColored bool) string { |
| 332 | errToken := tk |
| 333 | curLine := tk.Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Position..Linescip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Position#Line. |
| 334 | curExtLine := curLine + p.newLineCountscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#newLineCount().(p.removeLeftSideNewLineCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#removeLeftSideNewLineChar().(tk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin.)) |
| 335 | if p.isNewLineLastCharscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#isNewLineLastChar().(tk.Originscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Origin.) { |
| 336 | // if last character ( exclude white space ) is new line character, ignore it. |
| 337 | curExtLine-- |
| 338 | } |
| 339 | |
| 340 | minLine := int(mathscip-go gomod github.com/golang/go/src go1.21.0 math/.Maxscip-go gomod github.com/golang/go/src go1.21.0 math/Max().(float64(curLine-3), 1)) |
| 341 | maxLine := curExtLine + 3 |
| 342 | p.setupErrorTokenFormatscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#setupErrorTokenFormat().(curLine, isColored) |
| 343 | |
| 344 | beforeTokens := p.printBeforeTokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#printBeforeTokens().(tk, minLine, curExtLine) |
| 345 | lastTk := beforeTokens[len(beforeTokens)-1] |
| 346 | afterTokens := p.printAfterTokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#printAfterTokens().(lastTk.Nextscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Next., maxLine) |
| 347 | |
| 348 | beforeSource := p.PrintTokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintTokens().(beforeTokens) |
| 349 | prefixSpaceNum := len(fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().(" %2d | ", curLine)) |
| 350 | annotateLine := stringsscip-go gomod github.com/golang/go/src go1.21.0 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21.0 strings/Repeat().(" ", prefixSpaceNum+errToken.Positionscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Token#Position..Columnscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/token`/Position#Column.-1) + "^" |
| 351 | afterSource := p.PrintTokensscip-go gomod github.com/goccy/go-yaml . `github.com/goccy/go-yaml/printer`/Printer#PrintTokens().(afterTokens) |
| 352 | return fmtscip-go gomod github.com/golang/go/src go1.21.0 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.21.0 fmt/Sprintf().("%s\n%s\n%s", beforeSource, annotateLine, afterSource) |
| 353 | } |