MCPcopy Create free account
hub / github.com/deroproject/derohe / parse_function_line

Function parse_function_line

dvm/dvm.go:171–281  ·  view source on GitHub ↗

this will parse 1 line at a time, if there is an error, it is returned

(SC *SmartContract, function **Function, line []string)

Source from the content-addressed store, hash-verified

169
170// this will parse 1 line at a time, if there is an error, it is returned
171func parse_function_line(SC *SmartContract, function **Function, line []string) (err error) {
172 pos := 0
173 //fmt.Printf("parsing function line %+v\n", line)
174
175 if *function == nil { //if no current function, only legal is Sub
176 if !strings.EqualFold(line[pos], "Function") {
177 return fmt.Errorf("Expecting declaration of function but found \"%s\"", line[0])
178 }
179 pos++
180
181 var f Function
182 f.Lines = map[uint64][]string{} // initialize line map
183 f.LinesNumberIndex = map[uint64]uint64{}
184
185 if len(line) < (pos + 1) {
186 return fmt.Errorf("function name missing")
187 }
188
189 if !check_valid_name(line[pos]) {
190 return fmt.Errorf("function name \"%s\" contains invalid characters", line[pos])
191 }
192 f.Name = line[pos]
193
194 pos++
195 if len(line) < (pos+1) || line[pos] != "(" {
196 return fmt.Errorf("function \"%s\" missing '('", f.Name)
197 }
198
199 parse_params: // now lets parse function params, but lets filter out ,
200 pos++
201 if len(line) < (pos + 1) {
202 return fmt.Errorf("function \"%s\" missing function parameters", f.Name)
203 }
204
205 if line[pos] == "," {
206 goto parse_params
207 }
208 if line[pos] == ")" {
209 // function does not have any parameters
210 // or all parameters have been parsed
211
212 } else { // we must parse param name, param type as pairs
213 if len(line) < (pos + 2) {
214 return fmt.Errorf("function \"%s\" missing function parameters", f.Name)
215 }
216
217 param_name := line[pos]
218 param_type := check_valid_type(line[pos+1])
219
220 if !check_valid_name(param_name) {
221 return fmt.Errorf("function name \"%s\", variable name \"%s\" contains invalid characters", f.Name, param_name)
222 }
223
224 if param_type == Invalid {
225 return fmt.Errorf("function name \"%s\", variable type \"%s\" is invalid", f.Name, line[pos+1])
226 }
227 f.Params = append(f.Params, Variable{Name: param_name, Type: param_type})
228

Callers 1

ParseSmartContractFunction · 0.85

Calls 2

check_valid_nameFunction · 0.85
check_valid_typeFunction · 0.85

Tested by

no test coverage detected