Skip to content

Commit

Permalink
Unexports statements add/addFull methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tomnomnom committed Sep 9, 2016
1 parent ca66db9 commit cfade78
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func ungron(r io.Reader, w io.Writer, opts int) (int, error) {
var ss statements
for scanner.Scan() {
s := statementFromString(scanner.Text())
ss.AddFull(s)
ss.addFull(s)
}
if err := scanner.Err(); err != nil {
return exitReadInput, fmt.Errorf("failed to read input statements")
Expand Down
18 changes: 13 additions & 5 deletions statements.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (s statement) String() string {
return strings.Join(out, "")
}

// colorString returns the string form of a statement with ASCII color codes
func (s statement) colorString() string {
out := make([]string, 0, len(s)+2)
for _, t := range s {
Expand All @@ -32,6 +33,8 @@ func (s statement) colorString() string {
return strings.Join(out, "")
}

// withBare returns a copy of a statement with a new bare
// word token appended to it
func (s statement) withBare(k string) statement {
return append(
s,
Expand All @@ -40,6 +43,8 @@ func (s statement) withBare(k string) statement {
)
}

// withQuotedKey returns a copy of a statement with a new
// quoted key token appended to it
func (s statement) withQuotedKey(k string) statement {
return append(
s,
Expand All @@ -49,6 +54,8 @@ func (s statement) withQuotedKey(k string) statement {
)
}

// withNumericKey returns a copy of a statement with a new
// numeric key token appended to it
func (s statement) withNumericKey(k int) statement {
return append(s,
token{"[", typLBrace},
Expand All @@ -61,14 +68,15 @@ func (s statement) withNumericKey(k int) statement {
// E.g statement: json.foo = "bar";
type statements []statement

// Add makes a copy of a statement and appends it to the list of statements
func (ss *statements) Add(s statement, new token) {
// add takes a statement representing a path and a value token and appends
// it to the list of statements as a complete assignment
func (ss *statements) add(s statement, new token) {
add := append(s, token{"=", typEquals}, new, token{";", typSemi})
*ss = append(*ss, add)
}

// AddFull adds a new statement to the list given the entire statement
func (ss *statements) AddFull(s statement) {
// addFull appends a new complete statement to list of statements
func (ss *statements) addFull(s statement) {
*ss = append(*ss, s)
}

Expand Down Expand Up @@ -218,7 +226,7 @@ func statementsFromJSON(r io.Reader) (statements, error) {
func (ss *statements) fill(prefix statement, v interface{}) {

// Add a statement for the current prefix and value
ss.Add(prefix, valueTokenFromInterface(v))
ss.add(prefix, valueTokenFromInterface(v))

// Recurse into objects and arrays
switch vv := v.(type) {
Expand Down

0 comments on commit cfade78

Please sign in to comment.