Skip to content

Commit

Permalink
Generate stringer for tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
lebauce committed Jul 8, 2020
1 parent ac34145 commit 00c3682
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 76 deletions.
12 changes: 12 additions & 0 deletions .mk/stringer.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
STRINGER_FILES = $(patsubst %.go,%_string.go,$(shell git grep //go:generate | grep "stringer" | cut -d ":" -f 1))

%_string.go: %.go
go generate -run stringer $<

.PHONY: .stringer
.stringer: $(STRINGER_FILES)

.PHONY: .stringer.clean
.stringer.clean:
find . \( -name *_string.go ! -path './vendor/*' \) -exec rm {} \;

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ include .mk/static.mk
include .mk/tests.mk
include .mk/vppapi.mk
include .mk/swagger.mk
include .mk/stringer.mk

.DEFAULT_GOAL := all

Expand Down
96 changes: 96 additions & 0 deletions graffiti/graph/traversal/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//go:generate stringer -type=Token $GOFILE

/*
* Copyright (C) 2016 Red Hat, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy ofthe License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specificlanguage governing permissions and
* limitations under the License.
*
*/

package traversal

// Token represents a lexical token.
type Token int

// Default language token, extension token start at 1000
const (
// Special tokens
ILLEGAL Token = iota
EOF
WS

// Literals
IDENT

// Misc characters
COMMA
DOT
LEFTPARENTHESIS
RIGHTPARENTHESIS
STRING
NUMBER

// Keywords
G
V
E
HAS
HASKEY
HASNOT
HASEITHER
OUT
IN
OUTV
INV
BOTHV
OUTE
INE
BOTHE
DEDUP
WITHIN
WITHOUT
METADATA
SHORTESTPATHTO
NE
NEE
BOTH
CONTEXT
REGEX
LT
GT
LTE
GTE
INSIDE
OUTSIDE
BETWEEN
COUNT
RANGE
LIMIT
SORT
VALUES
KEYS
SUM
ASC
DESC
IPV4RANGE
SUBGRAPH
FOREVER
NOW
AS
SELECT

TRUE
FALSE

// extensions token have to start after 1000
)
16 changes: 16 additions & 0 deletions graffiti/graph/traversal/token_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 0 additions & 76 deletions graffiti/graph/traversal/traversal_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,82 +24,6 @@ import (
"strings"
)

// Token represents a lexical token.
type Token int

// Default language token, extension token start at 1000
const (
// Special tokens
ILLEGAL Token = iota
EOF
WS

// Literals
IDENT

// Misc characters
COMMA
DOT
LEFTPARENTHESIS
RIGHTPARENTHESIS
STRING
NUMBER

// Keywords
G
V
E
HAS
HASKEY
HASNOT
HASEITHER
OUT
IN
OUTV
INV
BOTHV
OUTE
INE
BOTHE
DEDUP
WITHIN
WITHOUT
METADATA
SHORTESTPATHTO
NE
NEE
BOTH
CONTEXT
REGEX
LT
GT
LTE
GTE
INSIDE
OUTSIDE
BETWEEN
COUNT
RANGE
LIMIT
SORT
VALUES
KEYS
SUM
ASC
DESC
IPV4RANGE
SUBGRAPH
FOREVER
NOW
AS
SELECT

TRUE
FALSE

// extensions token have to start after 1000
)

// GremlinTraversalScanner describes a buffer scanner for Gremlin expression extension
type GremlinTraversalScanner struct {
reader *bufio.Reader
Expand Down

0 comments on commit 00c3682

Please sign in to comment.