• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stephenafamo / bob / 14939098091

09 May 2025 10:59PM UTC coverage: 36.868% (-4.6%) from 41.506%
14939098091

push

github

stephenafamo
Move reusable sqlite parser components to antlrhelpers package

0 of 758 new or added lines in 12 files covered. (0.0%)

547 existing lines in 8 files now uncovered.

6533 of 17720 relevant lines covered (36.87%)

212.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/gen/bobgen-helpers/parser/antlrhelpers/functions.go
1
package antlrhelpers
2

3
import (
4
        "fmt"
5
        "strings"
6
)
7

8
type Functions map[string]Function
9

10
type Function struct {
11
        RequiredArgs         int
12
        Variadic             bool
13
        Args                 []string
14
        ReturnType           string
15
        CalcReturnType       func(...string) string // If present, will be used to calculate the return type
16
        ShouldArgsBeNullable bool
17
        CalcNullable         func(...func() bool) func() bool // will be provided with the nullability of the args
18
}
19

NEW
20
func (f Function) ArgType(i int) string {
×
NEW
21
        if i >= len(f.Args) {
×
NEW
22
                return f.Args[len(f.Args)-1]
×
NEW
23
        }
×
24

NEW
25
        return f.Args[i]
×
26
}
27

NEW
28
func GetFunctionType(functions Functions, funcName string, argTypes []string) (Function, error) {
×
NEW
29
        f, ok := functions[funcName]
×
NEW
30
        if !ok {
×
NEW
31
                return Function{}, fmt.Errorf("function %q not found", funcName)
×
NEW
32
        }
×
33

NEW
34
        if len(argTypes) < f.RequiredArgs {
×
NEW
35
                return Function{}, fmt.Errorf("too few arguments for function %q, %d/%d", funcName, len(argTypes), f.RequiredArgs)
×
NEW
36
        }
×
37

NEW
38
        if !f.Variadic && len(argTypes) > len(f.Args) {
×
NEW
39
                return Function{}, fmt.Errorf("too many arguments for function %q, %d/%d", funcName, len(argTypes), len(f.Args))
×
NEW
40
        }
×
41

NEW
42
        for i, arg := range argTypes {
×
NEW
43
                // We don't know the type of the given argument
×
NEW
44
                if arg == "" {
×
NEW
45
                        continue
×
46
                }
47

NEW
48
                argID := i
×
NEW
49
                if f.Variadic && i >= len(f.Args) {
×
NEW
50
                        argID = len(f.Args) - 1
×
NEW
51
                }
×
52

53
                // means the func can take any type in this position
NEW
54
                if f.Args[argID] == "" {
×
NEW
55
                        continue
×
56
                }
57

NEW
58
                if !strings.EqualFold(f.Args[argID], arg) {
×
NEW
59
                        return Function{}, fmt.Errorf("function %q(%s) expects %s at position %d, got %s", funcName, strings.Join(argTypes, ", "), f.Args[argID], i+1, arg)
×
NEW
60
                }
×
61
        }
62

NEW
63
        if f.CalcReturnType != nil {
×
NEW
64
                f.ReturnType = f.CalcReturnType(argTypes...)
×
NEW
65
        }
×
66

NEW
67
        return f, nil
×
68
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc