vendor: update dependencies to latest

This commit is contained in:
Nick Craig-Wood 2018-11-24 15:31:25 +00:00
parent 58f7141c96
commit 89625e54cf
173 changed files with 4954 additions and 2224 deletions

View file

@ -12,10 +12,6 @@ func isComment(b []rune) bool {
return true
case '#':
return true
case '/':
if len(b) > 1 {
return b[1] == '/'
}
}
return false

View file

@ -24,7 +24,6 @@
//
// SkipState will skip (NL WS)+
//
// comment -> # comment' | ; comment' | / comment_slash
// comment_slash -> / comment'
// comment -> # comment' | ; comment'
// comment' -> epsilon | value
package ini

View file

@ -25,8 +25,7 @@ const (
// SkipTokenState will skip any token and push the previous
// state onto the stack.
SkipTokenState
// comment -> # comment' | ; comment' | / comment_slash
// comment_slash -> / comment'
// comment -> # comment' | ; comment'
// comment' -> MarkComplete | value
CommentState
// MarkComplete state will complete statements and move that
@ -58,7 +57,7 @@ var parseTable = map[ASTKind]map[TokenType]int{
TokenOp: StatementPrimeState,
TokenLit: ValueState,
TokenSep: OpenScopeState,
TokenWS: SkipTokenState,
TokenWS: ValueState,
TokenNL: SkipState,
TokenComment: CommentState,
TokenNone: MarkCompleteState,
@ -88,8 +87,9 @@ var parseTable = map[ASTKind]map[TokenType]int{
},
ASTKindSectionStatement: map[TokenType]int{
TokenLit: SectionState,
TokenOp: SectionState,
TokenSep: CloseScopeState,
TokenWS: SkipTokenState,
TokenWS: SectionState,
TokenNL: SkipTokenState,
},
ASTKindCompletedSectionStatement: map[TokenType]int{
@ -157,6 +157,12 @@ loop:
step := parseTable[k.Kind][tok.Type()]
if s.ShouldSkip(tok) {
// being in a skip state with no tokens will break out of
// the parse loop since there is nothing left to process.
if len(tokens) == 0 {
break loop
}
step = SkipTokenState
}
@ -192,6 +198,7 @@ loop:
)
}
k = trimSpaces(k)
expr := newEqualExpr(k, tok)
stack.Push(expr)
case ValueState:
@ -214,6 +221,9 @@ loop:
// assiging a value to some key
k.AppendChild(newExpression(tok))
stack.Push(newExprStatement(k))
case ASTKindExpr:
k.Root.raw = append(k.Root.raw, tok.Raw()...)
stack.Push(k)
case ASTKindExprStatement:
root := k.GetRoot()
children := root.GetChildren()
@ -248,6 +258,7 @@ loop:
return nil, NewParseError("expected ']'")
}
k = trimSpaces(k)
stack.Push(newCompletedSectionStatement(k))
case SectionState:
var stmt AST
@ -263,7 +274,6 @@ loop:
// the label of the section
stmt = newSectionStatement(tok)
case ASTKindSectionStatement:
k.Root.raw = append(k.Root.raw, ' ')
k.Root.raw = append(k.Root.raw, tok.Raw()...)
stmt = k
default:
@ -310,3 +320,28 @@ loop:
// returns a sublist which exludes the start symbol
return stack.List(), nil
}
// trimSpaces will trim spaces on the left and right hand side of
// the literal.
func trimSpaces(k AST) AST {
// trim left hand side of spaces
for i := 0; i < len(k.Root.raw); i++ {
if !isWhitespace(k.Root.raw[i]) {
break
}
k.Root.raw = k.Root.raw[1:]
i--
}
// trim right hand side of spaces
for i := len(k.Root.raw) - 1; i >= 0; i-- {
if !isWhitespace(k.Root.raw[i]) {
break
}
k.Root.raw = k.Root.raw[:len(k.Root.raw)-1]
}
return k
}

View file

@ -166,9 +166,6 @@ func newValue(t ValueType, base int, raw []rune) (Value, error) {
switch t {
case DecimalType:
v.decimal, err = strconv.ParseFloat(string(raw), 64)
if err != nil {
panic(err)
}
case IntegerType:
if base != 10 {
raw = raw[2:]
@ -183,6 +180,16 @@ func newValue(t ValueType, base int, raw []rune) (Value, error) {
v.boolean = runeCompare(v.raw, runesTrue)
}
// issue 2253
//
// if the value trying to be parsed is too large, then we will use
// the 'StringType' and raw value instead.
if nerr, ok := err.(*strconv.NumError); ok && nerr.Err == strconv.ErrRange {
v.Type = StringType
v.str = string(raw)
err = nil
}
return v, err
}

View file

@ -5,10 +5,10 @@ package ini
// files. See example below
//
// [ foo ]
// nested = // this section will be skipped
// nested = ; this section will be skipped
// a=b
// c=d
// bar=baz // this will be included
// bar=baz ; this will be included
type skipper struct {
shouldSkip bool
TokenSet bool
@ -22,7 +22,10 @@ func newSkipper() skipper {
}
func (s *skipper) ShouldSkip(tok Token) bool {
if s.shouldSkip && s.prevTok.Type() == TokenNL && tok.Type() != TokenWS {
if s.shouldSkip &&
s.prevTok.Type() == TokenNL &&
tok.Type() != TokenWS {
s.Continue()
return false
}

View file

@ -18,9 +18,8 @@ func newExprStatement(ast AST) AST {
// CommentStatement represents a comment in the ini defintion.
//
// grammar:
// comment -> #comment' | ;comment' | /comment_slash
// comment_slash -> /comment'
// comment' -> value
// comment -> #comment' | ;comment'
// comment' -> epsilon | value
func newCommentStatement(tok Token) AST {
return newAST(ASTKindCommentStatement, newExpression(tok))
}

View file

@ -141,6 +141,11 @@ func (t Section) ValueType(k string) (ValueType, bool) {
return v.Type, ok
}
// Bool returns a bool value at k
func (t Section) Bool(k string) bool {
return t.values[k].BoolValue()
}
// Int returns an integer value at k
func (t Section) Int(k string) int64 {
return t.values[k].IntValue()