Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 69ec501

Browse files
committed
renaming tables to sections and adding more docs
1 parent ca8198f commit 69ec501

File tree

9 files changed

+70
-60
lines changed

9 files changed

+70
-60
lines changed

aws/session/internal/ini/ast.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ const (
1010
ASTKindExpr
1111
ASTKindStatement
1212
ASTKindExprStatement
13-
ASTKindNestedTableStatement
14-
ASTKindCompletedNestedTableStatement
13+
ASTKindNestedSectionStatement
14+
ASTKindCompletedNestedSectionStatement
1515
ASTKindCommentStatement
1616
)
1717

@@ -27,8 +27,8 @@ func (k ASTKind) String() string {
2727
return "stmt"
2828
case ASTKindExprStatement:
2929
return "expr_stmt"
30-
case ASTKindNestedTableStatement:
31-
return "nested_table_stmt"
30+
case ASTKindNestedSectionStatement:
31+
return "nested_section_stmt"
3232
default:
3333
return ""
3434
}

aws/session/internal/ini/comment_token.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ type CommentToken struct {
77
comment string
88
}
99

10+
// isComment will return whether or not the next byte(s) is a
11+
// comment.
1012
func isComment(b []byte) bool {
1113
if len(b) == 0 {
1214
return false
@@ -26,6 +28,8 @@ func isComment(b []byte) bool {
2628
return false
2729
}
2830

31+
// newCommentToken will create a comment token and
32+
// return how many bytes were read.
2933
func newCommentToken(b []byte) (CommentToken, int, error) {
3034
i := 0
3135
value := ""

aws/session/internal/ini/ini.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import (
44
"os"
55
)
66

7-
func OpenFile(path string) (Tables, error) {
7+
// OpenFile takes a path to a given file, and will open and parse
8+
// that file.
9+
func OpenFile(path string) (Sections, error) {
810
f, err := os.Open(path)
911
if err != nil {
1012
return nil, err
@@ -14,7 +16,9 @@ func OpenFile(path string) (Tables, error) {
1416
return ParseFile(f)
1517
}
1618

17-
func ParseFile(f *os.File) (Tables, error) {
19+
// ParseFile will parse the given file using the shared config
20+
// visitor.
21+
func ParseFile(f *os.File) (Sections, error) {
1822
tree, err := Parse(f)
1923
if err != nil {
2024
return nil, err
@@ -25,5 +29,5 @@ func ParseFile(f *os.File) (Tables, error) {
2529
return nil, err
2630
}
2731

28-
return v.Tables, nil
32+
return v.Sections, nil
2933
}

aws/session/internal/ini/ini_parser.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ var parseTable = map[ASTKind]map[tokenType]int{
6161
tokenNL: -1,
6262
tokenComment: 11, // comment -> #comment' | ;comment' | /comment_slash
6363
},
64-
ASTKindNestedTableStatement: map[tokenType]int{
64+
ASTKindNestedSectionStatement: map[tokenType]int{
6565
tokenLit: 7, // table_nested -> label nested_array_close
6666
tokenSep: 8, // nested_array_close -> ] array_close
6767
tokenWS: -1,
6868
tokenNL: -1,
6969
tokenComment: 11, // comment -> #comment' | ;comment' | /comment_slash
7070
},
71-
ASTKindCompletedNestedTableStatement: map[tokenType]int{
71+
ASTKindCompletedNestedSectionStatement: map[tokenType]int{
7272
tokenSep: 9, // nested_array_close -> ] epsilon
7373
tokenWS: -1,
7474
tokenNL: -1,
@@ -173,28 +173,28 @@ func Parse(r io.Reader) ([]AST, error) {
173173

174174
var stmt AST
175175

176-
if t, ok := k.(TableStatement); ok {
176+
if t, ok := k.(SectionStatement); ok {
177177
t.Name = strings.Join([]string{t.Name, tok.Raw()}, " ")
178178
stmt = t
179179
} else {
180-
stmt = newTableStatement(tok)
180+
stmt = newSectionStatement(tok)
181181
}
182182
stack.Push(stmt)
183183
case 6:
184184
if tok.Raw() == "]" {
185185
stack.Epsilon(k)
186186
} else if tok.Raw() == "[" {
187-
stmt := newNestedTableStatement()
187+
stmt := newNestedSectionStatement()
188188
stack.Push(stmt)
189189
} else {
190190
return stack.list, awserr.New(ErrCodeParseError, "expected ']'", nil)
191191
}
192192
case 7:
193193
switch tok.Type() {
194194
case tokenLit:
195-
stmt, ok := k.(NestedTableStatement)
195+
stmt, ok := k.(NestedSectionStatement)
196196
if !ok {
197-
return stack.list, awserr.New(ErrCodeParseError, "expected nested table statement", nil)
197+
return stack.list, awserr.New(ErrCodeParseError, "expected nested section statement", nil)
198198
}
199199

200200
stmt.Labels = append(stmt.Labels, tok.Raw())
@@ -207,7 +207,7 @@ func Parse(r io.Reader) ([]AST, error) {
207207
return stack.list, awserr.New(ErrCodeParseError, "expected closing bracket", nil)
208208
}
209209

210-
stmt := newCompletedNestedTableStatement(k)
210+
stmt := newCompletedNestedSectionStatement(k)
211211
stack.Push(stmt)
212212
case 9:
213213
if tok.Raw() != "]" {

aws/session/internal/ini/ini_parser_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,20 @@ func TestParser(t *testing.T) {
8282
{
8383
r: bytes.NewBuffer([]byte(`[ default ]`)),
8484
expectedStack: []AST{
85-
newTableStatement(defaultId),
85+
newSectionStatement(defaultId),
8686
},
8787
},
8888
{
8989
r: bytes.NewBuffer([]byte(`[default]`)),
9090
expectedStack: []AST{
91-
newTableStatement(defaultId),
91+
newSectionStatement(defaultId),
9292
},
9393
},
9494
{
9595
r: bytes.NewBuffer([]byte(`[default]
9696
region="us-west-2"`)),
9797
expectedStack: []AST{
98-
newTableStatement(defaultId),
98+
newSectionStatement(defaultId),
9999
newExprStatement(EqualExpr{
100100
Left: newExpression(regionId),
101101
Root: equalOp,
@@ -114,7 +114,7 @@ output = json
114114
region = us-west-2
115115
`)),
116116
expectedStack: []AST{
117-
newTableStatement(defaultId),
117+
newSectionStatement(defaultId),
118118
newExprStatement(EqualExpr{
119119
Left: newExpression(regionId),
120120
Root: equalOp,
@@ -130,7 +130,7 @@ region = us-west-2
130130
Root: equalOp,
131131
Right: newExpression(outputLit),
132132
}),
133-
newTableStatement(assumeId),
133+
newSectionStatement(assumeId),
134134
newExprStatement(EqualExpr{
135135
Left: newExpression(outputId),
136136
Root: equalOp,
@@ -157,7 +157,7 @@ output = json
157157
region = us-west-2
158158
`)),
159159
expectedStack: []AST{
160-
newTableStatement(defaultId),
160+
newSectionStatement(defaultId),
161161
newExprStatement(EqualExpr{
162162
Left: newExpression(regionId),
163163
Root: equalOp,
@@ -173,7 +173,7 @@ region = us-west-2
173173
Root: equalOp,
174174
Right: newExpression(outputLit),
175175
}),
176-
newTableStatement(assumeId),
176+
newSectionStatement(assumeId),
177177
newExprStatement(EqualExpr{
178178
Left: newExpression(outputId),
179179
Root: equalOp,
@@ -200,7 +200,7 @@ output = json
200200
region = us-west-2
201201
`)),
202202
expectedStack: []AST{
203-
newTableStatement(defaultId),
203+
newSectionStatement(defaultId),
204204
newExprStatement(EqualExpr{
205205
Left: newExpression(regionId),
206206
Root: equalOp,
@@ -216,7 +216,7 @@ region = us-west-2
216216
Root: equalOp,
217217
Right: newExpression(outputLit),
218218
}),
219-
newTableStatement(assumeId),
219+
newSectionStatement(assumeId),
220220
newExprStatement(EqualExpr{
221221
Left: newExpression(outputId),
222222
Root: equalOp,

aws/session/internal/ini/statement.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ func (stmt Statement) Kind() ASTKind {
1212
return ASTKindStatement
1313
}
1414

15-
type TableStatement struct {
15+
type SectionStatement struct {
1616
Name string
1717
}
1818

19-
func newTableStatement(tok iniToken) TableStatement {
20-
return TableStatement{
19+
func newSectionStatement(tok iniToken) SectionStatement {
20+
return SectionStatement{
2121
Name: tok.Raw(),
2222
}
2323
}
2424

25-
func (stmt TableStatement) Kind() ASTKind {
25+
func (stmt SectionStatement) Kind() ASTKind {
2626
return ASTKindStatement
2727
}
2828

29-
func (stmt TableStatement) String() string {
29+
func (stmt SectionStatement) String() string {
3030
return fmt.Sprintf("{%s}", stmt.Name)
3131
}
3232

@@ -48,40 +48,40 @@ func (stmt ExprStatement) String() string {
4848
return fmt.Sprintf("{%v}", stmt.V)
4949
}
5050

51-
type NestedTableStatement struct {
51+
type NestedSectionStatement struct {
5252
Labels []string
5353
kind ASTKind
5454
}
5555

56-
func newNestedTableStatement() NestedTableStatement {
57-
return NestedTableStatement{
58-
kind: ASTKindNestedTableStatement,
56+
func newNestedSectionStatement() NestedSectionStatement {
57+
return NestedSectionStatement{
58+
kind: ASTKindNestedSectionStatement,
5959
}
6060
}
6161

62-
func (stmt NestedTableStatement) Kind() ASTKind {
63-
return ASTKindNestedTableStatement
62+
func (stmt NestedSectionStatement) Kind() ASTKind {
63+
return ASTKindNestedSectionStatement
6464
}
6565

66-
func (stmt NestedTableStatement) String() string {
66+
func (stmt NestedSectionStatement) String() string {
6767
return fmt.Sprintf("{[[ %v ]]}", stmt.Labels)
6868
}
6969

70-
type CompletedNestedTableStatement struct {
70+
type CompletedNestedSectionStatement struct {
7171
Root AST
7272
}
7373

74-
func newCompletedNestedTableStatement(k AST) CompletedNestedTableStatement {
75-
return CompletedNestedTableStatement{
74+
func newCompletedNestedSectionStatement(k AST) CompletedNestedSectionStatement {
75+
return CompletedNestedSectionStatement{
7676
Root: k,
7777
}
7878
}
7979

80-
func (stmt CompletedNestedTableStatement) Kind() ASTKind {
81-
return ASTKindCompletedNestedTableStatement
80+
func (stmt CompletedNestedSectionStatement) Kind() ASTKind {
81+
return ASTKindCompletedNestedSectionStatement
8282
}
8383

84-
func (stmt CompletedNestedTableStatement) String() string {
84+
func (stmt CompletedNestedSectionStatement) String() string {
8585
return fmt.Sprintf("{[[ %v ]]}", stmt.Root)
8686
}
8787

aws/session/internal/ini/visitor.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,48 @@ import (
66
"github.com/aws/aws-sdk-go/aws/awserr"
77
)
88

9+
// Visitor is an interface used by walkers that will
10+
// traverse an array of ASTs.
911
type Visitor interface {
1012
VisitExpr(AST) error
1113
VisitStatement(AST) error
1214
}
1315

14-
type Tables map[string]Table
16+
type Sections map[string]Section
1517

1618
type SharedConfigVisitor struct {
17-
scope string
18-
Tables Tables
19+
scope string
20+
Sections Sections
1921
}
2022

2123
func NewSharedConfigVisitor() *SharedConfigVisitor {
2224
return &SharedConfigVisitor{
23-
Tables: Tables{},
25+
Sections: Sections{},
2426
}
2527
}
2628

27-
func (t Tables) GetSection(p string) (Table, bool) {
28-
tables := map[string]Table(t)
29-
v, ok := tables[p]
29+
func (t Sections) GetSection(p string) (Section, bool) {
30+
sections := map[string]Section(t)
31+
v, ok := sections[p]
3032
return v, ok
3133
}
3234

3335
type Values map[string]iniToken
3436

35-
type Table struct {
37+
type Section struct {
3638
Name string
3739
Values Values
3840
}
3941

40-
func (t Table) Int(k string) int64 {
42+
func (t Section) Int(k string) int64 {
4143
return t.Values[k].IntValue()
4244
}
4345

44-
func (t Table) Float64(k string) float64 {
46+
func (t Section) Float64(k string) float64 {
4547
return t.Values[k].FloatValue()
4648
}
4749

48-
func (t Table) String(k string) string {
50+
func (t Section) String(k string) string {
4951
_, ok := t.Values[k]
5052
if !ok {
5153
return ""
@@ -54,7 +56,7 @@ func (t Table) String(k string) string {
5456
}
5557

5658
func (v *SharedConfigVisitor) VisitExpr(expr AST) error {
57-
t := v.Tables[v.scope]
59+
t := v.Sections[v.scope]
5860
if t.Values == nil {
5961
t.Values = Values{}
6062
}
@@ -69,14 +71,14 @@ func (v *SharedConfigVisitor) VisitExpr(expr AST) error {
6971
return awserr.New(ErrCodeParseError, "unsupported expression", nil)
7072
}
7173

72-
v.Tables[v.scope] = t
74+
v.Sections[v.scope] = t
7375
return nil
7476
}
7577

7678
func (v *SharedConfigVisitor) VisitStatement(stmt AST) error {
7779
switch s := stmt.(type) {
78-
case TableStatement:
79-
v.Tables[s.Name] = Table{}
80+
case SectionStatement:
81+
v.Sections[s.Name] = Section{}
8082
v.scope = s.Name
8183
default:
8284
return awserr.New(ErrCodeParseError, fmt.Sprintf("unsupported statement: %T", s), nil)

aws/session/internal/ini/walker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ func Walk(tree []AST, v Visitor) error {
1010
return err
1111
}
1212
case ASTKindStatement,
13-
ASTKindNestedTableStatement,
14-
ASTKindCompletedNestedTableStatement:
13+
ASTKindNestedSectionStatement,
14+
ASTKindCompletedNestedSectionStatement:
1515

1616
if err := v.VisitStatement(node); err != nil {
1717
return err

aws/session/internal/ini/walker_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func TestDataFiles(t *testing.T) {
111111
}
112112

113113
for profile, tableIface := range e {
114-
p, ok := v.Tables.GetSection(profile)
114+
p, ok := v.Sections.GetSection(profile)
115115
if !ok {
116116
t.Fatal("could not find profile " + profile)
117117
}

0 commit comments

Comments
 (0)