package ini
Import Path
github.com/aws/aws-sdk-go/internal/ini (on go.dev)
Dependency Relation
imports 10 packages, and imported by 2 packages
Involved Source Files
ast.go
comma_token.go
comment_token.go
Package ini is an LL(1) parser for configuration files.
Example:
sections, err := ini.OpenFile("/path/to/file")
if err != nil {
panic(err)
}
profile := "foo"
section, ok := sections.GetSection(profile)
if !ok {
fmt.Printf("section %q could not be found", profile)
}
Below is the BNF that describes this parser
Grammar:
stmt -> value stmt'
stmt' -> epsilon | op stmt
value -> number | string | boolean | quoted_string
section -> [ section'
section' -> value section_close
section_close -> ]
SkipState will skip (NL WS)+
comment -> # comment' | ; comment'
comment' -> epsilon | value
empty_token.go
expression.go
ini.go
ini_lexer.go
ini_parser.go
literal_tokens.go
newline_token.go
number_helper.go
op_tokens.go
parse_error.go
parse_stack.go
sep_tokens.go
skipper.go
statement.go
value_util.go
visitor.go
walker.go
ws_token.go
Package-Level Type Names (total 17, in which 12 are exported)
AST interface allows us to determine what kind of node we
are on and casting may not need to be necessary.
The root is always the first node in Children
Children []AST
Kind ASTKind
Root Token
RootToken bool
AppendChild will append to the list of children an AST has.
GetChildren will return the current AST's list of children
GetRoot will return the root AST which can be the first entry
in the children list or a token.
SetChildren will set and override all children of the AST.
func ParseAST(r io.Reader) ([]AST, error)
func ParseASTBytes(b []byte) ([]AST, error)
func (*AST).GetChildren() []AST
func (*AST).GetRoot() AST
func ParseStack.List() []AST
func (*ParseStack).Pop() AST
func newAST(kind ASTKind, root AST, children ...AST) AST
func newASTWithRootToken(kind ASTKind, root Token, children ...AST) AST
func newCommentStatement(tok Token) AST
func newCompletedSectionStatement(ast AST) AST
func newEqualExpr(left AST, tok Token) AST
func newExpression(tok Token) AST
func newExprStatement(ast AST) AST
func newSectionStatement(tok Token) AST
func newSkipStatement(ast AST) AST
func newStatement() AST
func parse(tokens []Token) ([]AST, error)
func trimSpaces(k AST) AST
func EqualExprKey(ast AST) string
func Walk(tree []AST, v Visitor) error
func (*AST).AppendChild(child AST)
func (*AST).SetChildren(children []AST)
func (*DefaultVisitor).VisitExpr(expr AST) error
func (*DefaultVisitor).VisitStatement(stmt AST) error
func (*ParseStack).MarkComplete(ast AST)
func (*ParseStack).Push(ast AST)
func Visitor.VisitExpr(AST) error
func Visitor.VisitStatement(AST) error
func newAST(kind ASTKind, root AST, children ...AST) AST
func newAST(kind ASTKind, root AST, children ...AST) AST
func newASTWithRootToken(kind ASTKind, root Token, children ...AST) AST
func newCompletedSectionStatement(ast AST) AST
func newEqualExpr(left AST, tok Token) AST
func newExprStatement(ast AST) AST
func newSkipStatement(ast AST) AST
func trimSpaces(k AST) AST
var Start
ASTKind represents different states in the parse table
and the type of AST that is being constructed
( T) String() string
T : expvar.Var
T : fmt.Stringer
T : context.stringer
T : runtime.stringer
func newAST(kind ASTKind, root AST, children ...AST) AST
func newASTWithRootToken(kind ASTKind, root Token, children ...AST) AST
const ASTKindCommentStatement
const ASTKindCompletedNestedSectionStatement
const ASTKindCompletedSectionStatement
const ASTKindEqualExpr
const ASTKindExpr
const ASTKindExprStatement
const ASTKindNestedSectionStatement
const ASTKindNone
const ASTKindSectionStatement
const ASTKindSkipStatement
const ASTKindStart
const ASTKindStatement
DefaultVisitor is used to visit statements and expressions
and ensure that they are both of the correct format.
In addition, upon visiting this will build sections and populate
the Sections field which can be used to retrieve profile
configuration.
Sections Sections
scope string
VisitExpr visits expressions...
VisitStatement visits statements...
*T : Visitor
func NewDefaultVisitor() *DefaultVisitor
ParseError is an error which is returned during any part of
the parsing process.
msg string
Code will return the ErrCodeParseError
(*T) Error() string
Message returns the error's message
OrigError return nothing since there will never be any
original error.
*T : error
func NewParseError(message string) *ParseError
ParseStack is a stack that contains a container, the stack portion,
and the list which is the list of ASTs that have been successfully
parsed.
container []AST
index int
list []AST
top int
Len will return the length of the container
List will return the completed statements
MarkComplete will append the AST to the list of completed statements
Pop will return and truncate the last container element.
Push will add the new AST to the container
( T) String() string
T : expvar.Var
T : fmt.Stringer
*T : github.com/aws/aws-sdk-go/aws/corehandlers.lener
T : context.stringer
T : runtime.stringer
func newParseStack(sizeContainer, sizeList int) ParseStack
Section contains a name and values. This represent
a sectioned entry in a configuration file.
Name string
values values
Bool returns a bool value at k
Float64 returns a float value at k
Has will return whether or not an entry exists in a given section
Int returns an integer value at k
String returns the string value at k
ValueType will returned what type the union is set to. If
k was not found, the NoneType will be returned.
func Sections.GetSection(p string) (Section, bool)
func github.com/aws/aws-sdk-go/aws/session.updateBool(dst *bool, section Section, key string)
func github.com/aws/aws-sdk-go/aws/session.updateBoolPtr(dst **bool, section Section, key string)
func github.com/aws/aws-sdk-go/aws/session.updateString(dst *string, section Section, key string)
Sections is a map of Section structures that represent
a configuration.
container map[string]Section
GetSection will return section p. If section p does not exist,
false will be returned in the second parameter.
List will return a list of all sections that were successfully
parsed.
func OpenFile(path string) (Sections, error)
func Parse(f io.Reader) (Sections, error)
func ParseBytes(b []byte) (Sections, error)
Token indicates a metadata about a given value.
ValueType ValueType
base int
raw []rune
t TokenType
Raw return the raw runes that were consumed
Type returns the token type
func newCommaToken() Token
func newCommentToken(b []rune) (Token, int, error)
func newLitToken(b []rune) (Token, int, error)
func newNewlineToken(b []rune) (Token, int, error)
func newOpToken(b []rune) (Token, int, error)
func newSepToken(b []rune) (Token, int, error)
func newToken(t TokenType, raw []rune, v ValueType) Token
func newWSToken(b []rune) (Token, int, error)
func (*Value).Append(tok Token)
func newASTWithRootToken(kind ASTKind, root Token, children ...AST) AST
func newCommentStatement(tok Token) AST
func newEqualExpr(left AST, tok Token) AST
func newExpression(tok Token) AST
func newSectionStatement(tok Token) AST
func parse(tokens []Token) ([]AST, error)
var emptyToken
TokenType represents the various different tokens types
( T) String() string
T : expvar.Var
T : fmt.Stringer
T : context.stringer
T : runtime.stringer
func Token.Type() TokenType
func newToken(t TokenType, raw []rune, v ValueType) Token
const TokenComma
const TokenComment
const TokenLit
const TokenNL
const TokenNone
const TokenOp
const TokenSep
const TokenWS
Value is a union container
Type ValueType
boolean bool
decimal float64
integer int64
raw []rune
str string
Append will append values and change the type to a string
type.
BoolValue returns a bool value
FloatValue returns a float value
IntValue returns an integer value
( T) String() string
StringValue returns the string value
T : expvar.Var
T : fmt.Stringer
T : context.stringer
T : runtime.stringer
func newValue(t ValueType, base int, raw []rune) (Value, error)
var emptyValue
ValueType is an enum that will signify what type
the Value is
( T) String() string
T : expvar.Var
T : fmt.Stringer
T : context.stringer
T : runtime.stringer
func Section.ValueType(k string) (ValueType, bool)
func newToken(t TokenType, raw []rune, v ValueType) Token
func newValue(t ValueType, base int, raw []rune) (Value, error)
const BoolType
const DecimalType
const IntegerType
const NoneType
const QuotedStringType
const StringType
Visitor is an interface used by walkers that will
traverse an array of ASTs.
( T) VisitExpr(AST) error
( T) VisitStatement(AST) error
*DefaultVisitor
func Walk(tree []AST, v Visitor) error
Package-Level Functions (total 60, in which 9 are exported)
EqualExprKey will return a LHS value in the equal expr
NewDefaultVisitor return a DefaultVisitor
NewParseError will return a new ParseError where message
is the description of the error.
OpenFile takes a path to a given file, and will open and parse
that file.
Parse will parse the given file using the shared config
visitor.
ParseAST will parse input from an io.Reader using
an LL(1) parser.
ParseASTBytes will parse input from a byte slice using
an LL(1) parser.
ParseBytes will parse the given bytes and return the parsed sections.
Walk will traverse the AST using the v, the Visitor.
Package-Level Variables (total 13, in which 1 are exported)
Start is used to indicate the starting state of the parse table.
Package-Level Constants (total 46, in which 40 are exported)
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ASTKind* is used in the parse table to transition between
the different states
ValueType enums
section_close -> ]
comment -> # comment' | ; comment'
comment' -> MarkComplete | value
ValueType enums
ErrCodeParseError is returned when a parsing error
has occurred.
ErrCodeUnableToReadFile is used when a file is failed to be
opened or read from.
ValueType enums
State enums for the parse table
MarkComplete state will complete statements and move that
to the completed AST list
ValueType enums
section -> [ section'
ValueType enums
section' -> value section_close
SkipState will skip (NL WS)+
SkipTokenState will skip any token and push the previous
state onto the stack.
stmt' -> MarkComplete | op stmt
stmt -> value stmt'
ValueType enums
TerminalState signifies that the tokens have been fully parsed
TokenType enums
TokenType enums
TokenType enums
TokenType enums
TokenType enums
TokenType enums
TokenType enums
TokenType enums
value -> number | string | boolean | quoted_string
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |