Skip to content

Commit

Permalink
Undid struct naming that pushed stuff to be public
Browse files Browse the repository at this point in the history
  • Loading branch information
rkrishnasanka committed Jul 12, 2024
1 parent 593ae9b commit 12fb92c
Show file tree
Hide file tree
Showing 29 changed files with 201 additions and 201 deletions.
12 changes: 6 additions & 6 deletions cmd/cmd_seed.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,13 @@ func graphQLFunc(gj *core.GraphJin, query string, data interface{}, opt map[stri
return val
}

type CSVSource struct {
type csvSource struct {
rows [][]string
i int
}

// NewCSVSource creates a new CSV source
func NewCSVSource(filename string, sep rune) (*CSVSource, error) {
func NewCSVSource(filename string, sep rune) (*csvSource, error) {
f, err := os.Open(filename)
if err != nil {
return nil, err
Expand All @@ -238,14 +238,14 @@ func NewCSVSource(filename string, sep rune) (*CSVSource, error) {
return nil, err
}

return &CSVSource{rows: rows}, nil
return &csvSource{rows: rows}, nil
}

func (c *CSVSource) Next() bool {
func (c *csvSource) Next() bool {
return c.i < len(c.rows)
}

func (c *CSVSource) Values() ([]interface{}, error) {
func (c *csvSource) Values() ([]interface{}, error) {
var vals []interface{}
var err error

Expand Down Expand Up @@ -286,7 +286,7 @@ func isDigit(v string) bool {
return true
}

func (c *CSVSource) Err() error {
func (c *csvSource) Err() error {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"gopkg.in/yaml.v3"
)

type ConfigInfo struct {
type configInfo struct {
Inherits string
}

Expand All @@ -25,7 +25,7 @@ func NewConfig(configPath, configFile string) (c *core.Config, err error) {
// NewConfigWithFS creates a new config object using the provided filesystem
func NewConfigWithFS(fs core.FS, configFile string) (c *core.Config, err error) {
c = &core.Config{FS: fs}
var ci ConfigInfo
var ci configInfo

if err = readConfig(fs, configFile, &ci); err != nil {
return
Expand Down
64 changes: 32 additions & 32 deletions core/internal/graph/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ var (
// this template was parsed.
type Pos int

// Item represents a token or text string returned from the scanner.
type Item struct {
// item represents a token or text string returned from the scanner.
type item struct {
_type MType // The type of this item.
pos Pos // The starting position, in bytes, of this item in the input string.
val []byte // The value of this item.
Expand Down Expand Up @@ -80,29 +80,29 @@ var punctuators = map[rune]MType{
const eof = -1

// StateFn represents the state of the scanner as a function that returns the next state.
type StateFn func(*Lexer) StateFn
type StateFn func(*lexer) StateFn

// Lexer holds the state of the scanner.
type Lexer struct {
// lexer holds the state of the scanner.
type lexer struct {
input []byte // the string being scanned
pos Pos // current position in the input
start Pos // start position of this item
width Pos // width of last rune read from input
items []Item // array of scanned items
itemsA [50]Item
items []item // array of scanned items
itemsA [50]item
line int16 // 1+number of newlines seen
err error
}

var zeroLex = Lexer{}
var zeroLex = lexer{}

// Reset resets the lexer to scan a new input string.
func (l *Lexer) Reset() {
func (l *lexer) Reset() {
*l = zeroLex
}

// next returns the next byte in the input.
func (l *Lexer) next() rune {
func (l *lexer) next() rune {
if int(l.pos) >= len(l.input) {
l.width = 0
return eof
Expand All @@ -117,14 +117,14 @@ func (l *Lexer) next() rune {
}

// peek returns but does not consume the next rune in the input.
func (l *Lexer) peek() rune {
func (l *lexer) peek() rune {
r := l.next()
l.backup()
return r
}

// backup steps back one rune. Can only be called once per call of next.
func (l *Lexer) backup() {
func (l *lexer) backup() {
if l.pos != 0 {
l.pos -= l.width
// Correct newline count.
Expand All @@ -135,13 +135,13 @@ func (l *Lexer) backup() {
}

// current returns the current bytes of the input.
func (l *Lexer) current() []byte {
func (l *lexer) current() []byte {
return l.input[l.start:l.pos]
}

// emit passes an item back to the client.
func (l *Lexer) emit(t MType) {
l.items = append(l.items, Item{t, l.start, l.current(), l.line})
func (l *lexer) emit(t MType) {
l.items = append(l.items, item{t, l.start, l.current(), l.line})
// Some items contain text internally. If so, count their newlines.
if t == itemStringVal {
for i := l.start; i < l.pos; i++ {
Expand All @@ -154,18 +154,18 @@ func (l *Lexer) emit(t MType) {
}

// emitL passes an item back to the client and lowercases the value.
func (l *Lexer) emitL(t MType) {
func (l *lexer) emitL(t MType) {
lowercase(l.current())
l.emit(t)
}

// ignore skips over the pending input before this point.
func (l *Lexer) ignore() {
func (l *lexer) ignore() {
l.start = l.pos
}

// accept consumes the next rune if it's from the valid set.
func (l *Lexer) accept(valid []byte) (rune, bool) {
func (l *lexer) accept(valid []byte) (rune, bool) {
r := l.next()
if r != eof && bytes.ContainsRune(valid, r) {
return r, true
Expand All @@ -175,7 +175,7 @@ func (l *Lexer) accept(valid []byte) (rune, bool) {
}

// acceptAlphaNum consumes a run of runes while they are alpha nums
func (l *Lexer) acceptAlphaNum() bool {
func (l *lexer) acceptAlphaNum() bool {
n := 0
for r := l.next(); isAlphaNumeric(r); r = l.next() {
n++
Expand All @@ -185,15 +185,15 @@ func (l *Lexer) acceptAlphaNum() bool {
}

// acceptComment consumes a run of runes while till the end of line
func (l *Lexer) acceptComment() {
func (l *lexer) acceptComment() {
n := 0
for r := l.next(); !isEndOfLine(r); r = l.next() {
n++
}
}

// acceptRun consumes a run of runes from the valid set.
func (l *Lexer) acceptRun(valid []byte) {
func (l *lexer) acceptRun(valid []byte) {
for bytes.ContainsRune(valid, l.next()) {

}
Expand All @@ -202,15 +202,15 @@ func (l *Lexer) acceptRun(valid []byte) {

// errorf returns an error token and terminates the scan by passing
// back a nil pointer that will be the next state, terminating l.nextItem.
func (l *Lexer) errorf(format string, args ...interface{}) StateFn {
func (l *lexer) errorf(format string, args ...interface{}) StateFn {
l.err = fmt.Errorf(format, args...)
l.items = append(l.items, Item{itemError, l.start, l.input[l.start:l.pos], l.line})
l.items = append(l.items, item{itemError, l.start, l.input[l.start:l.pos], l.line})
return nil
}

// lex creates a new scanner for the input string.
func lex(input []byte) (Lexer, error) {
var l Lexer
func lex(input []byte) (lexer, error) {
var l lexer

if len(input) == 0 {
return l, errors.New("empty query")
Expand All @@ -229,14 +229,14 @@ func lex(input []byte) (Lexer, error) {
}

// run runs the state machine for the lexer.
func (l *Lexer) run() {
func (l *lexer) run() {
for state := lexRoot; state != nil; {
state = state(l)
}
}

// lexInsideAction scans the elements inside action delimiters.
func lexRoot(l *Lexer) StateFn {
func lexRoot(l *lexer) StateFn {
r := l.next()

switch {
Expand Down Expand Up @@ -290,7 +290,7 @@ func lexRoot(l *Lexer) StateFn {
}

// lexName scans a name.
func lexName(l *Lexer) StateFn {
func lexName(l *lexer) StateFn {
for {
r := l.next()

Expand Down Expand Up @@ -320,7 +320,7 @@ func lexName(l *Lexer) StateFn {
}

// lexString scans a string.
func lexString(l *Lexer) StateFn {
func lexString(l *lexer) StateFn {
if sr, ok := l.accept([]byte(quotesToken)); ok {
l.ignore()

Expand Down Expand Up @@ -354,7 +354,7 @@ func lexString(l *Lexer) StateFn {
// lexNumber scans a number: decimal and float. This isn't a perfect number scanner
// for instance it accepts "." and "0x0.2" and "089" - but when it's wrong the input
// is invalid and the parser (via strconv) should notice.
func lexNumber(l *Lexer) StateFn {
func lexNumber(l *lexer) StateFn {
if !l.scanNumber() {
return l.errorf("bad number syntax: %q", l.input[l.start:l.pos])
}
Expand All @@ -363,7 +363,7 @@ func lexNumber(l *Lexer) StateFn {
}

// scanNumber scans a number: decimal and float.
func (l *Lexer) scanNumber() bool {
func (l *lexer) scanNumber() bool {
// Optional leading sign.
l.accept(signsToken)
l.acceptRun(digitToken)
Expand Down Expand Up @@ -415,7 +415,7 @@ func lowercase(b []byte) {
}

// String returns a string representation of the item.
func (i Item) String() string {
func (i item) String() string {
var v string

switch i._type {
Expand Down
16 changes: 8 additions & 8 deletions core/internal/graph/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ type Parser struct {
frags map[string]Fragment
input []byte // the string being scanned
pos int
items []Item
items []item
json bool
err error
}

func Parse(gql []byte) (op Operation, err error) {
var l Lexer
var l lexer

if len(gql) == 0 {
err = errors.New("empty query")
Expand Down Expand Up @@ -758,11 +758,11 @@ func (p *Parser) parseValue() (*Node, error) {
return node, nil
}

func (p *Parser) val(v Item) string {
func (p *Parser) val(v item) string {
return b2s(v.val)
}

func (p *Parser) vall(v Item) string {
func (p *Parser) vall(v item) string {
lowercase(v.val)
return b2s(v.val)
}
Expand Down Expand Up @@ -811,18 +811,18 @@ func (p *Parser) peekVal(values ...[]byte) bool {
return false
}

func (p *Parser) curr() Item {
func (p *Parser) curr() item {
if p.pos == -1 {
return Item{}
return item{}
}
return p.items[p.pos]
}

func (p *Parser) next() Item {
func (p *Parser) next() item {
n := p.pos + 1
if n >= len(p.items) {
p.err = errEOT
return Item{_type: itemEOF}
return item{_type: itemEOF}
}
p.pos = n
return p.items[p.pos]
Expand Down
2 changes: 1 addition & 1 deletion core/internal/graph/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type TField struct {
}

func ParseSchema(schema []byte) (s Schema, err error) {
var l Lexer
var l lexer

if len(schema) == 0 {
err = errors.New("empty schema")
Expand Down
Loading

0 comments on commit 12fb92c

Please sign in to comment.