MCPcopy
hub / github.com/google/go-jsonnet / parseArguments

Method parseArguments

internal/parser/parser.go:117–170  ·  view source on GitHub ↗

TODO(sbarzowski) - this returned bool is weird

(elementKind string)

Source from the content-addressed store, hash-verified

115
116// TODO(sbarzowski) - this returned bool is weird
117func (p *parser) parseArguments(elementKind string) (*token, *ast.Arguments, bool, errors.StaticError) {
118 args := &ast.Arguments{}
119 gotComma := false
120 namedArgumentAdded := false
121 first := true
122 for {
123 commaFodder := ast.Fodder{}
124 next := p.peek()
125
126 if next.kind == tokenParenR {
127 // gotComma can be true or false here.
128 return p.pop(), args, gotComma, nil
129 }
130
131 if !first && !gotComma {
132 return nil, nil, false, errors.MakeStaticError(fmt.Sprintf("Expected a comma before next %s, got %s", elementKind, next), next.loc)
133 }
134
135 idFodder, id, eqFodder, expr, err := p.parseArgument()
136 if err != nil {
137 return nil, nil, false, err
138 }
139
140 if p.peek().kind == tokenComma {
141 comma := p.pop()
142 gotComma = true
143 commaFodder = comma.fodder
144 } else {
145 gotComma = false
146 }
147
148 if id == nil {
149 if namedArgumentAdded {
150 return nil, nil, false, errors.MakeStaticError("Positional argument after a named argument is not allowed", next.loc)
151 }
152 el := ast.CommaSeparatedExpr{Expr: expr}
153 if gotComma {
154 el.CommaFodder = commaFodder
155 }
156 args.Positional = append(args.Positional, el)
157 } else {
158 namedArgumentAdded = true
159 args.Named = append(args.Named, ast.NamedArgument{
160 NameFodder: idFodder,
161 Name: *id,
162 EqFodder: eqFodder,
163 Arg: expr,
164 CommaFodder: commaFodder,
165 })
166 }
167
168 first = false
169 }
170}
171
172// parseParameter parses either <f1> id <f2> = expr or just <f1> id.
173// It returns either (<f1>, id, <f2>, expr) or (<f1>, id, nil, nil)

Callers 1

parseMethod · 0.95

Calls 4

peekMethod · 0.95
popMethod · 0.95
parseArgumentMethod · 0.95
MakeStaticErrorFunction · 0.92

Tested by

no test coverage detected