mirror of
https://github.com/yudai/gotty.git
synced 2026-02-14 20:28:07 +01:00
Change to go1.6.1 and vendoring
This commit is contained in:
parent
b1c5226875
commit
a350994aa2
164 changed files with 17 additions and 1383 deletions
1
vendor/github.com/yudai/hcl/.gitignore
generated
vendored
Normal file
1
vendor/github.com/yudai/hcl/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
y.output
|
||||
354
vendor/github.com/yudai/hcl/LICENSE
generated
vendored
Normal file
354
vendor/github.com/yudai/hcl/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
Mozilla Public License, version 2.0
|
||||
|
||||
1. Definitions
|
||||
|
||||
1.1. “Contributor”
|
||||
|
||||
means each individual or legal entity that creates, contributes to the
|
||||
creation of, or owns Covered Software.
|
||||
|
||||
1.2. “Contributor Version”
|
||||
|
||||
means the combination of the Contributions of others (if any) used by a
|
||||
Contributor and that particular Contributor’s Contribution.
|
||||
|
||||
1.3. “Contribution”
|
||||
|
||||
means Covered Software of a particular Contributor.
|
||||
|
||||
1.4. “Covered Software”
|
||||
|
||||
means Source Code Form to which the initial Contributor has attached the
|
||||
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
||||
Modifications of such Source Code Form, in each case including portions
|
||||
thereof.
|
||||
|
||||
1.5. “Incompatible With Secondary Licenses”
|
||||
means
|
||||
|
||||
a. that the initial Contributor has attached the notice described in
|
||||
Exhibit B to the Covered Software; or
|
||||
|
||||
b. that the Covered Software was made available under the terms of version
|
||||
1.1 or earlier of the License, but not also under the terms of a
|
||||
Secondary License.
|
||||
|
||||
1.6. “Executable Form”
|
||||
|
||||
means any form of the work other than Source Code Form.
|
||||
|
||||
1.7. “Larger Work”
|
||||
|
||||
means a work that combines Covered Software with other material, in a separate
|
||||
file or files, that is not Covered Software.
|
||||
|
||||
1.8. “License”
|
||||
|
||||
means this document.
|
||||
|
||||
1.9. “Licensable”
|
||||
|
||||
means having the right to grant, to the maximum extent possible, whether at the
|
||||
time of the initial grant or subsequently, any and all of the rights conveyed by
|
||||
this License.
|
||||
|
||||
1.10. “Modifications”
|
||||
|
||||
means any of the following:
|
||||
|
||||
a. any file in Source Code Form that results from an addition to, deletion
|
||||
from, or modification of the contents of Covered Software; or
|
||||
|
||||
b. any new file in Source Code Form that contains any Covered Software.
|
||||
|
||||
1.11. “Patent Claims” of a Contributor
|
||||
|
||||
means any patent claim(s), including without limitation, method, process,
|
||||
and apparatus claims, in any patent Licensable by such Contributor that
|
||||
would be infringed, but for the grant of the License, by the making,
|
||||
using, selling, offering for sale, having made, import, or transfer of
|
||||
either its Contributions or its Contributor Version.
|
||||
|
||||
1.12. “Secondary License”
|
||||
|
||||
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
||||
General Public License, Version 2.1, the GNU Affero General Public
|
||||
License, Version 3.0, or any later versions of those licenses.
|
||||
|
||||
1.13. “Source Code Form”
|
||||
|
||||
means the form of the work preferred for making modifications.
|
||||
|
||||
1.14. “You” (or “Your”)
|
||||
|
||||
means an individual or a legal entity exercising rights under this
|
||||
License. For legal entities, “You” includes any entity that controls, is
|
||||
controlled by, or is under common control with You. For purposes of this
|
||||
definition, “control” means (a) the power, direct or indirect, to cause
|
||||
the direction or management of such entity, whether by contract or
|
||||
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
||||
outstanding shares or beneficial ownership of such entity.
|
||||
|
||||
|
||||
2. License Grants and Conditions
|
||||
|
||||
2.1. Grants
|
||||
|
||||
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||
non-exclusive license:
|
||||
|
||||
a. under intellectual property rights (other than patent or trademark)
|
||||
Licensable by such Contributor to use, reproduce, make available,
|
||||
modify, display, perform, distribute, and otherwise exploit its
|
||||
Contributions, either on an unmodified basis, with Modifications, or as
|
||||
part of a Larger Work; and
|
||||
|
||||
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
||||
sale, have made, import, and otherwise transfer either its Contributions
|
||||
or its Contributor Version.
|
||||
|
||||
2.2. Effective Date
|
||||
|
||||
The licenses granted in Section 2.1 with respect to any Contribution become
|
||||
effective for each Contribution on the date the Contributor first distributes
|
||||
such Contribution.
|
||||
|
||||
2.3. Limitations on Grant Scope
|
||||
|
||||
The licenses granted in this Section 2 are the only rights granted under this
|
||||
License. No additional rights or licenses will be implied from the distribution
|
||||
or licensing of Covered Software under this License. Notwithstanding Section
|
||||
2.1(b) above, no patent license is granted by a Contributor:
|
||||
|
||||
a. for any code that a Contributor has removed from Covered Software; or
|
||||
|
||||
b. for infringements caused by: (i) Your and any other third party’s
|
||||
modifications of Covered Software, or (ii) the combination of its
|
||||
Contributions with other software (except as part of its Contributor
|
||||
Version); or
|
||||
|
||||
c. under Patent Claims infringed by Covered Software in the absence of its
|
||||
Contributions.
|
||||
|
||||
This License does not grant any rights in the trademarks, service marks, or
|
||||
logos of any Contributor (except as may be necessary to comply with the
|
||||
notice requirements in Section 3.4).
|
||||
|
||||
2.4. Subsequent Licenses
|
||||
|
||||
No Contributor makes additional grants as a result of Your choice to
|
||||
distribute the Covered Software under a subsequent version of this License
|
||||
(see Section 10.2) or under the terms of a Secondary License (if permitted
|
||||
under the terms of Section 3.3).
|
||||
|
||||
2.5. Representation
|
||||
|
||||
Each Contributor represents that the Contributor believes its Contributions
|
||||
are its original creation(s) or it has sufficient rights to grant the
|
||||
rights to its Contributions conveyed by this License.
|
||||
|
||||
2.6. Fair Use
|
||||
|
||||
This License is not intended to limit any rights You have under applicable
|
||||
copyright doctrines of fair use, fair dealing, or other equivalents.
|
||||
|
||||
2.7. Conditions
|
||||
|
||||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
||||
Section 2.1.
|
||||
|
||||
|
||||
3. Responsibilities
|
||||
|
||||
3.1. Distribution of Source Form
|
||||
|
||||
All distribution of Covered Software in Source Code Form, including any
|
||||
Modifications that You create or to which You contribute, must be under the
|
||||
terms of this License. You must inform recipients that the Source Code Form
|
||||
of the Covered Software is governed by the terms of this License, and how
|
||||
they can obtain a copy of this License. You may not attempt to alter or
|
||||
restrict the recipients’ rights in the Source Code Form.
|
||||
|
||||
3.2. Distribution of Executable Form
|
||||
|
||||
If You distribute Covered Software in Executable Form then:
|
||||
|
||||
a. such Covered Software must also be made available in Source Code Form,
|
||||
as described in Section 3.1, and You must inform recipients of the
|
||||
Executable Form how they can obtain a copy of such Source Code Form by
|
||||
reasonable means in a timely manner, at a charge no more than the cost
|
||||
of distribution to the recipient; and
|
||||
|
||||
b. You may distribute such Executable Form under the terms of this License,
|
||||
or sublicense it under different terms, provided that the license for
|
||||
the Executable Form does not attempt to limit or alter the recipients’
|
||||
rights in the Source Code Form under this License.
|
||||
|
||||
3.3. Distribution of a Larger Work
|
||||
|
||||
You may create and distribute a Larger Work under terms of Your choice,
|
||||
provided that You also comply with the requirements of this License for the
|
||||
Covered Software. If the Larger Work is a combination of Covered Software
|
||||
with a work governed by one or more Secondary Licenses, and the Covered
|
||||
Software is not Incompatible With Secondary Licenses, this License permits
|
||||
You to additionally distribute such Covered Software under the terms of
|
||||
such Secondary License(s), so that the recipient of the Larger Work may, at
|
||||
their option, further distribute the Covered Software under the terms of
|
||||
either this License or such Secondary License(s).
|
||||
|
||||
3.4. Notices
|
||||
|
||||
You may not remove or alter the substance of any license notices (including
|
||||
copyright notices, patent notices, disclaimers of warranty, or limitations
|
||||
of liability) contained within the Source Code Form of the Covered
|
||||
Software, except that You may alter any license notices to the extent
|
||||
required to remedy known factual inaccuracies.
|
||||
|
||||
3.5. Application of Additional Terms
|
||||
|
||||
You may choose to offer, and to charge a fee for, warranty, support,
|
||||
indemnity or liability obligations to one or more recipients of Covered
|
||||
Software. However, You may do so only on Your own behalf, and not on behalf
|
||||
of any Contributor. You must make it absolutely clear that any such
|
||||
warranty, support, indemnity, or liability obligation is offered by You
|
||||
alone, and You hereby agree to indemnify every Contributor for any
|
||||
liability incurred by such Contributor as a result of warranty, support,
|
||||
indemnity or liability terms You offer. You may include additional
|
||||
disclaimers of warranty and limitations of liability specific to any
|
||||
jurisdiction.
|
||||
|
||||
4. Inability to Comply Due to Statute or Regulation
|
||||
|
||||
If it is impossible for You to comply with any of the terms of this License
|
||||
with respect to some or all of the Covered Software due to statute, judicial
|
||||
order, or regulation then You must: (a) comply with the terms of this License
|
||||
to the maximum extent possible; and (b) describe the limitations and the code
|
||||
they affect. Such description must be placed in a text file included with all
|
||||
distributions of the Covered Software under this License. Except to the
|
||||
extent prohibited by statute or regulation, such description must be
|
||||
sufficiently detailed for a recipient of ordinary skill to be able to
|
||||
understand it.
|
||||
|
||||
5. Termination
|
||||
|
||||
5.1. The rights granted under this License will terminate automatically if You
|
||||
fail to comply with any of its terms. However, if You become compliant,
|
||||
then the rights granted under this License from a particular Contributor
|
||||
are reinstated (a) provisionally, unless and until such Contributor
|
||||
explicitly and finally terminates Your grants, and (b) on an ongoing basis,
|
||||
if such Contributor fails to notify You of the non-compliance by some
|
||||
reasonable means prior to 60 days after You have come back into compliance.
|
||||
Moreover, Your grants from a particular Contributor are reinstated on an
|
||||
ongoing basis if such Contributor notifies You of the non-compliance by
|
||||
some reasonable means, this is the first time You have received notice of
|
||||
non-compliance with this License from such Contributor, and You become
|
||||
compliant prior to 30 days after Your receipt of the notice.
|
||||
|
||||
5.2. If You initiate litigation against any entity by asserting a patent
|
||||
infringement claim (excluding declaratory judgment actions, counter-claims,
|
||||
and cross-claims) alleging that a Contributor Version directly or
|
||||
indirectly infringes any patent, then the rights granted to You by any and
|
||||
all Contributors for the Covered Software under Section 2.1 of this License
|
||||
shall terminate.
|
||||
|
||||
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
||||
license agreements (excluding distributors and resellers) which have been
|
||||
validly granted by You or Your distributors under this License prior to
|
||||
termination shall survive termination.
|
||||
|
||||
6. Disclaimer of Warranty
|
||||
|
||||
Covered Software is provided under this License on an “as is” basis, without
|
||||
warranty of any kind, either expressed, implied, or statutory, including,
|
||||
without limitation, warranties that the Covered Software is free of defects,
|
||||
merchantable, fit for a particular purpose or non-infringing. The entire
|
||||
risk as to the quality and performance of the Covered Software is with You.
|
||||
Should any Covered Software prove defective in any respect, You (not any
|
||||
Contributor) assume the cost of any necessary servicing, repair, or
|
||||
correction. This disclaimer of warranty constitutes an essential part of this
|
||||
License. No use of any Covered Software is authorized under this License
|
||||
except under this disclaimer.
|
||||
|
||||
7. Limitation of Liability
|
||||
|
||||
Under no circumstances and under no legal theory, whether tort (including
|
||||
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
||||
distributes Covered Software as permitted above, be liable to You for any
|
||||
direct, indirect, special, incidental, or consequential damages of any
|
||||
character including, without limitation, damages for lost profits, loss of
|
||||
goodwill, work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses, even if such party shall have been
|
||||
informed of the possibility of such damages. This limitation of liability
|
||||
shall not apply to liability for death or personal injury resulting from such
|
||||
party’s negligence to the extent applicable law prohibits such limitation.
|
||||
Some jurisdictions do not allow the exclusion or limitation of incidental or
|
||||
consequential damages, so this exclusion and limitation may not apply to You.
|
||||
|
||||
8. Litigation
|
||||
|
||||
Any litigation relating to this License may be brought only in the courts of
|
||||
a jurisdiction where the defendant maintains its principal place of business
|
||||
and such litigation shall be governed by laws of that jurisdiction, without
|
||||
reference to its conflict-of-law provisions. Nothing in this Section shall
|
||||
prevent a party’s ability to bring cross-claims or counter-claims.
|
||||
|
||||
9. Miscellaneous
|
||||
|
||||
This License represents the complete agreement concerning the subject matter
|
||||
hereof. If any provision of this License is held to be unenforceable, such
|
||||
provision shall be reformed only to the extent necessary to make it
|
||||
enforceable. Any law or regulation which provides that the language of a
|
||||
contract shall be construed against the drafter shall not be used to construe
|
||||
this License against a Contributor.
|
||||
|
||||
|
||||
10. Versions of the License
|
||||
|
||||
10.1. New Versions
|
||||
|
||||
Mozilla Foundation is the license steward. Except as provided in Section
|
||||
10.3, no one other than the license steward has the right to modify or
|
||||
publish new versions of this License. Each version will be given a
|
||||
distinguishing version number.
|
||||
|
||||
10.2. Effect of New Versions
|
||||
|
||||
You may distribute the Covered Software under the terms of the version of
|
||||
the License under which You originally received the Covered Software, or
|
||||
under the terms of any subsequent version published by the license
|
||||
steward.
|
||||
|
||||
10.3. Modified Versions
|
||||
|
||||
If you create software not governed by this License, and you want to
|
||||
create a new license for such software, you may create and use a modified
|
||||
version of this License if you rename the license and remove any
|
||||
references to the name of the license steward (except to note that such
|
||||
modified license differs from this License).
|
||||
|
||||
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
|
||||
If You choose to distribute Source Code Form that is Incompatible With
|
||||
Secondary Licenses under the terms of this version of the License, the
|
||||
notice described in Exhibit B of this License must be attached.
|
||||
|
||||
Exhibit A - Source Code Form License Notice
|
||||
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
|
||||
If it is not possible or desirable to put the notice in a particular file, then
|
||||
You may include the notice in a location (such as a LICENSE file in a relevant
|
||||
directory) where a recipient would be likely to look for such a notice.
|
||||
|
||||
You may add additional accurate notices of copyright ownership.
|
||||
|
||||
Exhibit B - “Incompatible With Secondary Licenses” Notice
|
||||
|
||||
This Source Code Form is “Incompatible
|
||||
With Secondary Licenses”, as defined by
|
||||
the Mozilla Public License, v. 2.0.
|
||||
|
||||
17
vendor/github.com/yudai/hcl/Makefile
generated
vendored
Normal file
17
vendor/github.com/yudai/hcl/Makefile
generated
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
TEST?=./...
|
||||
|
||||
default: test
|
||||
|
||||
fmt: generate
|
||||
go fmt ./...
|
||||
|
||||
test: generate
|
||||
go test $(TEST) $(TESTARGS)
|
||||
|
||||
generate:
|
||||
go generate ./...
|
||||
|
||||
updatedeps:
|
||||
go get -u golang.org/x/tools/cmd/stringer
|
||||
|
||||
.PHONY: default generate test updatedeps
|
||||
84
vendor/github.com/yudai/hcl/README.md
generated
vendored
Normal file
84
vendor/github.com/yudai/hcl/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# HCL
|
||||
|
||||
HCL (HashiCorp Configuration Language) is a configuration language built
|
||||
by HashiCorp. The goal of HCL is to build a structured configuration language
|
||||
that is both human and machine friendly for use with command-line tools, but
|
||||
specifically targeted towards DevOps tools, servers, etc.
|
||||
|
||||
HCL is also fully JSON compatible. That is, JSON can be used as completely
|
||||
valid input to a system expecting HCL. This helps makes systems
|
||||
interoperable with other systems.
|
||||
|
||||
HCL is heavily inspired by
|
||||
[libucl](https://github.com/vstakhov/libucl),
|
||||
nginx configuration, and others similar.
|
||||
|
||||
## Why?
|
||||
|
||||
A common question when viewing HCL is to ask the question: why not
|
||||
JSON, YAML, etc.?
|
||||
|
||||
Prior to HCL, the tools we built at [HashiCorp](http://www.hashicorp.com)
|
||||
used a variety of configuration languages from full programming languages
|
||||
such as Ruby to complete data structure languages such as JSON. What we
|
||||
learned is that some people wanted human-friendly configuration languages
|
||||
and some people wanted machine-friendly languages.
|
||||
|
||||
JSON fits a nice balance in this, but is fairly verbose and most
|
||||
importantly doesn't support comments. With YAML, we found that beginners
|
||||
had a really hard time determining what the actual structure was, and
|
||||
ended up guessing more than not whether to use a hyphen, colon, etc.
|
||||
in order to represent some configuration key.
|
||||
|
||||
Full programming languages such as Ruby enable complex behavior
|
||||
a configuration language shouldn't usually allow, and also forces
|
||||
people to learn some set of Ruby.
|
||||
|
||||
Because of this, we decided to create our own configuration language
|
||||
that is JSON-compatible. Our configuration language (HCL) is designed
|
||||
to be written and modified by humans. The API for HCL allows JSON
|
||||
as an input so that it is also machine-friendly (machines can generate
|
||||
JSON instead of trying to generate HCL).
|
||||
|
||||
Our goal with HCL is not to alienate other configuration languages.
|
||||
It is instead to provide HCL as a specialized language for our tools,
|
||||
and JSON as the interoperability layer.
|
||||
|
||||
## Syntax
|
||||
|
||||
The complete grammar
|
||||
[can be found here](https://github.com/hashicorp/hcl/blob/master/hcl/parse.y),
|
||||
if you're more comfortable reading specifics, but a high-level overview
|
||||
of the syntax and grammar are listed here.
|
||||
|
||||
* Single line comments start with `#` or `//`
|
||||
|
||||
* Multi-line comments are wrapped in `/*` and `*/`. Nested block comments
|
||||
are not allowed. A multi-line comment (also known as a block comment)
|
||||
terminates at the first `*/` found.
|
||||
|
||||
* Values are assigned with the syntax `key = value` (whitespace doesn't
|
||||
matter). The value can be any primitive: a string, number, boolean,
|
||||
object, or list.
|
||||
|
||||
* Strings are double-quoted and can contain any UTF-8 characters.
|
||||
Example: `"Hello, World"`
|
||||
|
||||
* Numbers are assumed to be base 10. If you prefix a number with 0x,
|
||||
it is treated as a hexadecimal. If it is prefixed with 0, it is
|
||||
treated as an octal. Numbers can be in scientific notation: "1e10".
|
||||
|
||||
* Boolean values: `true`, `false`
|
||||
|
||||
* Arrays can be made by wrapping it in `[]`. Example:
|
||||
`["foo", "bar", 42]`. Arrays can contain primitives
|
||||
and other arrays, but cannot contain objects. Objects must
|
||||
use the block syntax shown below.
|
||||
|
||||
Objects and nested objects are created using the structure shown below:
|
||||
|
||||
```
|
||||
variable "ami" {
|
||||
description = "the AMI to use"
|
||||
}
|
||||
```
|
||||
490
vendor/github.com/yudai/hcl/decoder.go
generated
vendored
Normal file
490
vendor/github.com/yudai/hcl/decoder.go
generated
vendored
Normal file
|
|
@ -0,0 +1,490 @@
|
|||
package hcl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/yudai/hcl/hcl"
|
||||
)
|
||||
|
||||
// This is the tag to use with structures to have settings for HCL
|
||||
const tagName = "hcl"
|
||||
|
||||
// Decode reads the given input and decodes it into the structure
|
||||
// given by `out`.
|
||||
func Decode(out interface{}, in string) error {
|
||||
obj, err := Parse(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return DecodeObject(out, obj)
|
||||
}
|
||||
|
||||
// DecodeObject is a lower-level version of Decode. It decodes a
|
||||
// raw Object into the given output.
|
||||
func DecodeObject(out interface{}, n *hcl.Object) error {
|
||||
val := reflect.ValueOf(out)
|
||||
if val.Kind() != reflect.Ptr {
|
||||
return errors.New("result must be a pointer")
|
||||
}
|
||||
|
||||
var d decoder
|
||||
return d.decode("root", n, val.Elem())
|
||||
}
|
||||
|
||||
type decoder struct {
|
||||
stack []reflect.Kind
|
||||
}
|
||||
|
||||
func (d *decoder) decode(name string, o *hcl.Object, result reflect.Value) error {
|
||||
k := result
|
||||
|
||||
// If we have an interface with a valid value, we use that
|
||||
// for the check.
|
||||
if result.Kind() == reflect.Interface {
|
||||
elem := result.Elem()
|
||||
if elem.IsValid() {
|
||||
k = elem
|
||||
}
|
||||
}
|
||||
|
||||
// Push current onto stack unless it is an interface.
|
||||
if k.Kind() != reflect.Interface {
|
||||
d.stack = append(d.stack, k.Kind())
|
||||
|
||||
// Schedule a pop
|
||||
defer func() {
|
||||
d.stack = d.stack[:len(d.stack)-1]
|
||||
}()
|
||||
}
|
||||
|
||||
switch k.Kind() {
|
||||
case reflect.Bool:
|
||||
return d.decodeBool(name, o, result)
|
||||
case reflect.Float64:
|
||||
return d.decodeFloat(name, o, result)
|
||||
case reflect.Int:
|
||||
return d.decodeInt(name, o, result)
|
||||
case reflect.Interface:
|
||||
// When we see an interface, we make our own thing
|
||||
return d.decodeInterface(name, o, result)
|
||||
case reflect.Map:
|
||||
return d.decodeMap(name, o, result)
|
||||
case reflect.Ptr:
|
||||
return d.decodePtr(name, o, result)
|
||||
case reflect.Slice:
|
||||
return d.decodeSlice(name, o, result)
|
||||
case reflect.String:
|
||||
return d.decodeString(name, o, result)
|
||||
case reflect.Struct:
|
||||
return d.decodeStruct(name, o, result)
|
||||
default:
|
||||
return fmt.Errorf(
|
||||
"%s: unknown kind to decode into: %s", name, k.Kind())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodeBool(name string, o *hcl.Object, result reflect.Value) error {
|
||||
switch o.Type {
|
||||
case hcl.ValueTypeBool:
|
||||
result.Set(reflect.ValueOf(o.Value.(bool)))
|
||||
default:
|
||||
return fmt.Errorf("%s: unknown type %v", name, o.Type)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodeFloat(name string, o *hcl.Object, result reflect.Value) error {
|
||||
switch o.Type {
|
||||
case hcl.ValueTypeFloat:
|
||||
result.Set(reflect.ValueOf(o.Value.(float64)))
|
||||
default:
|
||||
return fmt.Errorf("%s: unknown type %v", name, o.Type)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodeInt(name string, o *hcl.Object, result reflect.Value) error {
|
||||
switch o.Type {
|
||||
case hcl.ValueTypeInt:
|
||||
result.Set(reflect.ValueOf(o.Value.(int)))
|
||||
case hcl.ValueTypeString:
|
||||
v, err := strconv.ParseInt(o.Value.(string), 0, 0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result.SetInt(int64(v))
|
||||
default:
|
||||
return fmt.Errorf("%s: unknown type %v", name, o.Type)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodeInterface(name string, o *hcl.Object, result reflect.Value) error {
|
||||
var set reflect.Value
|
||||
redecode := true
|
||||
|
||||
switch o.Type {
|
||||
case hcl.ValueTypeObject:
|
||||
// If we're at the root or we're directly within a slice, then we
|
||||
// decode objects into map[string]interface{}, otherwise we decode
|
||||
// them into lists.
|
||||
if len(d.stack) == 0 || d.stack[len(d.stack)-1] == reflect.Slice {
|
||||
var temp map[string]interface{}
|
||||
tempVal := reflect.ValueOf(temp)
|
||||
result := reflect.MakeMap(
|
||||
reflect.MapOf(
|
||||
reflect.TypeOf(""),
|
||||
tempVal.Type().Elem()))
|
||||
|
||||
set = result
|
||||
} else {
|
||||
var temp []map[string]interface{}
|
||||
tempVal := reflect.ValueOf(temp)
|
||||
result := reflect.MakeSlice(
|
||||
reflect.SliceOf(tempVal.Type().Elem()), 0, int(o.Len()))
|
||||
set = result
|
||||
}
|
||||
case hcl.ValueTypeList:
|
||||
var temp []interface{}
|
||||
tempVal := reflect.ValueOf(temp)
|
||||
result := reflect.MakeSlice(
|
||||
reflect.SliceOf(tempVal.Type().Elem()), 0, 0)
|
||||
set = result
|
||||
case hcl.ValueTypeBool:
|
||||
var result bool
|
||||
set = reflect.Indirect(reflect.New(reflect.TypeOf(result)))
|
||||
case hcl.ValueTypeFloat:
|
||||
var result float64
|
||||
set = reflect.Indirect(reflect.New(reflect.TypeOf(result)))
|
||||
case hcl.ValueTypeInt:
|
||||
var result int
|
||||
set = reflect.Indirect(reflect.New(reflect.TypeOf(result)))
|
||||
case hcl.ValueTypeString:
|
||||
set = reflect.Indirect(reflect.New(reflect.TypeOf("")))
|
||||
case hcl.ValueTypeNil:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf(
|
||||
"%s: cannot decode into interface: %T",
|
||||
name, o)
|
||||
}
|
||||
|
||||
// Set the result to what its supposed to be, then reset
|
||||
// result so we don't reflect into this method anymore.
|
||||
result.Set(set)
|
||||
|
||||
if redecode {
|
||||
// Revisit the node so that we can use the newly instantiated
|
||||
// thing and populate it.
|
||||
if err := d.decode(name, o, result); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodeMap(name string, o *hcl.Object, result reflect.Value) error {
|
||||
if o.Type != hcl.ValueTypeObject {
|
||||
return fmt.Errorf("%s: not an object type for map (%v)", name, o.Type)
|
||||
}
|
||||
|
||||
// If we have an interface, then we can address the interface,
|
||||
// but not the slice itself, so get the element but set the interface
|
||||
set := result
|
||||
if result.Kind() == reflect.Interface {
|
||||
result = result.Elem()
|
||||
}
|
||||
|
||||
resultType := result.Type()
|
||||
resultElemType := resultType.Elem()
|
||||
resultKeyType := resultType.Key()
|
||||
if resultKeyType.Kind() != reflect.String {
|
||||
return fmt.Errorf(
|
||||
"%s: map must have string keys", name)
|
||||
}
|
||||
|
||||
// Make a map if it is nil
|
||||
resultMap := result
|
||||
if result.IsNil() {
|
||||
resultMap = reflect.MakeMap(
|
||||
reflect.MapOf(resultKeyType, resultElemType))
|
||||
}
|
||||
|
||||
// Go through each element and decode it.
|
||||
for _, o := range o.Elem(false) {
|
||||
if o.Value == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, o := range o.Elem(true) {
|
||||
// Make the field name
|
||||
fieldName := fmt.Sprintf("%s.%s", name, o.Key)
|
||||
|
||||
// Get the key/value as reflection values
|
||||
key := reflect.ValueOf(o.Key)
|
||||
val := reflect.Indirect(reflect.New(resultElemType))
|
||||
|
||||
// If we have a pre-existing value in the map, use that
|
||||
oldVal := resultMap.MapIndex(key)
|
||||
if oldVal.IsValid() {
|
||||
val.Set(oldVal)
|
||||
}
|
||||
|
||||
// Decode!
|
||||
if err := d.decode(fieldName, o, val); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Set the value on the map
|
||||
resultMap.SetMapIndex(key, val)
|
||||
}
|
||||
}
|
||||
|
||||
// Set the final map if we can
|
||||
set.Set(resultMap)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodePtr(name string, o *hcl.Object, result reflect.Value) error {
|
||||
// Create an element of the concrete (non pointer) type and decode
|
||||
// into that. Then set the value of the pointer to this type.
|
||||
switch o.Type {
|
||||
case hcl.ValueTypeNil:
|
||||
// NIL
|
||||
default:
|
||||
resultType := result.Type()
|
||||
resultElemType := resultType.Elem()
|
||||
val := reflect.New(resultElemType)
|
||||
if err := d.decode(name, o, reflect.Indirect(val)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result.Set(val)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodeSlice(name string, o *hcl.Object, result reflect.Value) error {
|
||||
// If we have an interface, then we can address the interface,
|
||||
// but not the slice itself, so get the element but set the interface
|
||||
set := result
|
||||
if result.Kind() == reflect.Interface {
|
||||
result = result.Elem()
|
||||
}
|
||||
|
||||
// Create the slice if it isn't nil
|
||||
resultType := result.Type()
|
||||
resultElemType := resultType.Elem()
|
||||
if result.IsNil() {
|
||||
resultSliceType := reflect.SliceOf(resultElemType)
|
||||
result = reflect.MakeSlice(
|
||||
resultSliceType, 0, 0)
|
||||
}
|
||||
|
||||
// Determine how we're doing this
|
||||
expand := true
|
||||
switch o.Type {
|
||||
case hcl.ValueTypeObject:
|
||||
expand = false
|
||||
default:
|
||||
// Array or anything else: we expand values and take it all
|
||||
}
|
||||
|
||||
i := 0
|
||||
for _, o := range o.Elem(expand) {
|
||||
fieldName := fmt.Sprintf("%s[%d]", name, i)
|
||||
|
||||
// Decode
|
||||
val := reflect.Indirect(reflect.New(resultElemType))
|
||||
if err := d.decode(fieldName, o, val); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Append it onto the slice
|
||||
result = reflect.Append(result, val)
|
||||
|
||||
i += 1
|
||||
}
|
||||
|
||||
set.Set(result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodeString(name string, o *hcl.Object, result reflect.Value) error {
|
||||
switch o.Type {
|
||||
case hcl.ValueTypeInt:
|
||||
result.Set(reflect.ValueOf(
|
||||
strconv.FormatInt(int64(o.Value.(int)), 10)).Convert(result.Type()))
|
||||
case hcl.ValueTypeString:
|
||||
result.Set(reflect.ValueOf(o.Value.(string)).Convert(result.Type()))
|
||||
default:
|
||||
return fmt.Errorf("%s: unknown type to string: %v", name, o.Type)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *decoder) decodeStruct(name string, o *hcl.Object, result reflect.Value) error {
|
||||
if o.Type != hcl.ValueTypeObject {
|
||||
return fmt.Errorf("%s: not an object type for struct (%v)", name, o.Type)
|
||||
}
|
||||
|
||||
// This slice will keep track of all the structs we'll be decoding.
|
||||
// There can be more than one struct if there are embedded structs
|
||||
// that are squashed.
|
||||
structs := make([]reflect.Value, 1, 5)
|
||||
structs[0] = result
|
||||
|
||||
// Compile the list of all the fields that we're going to be decoding
|
||||
// from all the structs.
|
||||
fields := make(map[*reflect.StructField]reflect.Value)
|
||||
for len(structs) > 0 {
|
||||
structVal := structs[0]
|
||||
structs = structs[1:]
|
||||
|
||||
structType := structVal.Type()
|
||||
for i := 0; i < structType.NumField(); i++ {
|
||||
fieldType := structType.Field(i)
|
||||
|
||||
if fieldType.Anonymous {
|
||||
fieldKind := fieldType.Type.Kind()
|
||||
if fieldKind != reflect.Struct {
|
||||
return fmt.Errorf(
|
||||
"%s: unsupported type to struct: %s",
|
||||
fieldType.Name, fieldKind)
|
||||
}
|
||||
|
||||
// We have an embedded field. We "squash" the fields down
|
||||
// if specified in the tag.
|
||||
squash := false
|
||||
tagParts := strings.Split(fieldType.Tag.Get(tagName), ",")
|
||||
for _, tag := range tagParts[1:] {
|
||||
if tag == "squash" {
|
||||
squash = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if squash {
|
||||
structs = append(
|
||||
structs, result.FieldByName(fieldType.Name))
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Normal struct field, store it away
|
||||
fields[&fieldType] = structVal.Field(i)
|
||||
}
|
||||
}
|
||||
|
||||
usedKeys := make(map[string]struct{})
|
||||
decodedFields := make([]string, 0, len(fields))
|
||||
decodedFieldsVal := make([]reflect.Value, 0)
|
||||
unusedKeysVal := make([]reflect.Value, 0)
|
||||
for fieldType, field := range fields {
|
||||
if !field.IsValid() {
|
||||
// This should never happen
|
||||
panic("field is not valid")
|
||||
}
|
||||
|
||||
// If we can't set the field, then it is unexported or something,
|
||||
// and we just continue onwards.
|
||||
if !field.CanSet() {
|
||||
continue
|
||||
}
|
||||
|
||||
fieldName := fieldType.Name
|
||||
|
||||
// This is whether or not we expand the object into its children
|
||||
// later.
|
||||
expand := false
|
||||
|
||||
tagValue := fieldType.Tag.Get(tagName)
|
||||
tagParts := strings.SplitN(tagValue, ",", 2)
|
||||
if len(tagParts) >= 2 {
|
||||
switch tagParts[1] {
|
||||
case "expand":
|
||||
expand = true
|
||||
case "decodedFields":
|
||||
decodedFieldsVal = append(decodedFieldsVal, field)
|
||||
continue
|
||||
case "key":
|
||||
field.SetString(o.Key)
|
||||
continue
|
||||
case "unusedKeys":
|
||||
unusedKeysVal = append(unusedKeysVal, field)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
if tagParts[0] != "" {
|
||||
fieldName = tagParts[0]
|
||||
}
|
||||
|
||||
// Find the element matching this name
|
||||
obj := o.Get(fieldName, true)
|
||||
if obj == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// Track the used key
|
||||
usedKeys[fieldName] = struct{}{}
|
||||
|
||||
// Create the field name and decode. We range over the elements
|
||||
// because we actually want the value.
|
||||
fieldName = fmt.Sprintf("%s.%s", name, fieldName)
|
||||
for _, obj := range obj.Elem(expand) {
|
||||
if err := d.decode(fieldName, obj, field); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
decodedFields = append(decodedFields, fieldType.Name)
|
||||
}
|
||||
|
||||
if len(decodedFieldsVal) > 0 {
|
||||
// Sort it so that it is deterministic
|
||||
sort.Strings(decodedFields)
|
||||
|
||||
for _, v := range decodedFieldsVal {
|
||||
v.Set(reflect.ValueOf(decodedFields))
|
||||
}
|
||||
}
|
||||
|
||||
// If we want to know what keys are unused, compile that
|
||||
if len(unusedKeysVal) > 0 {
|
||||
/*
|
||||
unusedKeys := make([]string, 0, int(obj.Len())-len(usedKeys))
|
||||
|
||||
for _, elem := range obj.Elem {
|
||||
k := elem.Key()
|
||||
if _, ok := usedKeys[k]; !ok {
|
||||
unusedKeys = append(unusedKeys, k)
|
||||
}
|
||||
}
|
||||
|
||||
if len(unusedKeys) == 0 {
|
||||
unusedKeys = nil
|
||||
}
|
||||
|
||||
for _, v := range unusedKeysVal {
|
||||
v.Set(reflect.ValueOf(unusedKeys))
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
11
vendor/github.com/yudai/hcl/hcl.go
generated
vendored
Normal file
11
vendor/github.com/yudai/hcl/hcl.go
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// hcl is a package for decoding HCL into usable Go structures.
|
||||
//
|
||||
// hcl input can come in either pure HCL format or JSON format.
|
||||
// It can be parsed into an AST, and then decoded into a structure,
|
||||
// or it can be decoded directly from a string into a structure.
|
||||
//
|
||||
// If you choose to parse HCL into a raw AST, the benefit is that you
|
||||
// can write custom visitor implementations to implement custom
|
||||
// semantic checks. By default, HCL does not perform any semantic
|
||||
// checks.
|
||||
package hcl
|
||||
447
vendor/github.com/yudai/hcl/hcl/lex.go
generated
vendored
Normal file
447
vendor/github.com/yudai/hcl/hcl/lex.go
generated
vendored
Normal file
|
|
@ -0,0 +1,447 @@
|
|||
package hcl
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
//go:generate go tool yacc -p "hcl" parse.y
|
||||
|
||||
// The parser expects the lexer to return 0 on EOF.
|
||||
const lexEOF = 0
|
||||
|
||||
// The parser uses the type <prefix>Lex as a lexer. It must provide
|
||||
// the methods Lex(*<prefix>SymType) int and Error(string).
|
||||
type hclLex struct {
|
||||
Input string
|
||||
|
||||
lastNumber bool
|
||||
pos int
|
||||
width int
|
||||
col, line int
|
||||
lastCol, lastLine int
|
||||
err error
|
||||
}
|
||||
|
||||
// The parser calls this method to get each new token.
|
||||
func (x *hclLex) Lex(yylval *hclSymType) int {
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
// Ignore all whitespace except a newline which we handle
|
||||
// specially later.
|
||||
if unicode.IsSpace(c) {
|
||||
x.lastNumber = false
|
||||
continue
|
||||
}
|
||||
|
||||
// Consume all comments
|
||||
switch c {
|
||||
case '#':
|
||||
fallthrough
|
||||
case '/':
|
||||
// Starting comment
|
||||
if !x.consumeComment(c) {
|
||||
return lexEOF
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// If it is a number, lex the number
|
||||
if c >= '0' && c <= '9' {
|
||||
x.lastNumber = true
|
||||
x.backup()
|
||||
return x.lexNumber(yylval)
|
||||
}
|
||||
|
||||
// This is a hacky way to find 'e' and lex it, but it works.
|
||||
if x.lastNumber {
|
||||
switch c {
|
||||
case 'e':
|
||||
fallthrough
|
||||
case 'E':
|
||||
switch x.next() {
|
||||
case '+':
|
||||
return EPLUS
|
||||
case '-':
|
||||
return EMINUS
|
||||
default:
|
||||
x.backup()
|
||||
return EPLUS
|
||||
}
|
||||
}
|
||||
}
|
||||
x.lastNumber = false
|
||||
|
||||
switch c {
|
||||
case '.':
|
||||
return PERIOD
|
||||
case '-':
|
||||
return MINUS
|
||||
case ',':
|
||||
return COMMA
|
||||
case '=':
|
||||
return EQUAL
|
||||
case '[':
|
||||
return LEFTBRACKET
|
||||
case ']':
|
||||
return RIGHTBRACKET
|
||||
case '{':
|
||||
return LEFTBRACE
|
||||
case '}':
|
||||
return RIGHTBRACE
|
||||
case '"':
|
||||
return x.lexString(yylval)
|
||||
case '<':
|
||||
return x.lexHeredoc(yylval)
|
||||
default:
|
||||
x.backup()
|
||||
return x.lexId(yylval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (x *hclLex) consumeComment(c rune) bool {
|
||||
single := c == '#'
|
||||
if !single {
|
||||
c = x.next()
|
||||
if c != '/' && c != '*' {
|
||||
x.backup()
|
||||
x.createErr(fmt.Sprintf("comment expected, got '%c'", c))
|
||||
return false
|
||||
}
|
||||
|
||||
single = c == '/'
|
||||
}
|
||||
|
||||
nested := 1
|
||||
for {
|
||||
c = x.next()
|
||||
if c == lexEOF {
|
||||
x.backup()
|
||||
if single {
|
||||
// Single line comments can end with an EOF
|
||||
return true
|
||||
}
|
||||
|
||||
// Multi-line comments must end with a */
|
||||
x.createErr(fmt.Sprintf("end of multi-line comment expected, got EOF"))
|
||||
return false
|
||||
}
|
||||
|
||||
// Single line comments continue until a '\n'
|
||||
if single {
|
||||
if c == '\n' {
|
||||
return true
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
// Multi-line comments continue until a '*/'
|
||||
switch c {
|
||||
case '/':
|
||||
c = x.next()
|
||||
if c == '*' {
|
||||
nested++
|
||||
} else {
|
||||
x.backup()
|
||||
}
|
||||
case '*':
|
||||
c = x.next()
|
||||
if c == '/' {
|
||||
return true
|
||||
} else {
|
||||
x.backup()
|
||||
}
|
||||
default:
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lexId lexes an identifier
|
||||
func (x *hclLex) lexId(yylval *hclSymType) int {
|
||||
var b bytes.Buffer
|
||||
first := true
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
break
|
||||
}
|
||||
|
||||
if !unicode.IsDigit(c) && !unicode.IsLetter(c) &&
|
||||
c != '_' && c != '-' && c != '.' {
|
||||
x.backup()
|
||||
|
||||
if first {
|
||||
x.createErr("Invalid identifier")
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
first = false
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
yylval.str = b.String()
|
||||
|
||||
switch yylval.str {
|
||||
case "true":
|
||||
yylval.b = true
|
||||
return BOOL
|
||||
case "false":
|
||||
yylval.b = false
|
||||
return BOOL
|
||||
case "null":
|
||||
return NULL
|
||||
}
|
||||
|
||||
return IDENTIFIER
|
||||
}
|
||||
|
||||
// lexHeredoc extracts a string from the input in heredoc format
|
||||
func (x *hclLex) lexHeredoc(yylval *hclSymType) int {
|
||||
if x.next() != '<' {
|
||||
x.createErr("Heredoc must start with <<")
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
// Now determine the marker
|
||||
var buf bytes.Buffer
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
// Newline signals the end of the marker
|
||||
if c == '\n' {
|
||||
break
|
||||
}
|
||||
|
||||
if _, err := buf.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
marker := buf.String()
|
||||
if marker == "" {
|
||||
x.createErr("Heredoc must have a marker, e.g. <<FOO")
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
check := true
|
||||
buf.Reset()
|
||||
for {
|
||||
c := x.next()
|
||||
|
||||
// If we're checking, then check to see if we see the marker
|
||||
if check {
|
||||
check = false
|
||||
|
||||
var cs []rune
|
||||
for _, r := range marker {
|
||||
if r != c {
|
||||
break
|
||||
}
|
||||
|
||||
cs = append(cs, c)
|
||||
c = x.next()
|
||||
}
|
||||
if len(cs) == len(marker) {
|
||||
break
|
||||
}
|
||||
|
||||
if len(cs) > 0 {
|
||||
for _, c := range cs {
|
||||
if _, err := buf.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if c == lexEOF {
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
// If we hit a newline, then reset to check
|
||||
if c == '\n' {
|
||||
check = true
|
||||
}
|
||||
|
||||
if _, err := buf.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
yylval.str = buf.String()
|
||||
return STRING
|
||||
}
|
||||
|
||||
// lexNumber lexes out a number
|
||||
func (x *hclLex) lexNumber(yylval *hclSymType) int {
|
||||
var b bytes.Buffer
|
||||
gotPeriod := false
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
break
|
||||
}
|
||||
|
||||
if c == '.' {
|
||||
if gotPeriod {
|
||||
x.backup()
|
||||
break
|
||||
}
|
||||
|
||||
gotPeriod = true
|
||||
} else if c < '0' || c > '9' {
|
||||
x.backup()
|
||||
break
|
||||
}
|
||||
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
x.createErr(fmt.Sprintf("Internal error: %s", err))
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
if !gotPeriod {
|
||||
v, err := strconv.ParseInt(b.String(), 0, 0)
|
||||
if err != nil {
|
||||
x.createErr(fmt.Sprintf("Expected number: %s", err))
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
yylval.num = int(v)
|
||||
return NUMBER
|
||||
}
|
||||
|
||||
f, err := strconv.ParseFloat(b.String(), 64)
|
||||
if err != nil {
|
||||
x.createErr(fmt.Sprintf("Expected float: %s", err))
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
yylval.f = float64(f)
|
||||
return FLOAT
|
||||
}
|
||||
|
||||
// lexString extracts a string from the input
|
||||
func (x *hclLex) lexString(yylval *hclSymType) int {
|
||||
braces := 0
|
||||
|
||||
var b bytes.Buffer
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
break
|
||||
}
|
||||
|
||||
// String end
|
||||
if c == '"' && braces == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
// If we hit a newline, then its an error
|
||||
if c == '\n' {
|
||||
x.createErr(fmt.Sprintf("Newline before string closed"))
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
// If we're escaping a quote, then escape the quote
|
||||
if c == '\\' {
|
||||
n := x.next()
|
||||
switch n {
|
||||
case '"':
|
||||
c = n
|
||||
case 'n':
|
||||
c = '\n'
|
||||
case '\\':
|
||||
c = n
|
||||
default:
|
||||
x.backup()
|
||||
}
|
||||
}
|
||||
|
||||
// If we're starting into variable, mark it
|
||||
if braces == 0 && c == '$' && x.peek() == '{' {
|
||||
braces += 1
|
||||
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
c = x.next()
|
||||
} else if braces > 0 && c == '{' {
|
||||
braces += 1
|
||||
}
|
||||
if braces > 0 && c == '}' {
|
||||
braces -= 1
|
||||
}
|
||||
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
yylval.str = b.String()
|
||||
return STRING
|
||||
}
|
||||
|
||||
// Return the next rune for the lexer.
|
||||
func (x *hclLex) next() rune {
|
||||
if int(x.pos) >= len(x.Input) {
|
||||
x.width = 0
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
r, w := utf8.DecodeRuneInString(x.Input[x.pos:])
|
||||
x.width = w
|
||||
x.pos += x.width
|
||||
|
||||
x.col += 1
|
||||
if x.line == 0 {
|
||||
x.line = 1
|
||||
}
|
||||
if r == '\n' {
|
||||
x.line += 1
|
||||
x.col = 0
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// peek returns but does not consume the next rune in the input
|
||||
func (x *hclLex) peek() rune {
|
||||
r := x.next()
|
||||
x.backup()
|
||||
return r
|
||||
}
|
||||
|
||||
// backup steps back one rune. Can only be called once per next.
|
||||
func (x *hclLex) backup() {
|
||||
x.col -= 1
|
||||
x.pos -= x.width
|
||||
}
|
||||
|
||||
// createErr records the given error
|
||||
func (x *hclLex) createErr(msg string) {
|
||||
x.err = fmt.Errorf("Line %d, column %d: %s", x.line, x.col, msg)
|
||||
}
|
||||
|
||||
// The parser calls this method on a parse error.
|
||||
func (x *hclLex) Error(s string) {
|
||||
x.createErr(s)
|
||||
}
|
||||
128
vendor/github.com/yudai/hcl/hcl/object.go
generated
vendored
Normal file
128
vendor/github.com/yudai/hcl/hcl/object.go
generated
vendored
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
package hcl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:generate stringer -type=ValueType
|
||||
|
||||
// ValueType is an enum represnting the type of a value in
|
||||
// a LiteralNode.
|
||||
type ValueType byte
|
||||
|
||||
const (
|
||||
ValueTypeUnknown ValueType = iota
|
||||
ValueTypeFloat
|
||||
ValueTypeInt
|
||||
ValueTypeString
|
||||
ValueTypeBool
|
||||
ValueTypeNil
|
||||
ValueTypeList
|
||||
ValueTypeObject
|
||||
)
|
||||
|
||||
// Object represents any element of HCL: an object itself, a list,
|
||||
// a literal, etc.
|
||||
type Object struct {
|
||||
Key string
|
||||
Type ValueType
|
||||
Value interface{}
|
||||
Next *Object
|
||||
}
|
||||
|
||||
// GoString is an implementation of the GoStringer interface.
|
||||
func (o *Object) GoString() string {
|
||||
return fmt.Sprintf("*%#v", *o)
|
||||
}
|
||||
|
||||
// Get gets all the objects that match the given key.
|
||||
//
|
||||
// It returns the resulting objects as a single Object structure with
|
||||
// the linked list populated.
|
||||
func (o *Object) Get(k string, insensitive bool) *Object {
|
||||
if o.Type != ValueTypeObject {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, o := range o.Elem(true) {
|
||||
if o.Key != k {
|
||||
if !insensitive || !strings.EqualFold(o.Key, k) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Elem returns all the elements that are part of this object.
|
||||
func (o *Object) Elem(expand bool) []*Object {
|
||||
if !expand {
|
||||
result := make([]*Object, 0, 1)
|
||||
current := o
|
||||
for current != nil {
|
||||
obj := *current
|
||||
obj.Next = nil
|
||||
result = append(result, &obj)
|
||||
|
||||
current = current.Next
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
if o.Value == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch o.Type {
|
||||
case ValueTypeList:
|
||||
return o.Value.([]*Object)
|
||||
case ValueTypeObject:
|
||||
result := make([]*Object, 0, 5)
|
||||
for _, obj := range o.Elem(false) {
|
||||
result = append(result, obj.Value.([]*Object)...)
|
||||
}
|
||||
return result
|
||||
default:
|
||||
return []*Object{o}
|
||||
}
|
||||
}
|
||||
|
||||
// Len returns the number of objects in this object structure.
|
||||
func (o *Object) Len() (i int) {
|
||||
current := o
|
||||
for current != nil {
|
||||
i += 1
|
||||
current = current.Next
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// ObjectList is a list of objects.
|
||||
type ObjectList []*Object
|
||||
|
||||
// Flat returns a flattened list structure of the objects.
|
||||
func (l ObjectList) Flat() []*Object {
|
||||
m := make(map[string]*Object)
|
||||
result := make([]*Object, 0, len(l))
|
||||
for _, obj := range l {
|
||||
prev, ok := m[obj.Key]
|
||||
if !ok {
|
||||
m[obj.Key] = obj
|
||||
result = append(result, obj)
|
||||
continue
|
||||
}
|
||||
|
||||
for prev.Next != nil {
|
||||
prev = prev.Next
|
||||
}
|
||||
prev.Next = obj
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
39
vendor/github.com/yudai/hcl/hcl/parse.go
generated
vendored
Normal file
39
vendor/github.com/yudai/hcl/hcl/parse.go
generated
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package hcl
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/hashicorp/go-multierror"
|
||||
)
|
||||
|
||||
// hclErrors are the errors built up from parsing. These should not
|
||||
// be accessed directly.
|
||||
var hclErrors []error
|
||||
var hclLock sync.Mutex
|
||||
var hclResult *Object
|
||||
|
||||
// Parse parses the given string and returns the result.
|
||||
func Parse(v string) (*Object, error) {
|
||||
hclLock.Lock()
|
||||
defer hclLock.Unlock()
|
||||
hclErrors = nil
|
||||
hclResult = nil
|
||||
|
||||
// Parse
|
||||
lex := &hclLex{Input: v}
|
||||
hclParse(lex)
|
||||
|
||||
// If we have an error in the lexer itself, return it
|
||||
if lex.err != nil {
|
||||
return nil, lex.err
|
||||
}
|
||||
|
||||
// Build up the errors
|
||||
var err error
|
||||
if len(hclErrors) > 0 {
|
||||
err = &multierror.Error{Errors: hclErrors}
|
||||
hclResult = nil
|
||||
}
|
||||
|
||||
return hclResult, err
|
||||
}
|
||||
281
vendor/github.com/yudai/hcl/hcl/parse.y
generated
vendored
Normal file
281
vendor/github.com/yudai/hcl/hcl/parse.y
generated
vendored
Normal file
|
|
@ -0,0 +1,281 @@
|
|||
// This is the yacc input for creating the parser for HCL.
|
||||
|
||||
%{
|
||||
package hcl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
b bool
|
||||
f float64
|
||||
num int
|
||||
str string
|
||||
obj *Object
|
||||
objlist []*Object
|
||||
}
|
||||
|
||||
%type <f> float
|
||||
%type <num> int
|
||||
%type <objlist> list listitems objectlist
|
||||
%type <obj> block number object objectitem
|
||||
%type <obj> listitem
|
||||
%type <str> blockId exp objectkey
|
||||
|
||||
%token <b> BOOL
|
||||
%token <f> FLOAT
|
||||
%token <num> NUMBER
|
||||
%token <str> COMMA IDENTIFIER EQUAL NEWLINE STRING MINUS
|
||||
%token <str> LEFTBRACE RIGHTBRACE LEFTBRACKET RIGHTBRACKET PERIOD
|
||||
%token <str> EPLUS EMINUS
|
||||
%token <str> NULL
|
||||
|
||||
%%
|
||||
|
||||
top:
|
||||
{
|
||||
hclResult = &Object{Type: ValueTypeObject}
|
||||
}
|
||||
| objectlist
|
||||
{
|
||||
hclResult = &Object{
|
||||
Type: ValueTypeObject,
|
||||
Value: ObjectList($1).Flat(),
|
||||
}
|
||||
}
|
||||
|
||||
objectlist:
|
||||
objectitem
|
||||
{
|
||||
$$ = []*Object{$1}
|
||||
}
|
||||
| objectlist objectitem
|
||||
{
|
||||
$$ = append($1, $2)
|
||||
}
|
||||
|
||||
object:
|
||||
LEFTBRACE objectlist RIGHTBRACE
|
||||
{
|
||||
$$ = &Object{
|
||||
Type: ValueTypeObject,
|
||||
Value: ObjectList($2).Flat(),
|
||||
}
|
||||
}
|
||||
| LEFTBRACE RIGHTBRACE
|
||||
{
|
||||
$$ = &Object{
|
||||
Type: ValueTypeObject,
|
||||
}
|
||||
}
|
||||
|
||||
objectkey:
|
||||
IDENTIFIER
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
| STRING
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
|
||||
objectitem:
|
||||
objectkey EQUAL number
|
||||
{
|
||||
$$ = $3
|
||||
$$.Key = $1
|
||||
}
|
||||
| objectkey EQUAL BOOL
|
||||
{
|
||||
$$ = &Object{
|
||||
Key: $1,
|
||||
Type: ValueTypeBool,
|
||||
Value: $3,
|
||||
}
|
||||
}
|
||||
| objectkey EQUAL NULL
|
||||
{
|
||||
$$ = &Object{
|
||||
Key: $1,
|
||||
Type: ValueTypeNil,
|
||||
}
|
||||
}
|
||||
| objectkey EQUAL STRING
|
||||
{
|
||||
$$ = &Object{
|
||||
Key: $1,
|
||||
Type: ValueTypeString,
|
||||
Value: $3,
|
||||
}
|
||||
}
|
||||
| objectkey EQUAL object
|
||||
{
|
||||
$3.Key = $1
|
||||
$$ = $3
|
||||
}
|
||||
| objectkey EQUAL list
|
||||
{
|
||||
$$ = &Object{
|
||||
Key: $1,
|
||||
Type: ValueTypeList,
|
||||
Value: $3,
|
||||
}
|
||||
}
|
||||
| block
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
|
||||
block:
|
||||
blockId object
|
||||
{
|
||||
$2.Key = $1
|
||||
$$ = $2
|
||||
}
|
||||
| blockId block
|
||||
{
|
||||
$$ = &Object{
|
||||
Key: $1,
|
||||
Type: ValueTypeObject,
|
||||
Value: []*Object{$2},
|
||||
}
|
||||
}
|
||||
|
||||
blockId:
|
||||
IDENTIFIER
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
| STRING
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
|
||||
list:
|
||||
LEFTBRACKET listitems RIGHTBRACKET
|
||||
{
|
||||
$$ = $2
|
||||
}
|
||||
| LEFTBRACKET listitems COMMA RIGHTBRACKET
|
||||
{
|
||||
$$ = $2
|
||||
}
|
||||
| LEFTBRACKET RIGHTBRACKET
|
||||
{
|
||||
$$ = nil
|
||||
}
|
||||
|
||||
listitems:
|
||||
listitem
|
||||
{
|
||||
$$ = []*Object{$1}
|
||||
}
|
||||
| listitems COMMA listitem
|
||||
{
|
||||
$$ = append($1, $3)
|
||||
}
|
||||
|
||||
listitem:
|
||||
number
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
| STRING
|
||||
{
|
||||
$$ = &Object{
|
||||
Type: ValueTypeString,
|
||||
Value: $1,
|
||||
}
|
||||
}
|
||||
| BOOL
|
||||
{
|
||||
$$ = &Object{
|
||||
Type: ValueTypeBool,
|
||||
Value: $1,
|
||||
}
|
||||
}
|
||||
| NULL
|
||||
{
|
||||
$$ = &Object{
|
||||
Type: ValueTypeNil,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
number:
|
||||
int
|
||||
{
|
||||
$$ = &Object{
|
||||
Type: ValueTypeInt,
|
||||
Value: $1,
|
||||
}
|
||||
}
|
||||
| float
|
||||
{
|
||||
$$ = &Object{
|
||||
Type: ValueTypeFloat,
|
||||
Value: $1,
|
||||
}
|
||||
}
|
||||
| int exp
|
||||
{
|
||||
fs := fmt.Sprintf("%d%s", $1, $2)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
$$ = &Object{
|
||||
Type: ValueTypeFloat,
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
| float exp
|
||||
{
|
||||
fs := fmt.Sprintf("%f%s", $1, $2)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
$$ = &Object{
|
||||
Type: ValueTypeFloat,
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
|
||||
int:
|
||||
MINUS int
|
||||
{
|
||||
$$ = $2 * -1
|
||||
}
|
||||
| NUMBER
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
|
||||
float:
|
||||
MINUS float
|
||||
{
|
||||
$$ = $2 * -1
|
||||
}
|
||||
| FLOAT
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
|
||||
exp:
|
||||
EPLUS NUMBER
|
||||
{
|
||||
$$ = "e" + strconv.FormatInt(int64($2), 10)
|
||||
}
|
||||
| EMINUS NUMBER
|
||||
{
|
||||
$$ = "e-" + strconv.FormatInt(int64($2), 10)
|
||||
}
|
||||
|
||||
%%
|
||||
16
vendor/github.com/yudai/hcl/hcl/valuetype_string.go
generated
vendored
Normal file
16
vendor/github.com/yudai/hcl/hcl/valuetype_string.go
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// generated by stringer -type=ValueType; DO NOT EDIT
|
||||
|
||||
package hcl
|
||||
|
||||
import "fmt"
|
||||
|
||||
const _ValueType_name = "ValueTypeUnknownValueTypeFloatValueTypeIntValueTypeStringValueTypeBoolValueTypeNilValueTypeListValueTypeObject"
|
||||
|
||||
var _ValueType_index = [...]uint8{0, 16, 30, 42, 57, 70, 82, 95, 110}
|
||||
|
||||
func (i ValueType) String() string {
|
||||
if i >= ValueType(len(_ValueType_index)-1) {
|
||||
return fmt.Sprintf("ValueType(%d)", i)
|
||||
}
|
||||
return _ValueType_name[_ValueType_index[i]:_ValueType_index[i+1]]
|
||||
}
|
||||
790
vendor/github.com/yudai/hcl/hcl/y.go
generated
vendored
Normal file
790
vendor/github.com/yudai/hcl/hcl/y.go
generated
vendored
Normal file
|
|
@ -0,0 +1,790 @@
|
|||
//line parse.y:4
|
||||
package hcl
|
||||
|
||||
import __yyfmt__ "fmt"
|
||||
|
||||
//line parse.y:4
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
//line parse.y:13
|
||||
type hclSymType struct {
|
||||
yys int
|
||||
b bool
|
||||
f float64
|
||||
num int
|
||||
str string
|
||||
obj *Object
|
||||
objlist []*Object
|
||||
}
|
||||
|
||||
const BOOL = 57346
|
||||
const FLOAT = 57347
|
||||
const NUMBER = 57348
|
||||
const COMMA = 57349
|
||||
const IDENTIFIER = 57350
|
||||
const EQUAL = 57351
|
||||
const NEWLINE = 57352
|
||||
const STRING = 57353
|
||||
const MINUS = 57354
|
||||
const LEFTBRACE = 57355
|
||||
const RIGHTBRACE = 57356
|
||||
const LEFTBRACKET = 57357
|
||||
const RIGHTBRACKET = 57358
|
||||
const PERIOD = 57359
|
||||
const EPLUS = 57360
|
||||
const EMINUS = 57361
|
||||
const NULL = 57362
|
||||
|
||||
var hclToknames = [...]string{
|
||||
"$end",
|
||||
"error",
|
||||
"$unk",
|
||||
"BOOL",
|
||||
"FLOAT",
|
||||
"NUMBER",
|
||||
"COMMA",
|
||||
"IDENTIFIER",
|
||||
"EQUAL",
|
||||
"NEWLINE",
|
||||
"STRING",
|
||||
"MINUS",
|
||||
"LEFTBRACE",
|
||||
"RIGHTBRACE",
|
||||
"LEFTBRACKET",
|
||||
"RIGHTBRACKET",
|
||||
"PERIOD",
|
||||
"EPLUS",
|
||||
"EMINUS",
|
||||
"NULL",
|
||||
}
|
||||
var hclStatenames = [...]string{}
|
||||
|
||||
const hclEofCode = 1
|
||||
const hclErrCode = 2
|
||||
const hclMaxDepth = 200
|
||||
|
||||
//line parse.y:281
|
||||
|
||||
//line yacctab:1
|
||||
var hclExca = [...]int{
|
||||
-1, 1,
|
||||
1, -1,
|
||||
-2, 0,
|
||||
-1, 6,
|
||||
9, 7,
|
||||
-2, 18,
|
||||
-1, 7,
|
||||
9, 8,
|
||||
-2, 19,
|
||||
}
|
||||
|
||||
const hclNprod = 39
|
||||
const hclPrivate = 57344
|
||||
|
||||
var hclTokenNames []string
|
||||
var hclStates []string
|
||||
|
||||
const hclLast = 69
|
||||
|
||||
var hclAct = [...]int{
|
||||
|
||||
36, 3, 22, 30, 9, 17, 27, 26, 31, 32,
|
||||
45, 23, 19, 25, 13, 10, 24, 39, 27, 26,
|
||||
6, 18, 47, 7, 38, 25, 43, 33, 41, 48,
|
||||
9, 46, 44, 40, 39, 27, 26, 42, 5, 1,
|
||||
14, 38, 25, 15, 2, 13, 35, 12, 49, 6,
|
||||
40, 4, 7, 27, 26, 29, 11, 37, 28, 6,
|
||||
25, 8, 7, 34, 21, 0, 0, 20, 16,
|
||||
}
|
||||
var hclPact = [...]int{
|
||||
|
||||
51, -1000, 51, -1000, 6, -1000, -1000, -1000, 32, -1000,
|
||||
1, -1000, -1000, 41, -1000, -1000, -1000, -1000, -1000, -1000,
|
||||
-1000, -1000, -10, -10, 30, 48, -1000, -1000, 12, -1000,
|
||||
-1000, 26, 4, -1000, 15, -1000, -1000, -1000, -1000, -1000,
|
||||
-1000, -1000, -1000, -1000, -1000, -1000, -1000, 13, -1000, -1000,
|
||||
}
|
||||
var hclPgo = [...]int{
|
||||
|
||||
0, 11, 2, 64, 63, 44, 38, 57, 56, 1,
|
||||
0, 61, 3, 51, 39,
|
||||
}
|
||||
var hclR1 = [...]int{
|
||||
|
||||
0, 14, 14, 5, 5, 8, 8, 13, 13, 9,
|
||||
9, 9, 9, 9, 9, 9, 6, 6, 11, 11,
|
||||
3, 3, 3, 4, 4, 10, 10, 10, 10, 7,
|
||||
7, 7, 7, 2, 2, 1, 1, 12, 12,
|
||||
}
|
||||
var hclR2 = [...]int{
|
||||
|
||||
0, 0, 1, 1, 2, 3, 2, 1, 1, 3,
|
||||
3, 3, 3, 3, 3, 1, 2, 2, 1, 1,
|
||||
3, 4, 2, 1, 3, 1, 1, 1, 1, 1,
|
||||
1, 2, 2, 2, 1, 2, 1, 2, 2,
|
||||
}
|
||||
var hclChk = [...]int{
|
||||
|
||||
-1000, -14, -5, -9, -13, -6, 8, 11, -11, -9,
|
||||
9, -8, -6, 13, 8, 11, -7, 4, 20, 11,
|
||||
-8, -3, -2, -1, 15, 12, 6, 5, -5, 14,
|
||||
-12, 18, 19, -12, -4, 16, -10, -7, 11, 4,
|
||||
20, -2, -1, 14, 6, 6, 16, 7, 16, -10,
|
||||
}
|
||||
var hclDef = [...]int{
|
||||
|
||||
1, -2, 2, 3, 0, 15, -2, -2, 0, 4,
|
||||
0, 16, 17, 0, 18, 19, 9, 10, 11, 12,
|
||||
13, 14, 29, 30, 0, 0, 34, 36, 0, 6,
|
||||
31, 0, 0, 32, 0, 22, 23, 25, 26, 27,
|
||||
28, 33, 35, 5, 37, 38, 20, 0, 21, 24,
|
||||
}
|
||||
var hclTok1 = [...]int{
|
||||
|
||||
1,
|
||||
}
|
||||
var hclTok2 = [...]int{
|
||||
|
||||
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20,
|
||||
}
|
||||
var hclTok3 = [...]int{
|
||||
0,
|
||||
}
|
||||
|
||||
var hclErrorMessages = [...]struct {
|
||||
state int
|
||||
token int
|
||||
msg string
|
||||
}{}
|
||||
|
||||
//line yaccpar:1
|
||||
|
||||
/* parser for yacc output */
|
||||
|
||||
var (
|
||||
hclDebug = 0
|
||||
hclErrorVerbose = false
|
||||
)
|
||||
|
||||
type hclLexer interface {
|
||||
Lex(lval *hclSymType) int
|
||||
Error(s string)
|
||||
}
|
||||
|
||||
type hclParser interface {
|
||||
Parse(hclLexer) int
|
||||
Lookahead() int
|
||||
}
|
||||
|
||||
type hclParserImpl struct {
|
||||
lookahead func() int
|
||||
}
|
||||
|
||||
func (p *hclParserImpl) Lookahead() int {
|
||||
return p.lookahead()
|
||||
}
|
||||
|
||||
func hclNewParser() hclParser {
|
||||
p := &hclParserImpl{
|
||||
lookahead: func() int { return -1 },
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
const hclFlag = -1000
|
||||
|
||||
func hclTokname(c int) string {
|
||||
if c >= 1 && c-1 < len(hclToknames) {
|
||||
if hclToknames[c-1] != "" {
|
||||
return hclToknames[c-1]
|
||||
}
|
||||
}
|
||||
return __yyfmt__.Sprintf("tok-%v", c)
|
||||
}
|
||||
|
||||
func hclStatname(s int) string {
|
||||
if s >= 0 && s < len(hclStatenames) {
|
||||
if hclStatenames[s] != "" {
|
||||
return hclStatenames[s]
|
||||
}
|
||||
}
|
||||
return __yyfmt__.Sprintf("state-%v", s)
|
||||
}
|
||||
|
||||
func hclErrorMessage(state, lookAhead int) string {
|
||||
const TOKSTART = 4
|
||||
|
||||
if !hclErrorVerbose {
|
||||
return "syntax error"
|
||||
}
|
||||
|
||||
for _, e := range hclErrorMessages {
|
||||
if e.state == state && e.token == lookAhead {
|
||||
return "syntax error: " + e.msg
|
||||
}
|
||||
}
|
||||
|
||||
res := "syntax error: unexpected " + hclTokname(lookAhead)
|
||||
|
||||
// To match Bison, suggest at most four expected tokens.
|
||||
expected := make([]int, 0, 4)
|
||||
|
||||
// Look for shiftable tokens.
|
||||
base := hclPact[state]
|
||||
for tok := TOKSTART; tok-1 < len(hclToknames); tok++ {
|
||||
if n := base + tok; n >= 0 && n < hclLast && hclChk[hclAct[n]] == tok {
|
||||
if len(expected) == cap(expected) {
|
||||
return res
|
||||
}
|
||||
expected = append(expected, tok)
|
||||
}
|
||||
}
|
||||
|
||||
if hclDef[state] == -2 {
|
||||
i := 0
|
||||
for hclExca[i] != -1 || hclExca[i+1] != state {
|
||||
i += 2
|
||||
}
|
||||
|
||||
// Look for tokens that we accept or reduce.
|
||||
for i += 2; hclExca[i] >= 0; i += 2 {
|
||||
tok := hclExca[i]
|
||||
if tok < TOKSTART || hclExca[i+1] == 0 {
|
||||
continue
|
||||
}
|
||||
if len(expected) == cap(expected) {
|
||||
return res
|
||||
}
|
||||
expected = append(expected, tok)
|
||||
}
|
||||
|
||||
// If the default action is to accept or reduce, give up.
|
||||
if hclExca[i+1] != 0 {
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
for i, tok := range expected {
|
||||
if i == 0 {
|
||||
res += ", expecting "
|
||||
} else {
|
||||
res += " or "
|
||||
}
|
||||
res += hclTokname(tok)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func hcllex1(lex hclLexer, lval *hclSymType) (char, token int) {
|
||||
token = 0
|
||||
char = lex.Lex(lval)
|
||||
if char <= 0 {
|
||||
token = hclTok1[0]
|
||||
goto out
|
||||
}
|
||||
if char < len(hclTok1) {
|
||||
token = hclTok1[char]
|
||||
goto out
|
||||
}
|
||||
if char >= hclPrivate {
|
||||
if char < hclPrivate+len(hclTok2) {
|
||||
token = hclTok2[char-hclPrivate]
|
||||
goto out
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(hclTok3); i += 2 {
|
||||
token = hclTok3[i+0]
|
||||
if token == char {
|
||||
token = hclTok3[i+1]
|
||||
goto out
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if token == 0 {
|
||||
token = hclTok2[1] /* unknown char */
|
||||
}
|
||||
if hclDebug >= 3 {
|
||||
__yyfmt__.Printf("lex %s(%d)\n", hclTokname(token), uint(char))
|
||||
}
|
||||
return char, token
|
||||
}
|
||||
|
||||
func hclParse(hcllex hclLexer) int {
|
||||
return hclNewParser().Parse(hcllex)
|
||||
}
|
||||
|
||||
func (hclrcvr *hclParserImpl) Parse(hcllex hclLexer) int {
|
||||
var hcln int
|
||||
var hcllval hclSymType
|
||||
var hclVAL hclSymType
|
||||
var hclDollar []hclSymType
|
||||
_ = hclDollar // silence set and not used
|
||||
hclS := make([]hclSymType, hclMaxDepth)
|
||||
|
||||
Nerrs := 0 /* number of errors */
|
||||
Errflag := 0 /* error recovery flag */
|
||||
hclstate := 0
|
||||
hclchar := -1
|
||||
hcltoken := -1 // hclchar translated into internal numbering
|
||||
hclrcvr.lookahead = func() int { return hclchar }
|
||||
defer func() {
|
||||
// Make sure we report no lookahead when not parsing.
|
||||
hclstate = -1
|
||||
hclchar = -1
|
||||
hcltoken = -1
|
||||
}()
|
||||
hclp := -1
|
||||
goto hclstack
|
||||
|
||||
ret0:
|
||||
return 0
|
||||
|
||||
ret1:
|
||||
return 1
|
||||
|
||||
hclstack:
|
||||
/* put a state and value onto the stack */
|
||||
if hclDebug >= 4 {
|
||||
__yyfmt__.Printf("char %v in %v\n", hclTokname(hcltoken), hclStatname(hclstate))
|
||||
}
|
||||
|
||||
hclp++
|
||||
if hclp >= len(hclS) {
|
||||
nyys := make([]hclSymType, len(hclS)*2)
|
||||
copy(nyys, hclS)
|
||||
hclS = nyys
|
||||
}
|
||||
hclS[hclp] = hclVAL
|
||||
hclS[hclp].yys = hclstate
|
||||
|
||||
hclnewstate:
|
||||
hcln = hclPact[hclstate]
|
||||
if hcln <= hclFlag {
|
||||
goto hcldefault /* simple state */
|
||||
}
|
||||
if hclchar < 0 {
|
||||
hclchar, hcltoken = hcllex1(hcllex, &hcllval)
|
||||
}
|
||||
hcln += hcltoken
|
||||
if hcln < 0 || hcln >= hclLast {
|
||||
goto hcldefault
|
||||
}
|
||||
hcln = hclAct[hcln]
|
||||
if hclChk[hcln] == hcltoken { /* valid shift */
|
||||
hclchar = -1
|
||||
hcltoken = -1
|
||||
hclVAL = hcllval
|
||||
hclstate = hcln
|
||||
if Errflag > 0 {
|
||||
Errflag--
|
||||
}
|
||||
goto hclstack
|
||||
}
|
||||
|
||||
hcldefault:
|
||||
/* default state action */
|
||||
hcln = hclDef[hclstate]
|
||||
if hcln == -2 {
|
||||
if hclchar < 0 {
|
||||
hclchar, hcltoken = hcllex1(hcllex, &hcllval)
|
||||
}
|
||||
|
||||
/* look through exception table */
|
||||
xi := 0
|
||||
for {
|
||||
if hclExca[xi+0] == -1 && hclExca[xi+1] == hclstate {
|
||||
break
|
||||
}
|
||||
xi += 2
|
||||
}
|
||||
for xi += 2; ; xi += 2 {
|
||||
hcln = hclExca[xi+0]
|
||||
if hcln < 0 || hcln == hcltoken {
|
||||
break
|
||||
}
|
||||
}
|
||||
hcln = hclExca[xi+1]
|
||||
if hcln < 0 {
|
||||
goto ret0
|
||||
}
|
||||
}
|
||||
if hcln == 0 {
|
||||
/* error ... attempt to resume parsing */
|
||||
switch Errflag {
|
||||
case 0: /* brand new error */
|
||||
hcllex.Error(hclErrorMessage(hclstate, hcltoken))
|
||||
Nerrs++
|
||||
if hclDebug >= 1 {
|
||||
__yyfmt__.Printf("%s", hclStatname(hclstate))
|
||||
__yyfmt__.Printf(" saw %s\n", hclTokname(hcltoken))
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case 1, 2: /* incompletely recovered error ... try again */
|
||||
Errflag = 3
|
||||
|
||||
/* find a state where "error" is a legal shift action */
|
||||
for hclp >= 0 {
|
||||
hcln = hclPact[hclS[hclp].yys] + hclErrCode
|
||||
if hcln >= 0 && hcln < hclLast {
|
||||
hclstate = hclAct[hcln] /* simulate a shift of "error" */
|
||||
if hclChk[hclstate] == hclErrCode {
|
||||
goto hclstack
|
||||
}
|
||||
}
|
||||
|
||||
/* the current p has no shift on "error", pop stack */
|
||||
if hclDebug >= 2 {
|
||||
__yyfmt__.Printf("error recovery pops state %d\n", hclS[hclp].yys)
|
||||
}
|
||||
hclp--
|
||||
}
|
||||
/* there is no state on the stack with an error shift ... abort */
|
||||
goto ret1
|
||||
|
||||
case 3: /* no shift yet; clobber input char */
|
||||
if hclDebug >= 2 {
|
||||
__yyfmt__.Printf("error recovery discards %s\n", hclTokname(hcltoken))
|
||||
}
|
||||
if hcltoken == hclEofCode {
|
||||
goto ret1
|
||||
}
|
||||
hclchar = -1
|
||||
hcltoken = -1
|
||||
goto hclnewstate /* try again in the same state */
|
||||
}
|
||||
}
|
||||
|
||||
/* reduction by production hcln */
|
||||
if hclDebug >= 2 {
|
||||
__yyfmt__.Printf("reduce %v in:\n\t%v\n", hcln, hclStatname(hclstate))
|
||||
}
|
||||
|
||||
hclnt := hcln
|
||||
hclpt := hclp
|
||||
_ = hclpt // guard against "declared and not used"
|
||||
|
||||
hclp -= hclR2[hcln]
|
||||
// hclp is now the index of $0. Perform the default action. Iff the
|
||||
// reduced production is ε, $1 is possibly out of range.
|
||||
if hclp+1 >= len(hclS) {
|
||||
nyys := make([]hclSymType, len(hclS)*2)
|
||||
copy(nyys, hclS)
|
||||
hclS = nyys
|
||||
}
|
||||
hclVAL = hclS[hclp+1]
|
||||
|
||||
/* consult goto table to find next state */
|
||||
hcln = hclR1[hcln]
|
||||
hclg := hclPgo[hcln]
|
||||
hclj := hclg + hclS[hclp].yys + 1
|
||||
|
||||
if hclj >= hclLast {
|
||||
hclstate = hclAct[hclg]
|
||||
} else {
|
||||
hclstate = hclAct[hclj]
|
||||
if hclChk[hclstate] != -hcln {
|
||||
hclstate = hclAct[hclg]
|
||||
}
|
||||
}
|
||||
// dummy call; replaced with literal code
|
||||
switch hclnt {
|
||||
|
||||
case 1:
|
||||
hclDollar = hclS[hclpt-0 : hclpt+1]
|
||||
//line parse.y:40
|
||||
{
|
||||
hclResult = &Object{Type: ValueTypeObject}
|
||||
}
|
||||
case 2:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:44
|
||||
{
|
||||
hclResult = &Object{
|
||||
Type: ValueTypeObject,
|
||||
Value: ObjectList(hclDollar[1].objlist).Flat(),
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:53
|
||||
{
|
||||
hclVAL.objlist = []*Object{hclDollar[1].obj}
|
||||
}
|
||||
case 4:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:57
|
||||
{
|
||||
hclVAL.objlist = append(hclDollar[1].objlist, hclDollar[2].obj)
|
||||
}
|
||||
case 5:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:63
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeObject,
|
||||
Value: ObjectList(hclDollar[2].objlist).Flat(),
|
||||
}
|
||||
}
|
||||
case 6:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:70
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeObject,
|
||||
}
|
||||
}
|
||||
case 7:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:78
|
||||
{
|
||||
hclVAL.str = hclDollar[1].str
|
||||
}
|
||||
case 8:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:82
|
||||
{
|
||||
hclVAL.str = hclDollar[1].str
|
||||
}
|
||||
case 9:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:88
|
||||
{
|
||||
hclVAL.obj = hclDollar[3].obj
|
||||
hclVAL.obj.Key = hclDollar[1].str
|
||||
}
|
||||
case 10:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:93
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclDollar[1].str,
|
||||
Type: ValueTypeBool,
|
||||
Value: hclDollar[3].b,
|
||||
}
|
||||
}
|
||||
case 11:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:101
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclDollar[1].str,
|
||||
Type: ValueTypeNil,
|
||||
}
|
||||
}
|
||||
case 12:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:108
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclDollar[1].str,
|
||||
Type: ValueTypeString,
|
||||
Value: hclDollar[3].str,
|
||||
}
|
||||
}
|
||||
case 13:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:116
|
||||
{
|
||||
hclDollar[3].obj.Key = hclDollar[1].str
|
||||
hclVAL.obj = hclDollar[3].obj
|
||||
}
|
||||
case 14:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:121
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclDollar[1].str,
|
||||
Type: ValueTypeList,
|
||||
Value: hclDollar[3].objlist,
|
||||
}
|
||||
}
|
||||
case 15:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:129
|
||||
{
|
||||
hclVAL.obj = hclDollar[1].obj
|
||||
}
|
||||
case 16:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:135
|
||||
{
|
||||
hclDollar[2].obj.Key = hclDollar[1].str
|
||||
hclVAL.obj = hclDollar[2].obj
|
||||
}
|
||||
case 17:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:140
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Key: hclDollar[1].str,
|
||||
Type: ValueTypeObject,
|
||||
Value: []*Object{hclDollar[2].obj},
|
||||
}
|
||||
}
|
||||
case 18:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:150
|
||||
{
|
||||
hclVAL.str = hclDollar[1].str
|
||||
}
|
||||
case 19:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:154
|
||||
{
|
||||
hclVAL.str = hclDollar[1].str
|
||||
}
|
||||
case 20:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:160
|
||||
{
|
||||
hclVAL.objlist = hclDollar[2].objlist
|
||||
}
|
||||
case 21:
|
||||
hclDollar = hclS[hclpt-4 : hclpt+1]
|
||||
//line parse.y:164
|
||||
{
|
||||
hclVAL.objlist = hclDollar[2].objlist
|
||||
}
|
||||
case 22:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:168
|
||||
{
|
||||
hclVAL.objlist = nil
|
||||
}
|
||||
case 23:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:174
|
||||
{
|
||||
hclVAL.objlist = []*Object{hclDollar[1].obj}
|
||||
}
|
||||
case 24:
|
||||
hclDollar = hclS[hclpt-3 : hclpt+1]
|
||||
//line parse.y:178
|
||||
{
|
||||
hclVAL.objlist = append(hclDollar[1].objlist, hclDollar[3].obj)
|
||||
}
|
||||
case 25:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:184
|
||||
{
|
||||
hclVAL.obj = hclDollar[1].obj
|
||||
}
|
||||
case 26:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:188
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeString,
|
||||
Value: hclDollar[1].str,
|
||||
}
|
||||
}
|
||||
case 27:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:195
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeBool,
|
||||
Value: hclDollar[1].b,
|
||||
}
|
||||
}
|
||||
case 28:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:202
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeNil,
|
||||
}
|
||||
}
|
||||
case 29:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:211
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeInt,
|
||||
Value: hclDollar[1].num,
|
||||
}
|
||||
}
|
||||
case 30:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:218
|
||||
{
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeFloat,
|
||||
Value: hclDollar[1].f,
|
||||
}
|
||||
}
|
||||
case 31:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:225
|
||||
{
|
||||
fs := fmt.Sprintf("%d%s", hclDollar[1].num, hclDollar[2].str)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeFloat,
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
case 32:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:238
|
||||
{
|
||||
fs := fmt.Sprintf("%f%s", hclDollar[1].f, hclDollar[2].str)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
hclVAL.obj = &Object{
|
||||
Type: ValueTypeFloat,
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
case 33:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:253
|
||||
{
|
||||
hclVAL.num = hclDollar[2].num * -1
|
||||
}
|
||||
case 34:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:257
|
||||
{
|
||||
hclVAL.num = hclDollar[1].num
|
||||
}
|
||||
case 35:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:263
|
||||
{
|
||||
hclVAL.f = hclDollar[2].f * -1
|
||||
}
|
||||
case 36:
|
||||
hclDollar = hclS[hclpt-1 : hclpt+1]
|
||||
//line parse.y:267
|
||||
{
|
||||
hclVAL.f = hclDollar[1].f
|
||||
}
|
||||
case 37:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:273
|
||||
{
|
||||
hclVAL.str = "e" + strconv.FormatInt(int64(hclDollar[2].num), 10)
|
||||
}
|
||||
case 38:
|
||||
hclDollar = hclS[hclpt-2 : hclpt+1]
|
||||
//line parse.y:277
|
||||
{
|
||||
hclVAL.str = "e-" + strconv.FormatInt(int64(hclDollar[2].num), 10)
|
||||
}
|
||||
}
|
||||
goto hclstack /* stack new state and value */
|
||||
}
|
||||
256
vendor/github.com/yudai/hcl/json/lex.go
generated
vendored
Normal file
256
vendor/github.com/yudai/hcl/json/lex.go
generated
vendored
Normal file
|
|
@ -0,0 +1,256 @@
|
|||
package json
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
//go:generate go tool yacc -p "json" parse.y
|
||||
|
||||
// This marks the end of the lexer
|
||||
const lexEOF = 0
|
||||
|
||||
// The parser uses the type <prefix>Lex as a lexer. It must provide
|
||||
// the methods Lex(*<prefix>SymType) int and Error(string).
|
||||
type jsonLex struct {
|
||||
Input string
|
||||
|
||||
pos int
|
||||
width int
|
||||
col, line int
|
||||
err error
|
||||
}
|
||||
|
||||
// The parser calls this method to get each new token.
|
||||
func (x *jsonLex) Lex(yylval *jsonSymType) int {
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
// Ignore all whitespace except a newline which we handle
|
||||
// specially later.
|
||||
if unicode.IsSpace(c) {
|
||||
continue
|
||||
}
|
||||
|
||||
// If it is a number, lex the number
|
||||
if c >= '0' && c <= '9' {
|
||||
x.backup()
|
||||
return x.lexNumber(yylval)
|
||||
}
|
||||
|
||||
switch c {
|
||||
case 'e':
|
||||
fallthrough
|
||||
case 'E':
|
||||
switch x.next() {
|
||||
case '+':
|
||||
return EPLUS
|
||||
case '-':
|
||||
return EMINUS
|
||||
default:
|
||||
x.backup()
|
||||
return EPLUS
|
||||
}
|
||||
case '.':
|
||||
return PERIOD
|
||||
case '-':
|
||||
return MINUS
|
||||
case ':':
|
||||
return COLON
|
||||
case ',':
|
||||
return COMMA
|
||||
case '[':
|
||||
return LEFTBRACKET
|
||||
case ']':
|
||||
return RIGHTBRACKET
|
||||
case '{':
|
||||
return LEFTBRACE
|
||||
case '}':
|
||||
return RIGHTBRACE
|
||||
case '"':
|
||||
return x.lexString(yylval)
|
||||
default:
|
||||
x.backup()
|
||||
return x.lexId(yylval)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// lexId lexes an identifier
|
||||
func (x *jsonLex) lexId(yylval *jsonSymType) int {
|
||||
var b bytes.Buffer
|
||||
first := true
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
break
|
||||
}
|
||||
|
||||
if !unicode.IsDigit(c) && !unicode.IsLetter(c) && c != '_' && c != '-' {
|
||||
x.backup()
|
||||
|
||||
if first {
|
||||
x.createErr("Invalid identifier")
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
first = false
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
switch v := b.String(); v {
|
||||
case "true":
|
||||
return TRUE
|
||||
case "false":
|
||||
return FALSE
|
||||
case "null":
|
||||
return NULL
|
||||
default:
|
||||
x.createErr(fmt.Sprintf("Invalid identifier: %s", v))
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
// lexNumber lexes out a number
|
||||
func (x *jsonLex) lexNumber(yylval *jsonSymType) int {
|
||||
var b bytes.Buffer
|
||||
gotPeriod := false
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
break
|
||||
}
|
||||
|
||||
if c == '.' {
|
||||
if gotPeriod {
|
||||
x.backup()
|
||||
break
|
||||
}
|
||||
|
||||
gotPeriod = true
|
||||
} else if c < '0' || c > '9' {
|
||||
x.backup()
|
||||
break
|
||||
}
|
||||
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
x.createErr(fmt.Sprintf("Internal error: %s", err))
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
if !gotPeriod {
|
||||
v, err := strconv.ParseInt(b.String(), 0, 0)
|
||||
if err != nil {
|
||||
x.createErr(fmt.Sprintf("Expected number: %s", err))
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
yylval.num = int(v)
|
||||
return NUMBER
|
||||
}
|
||||
|
||||
f, err := strconv.ParseFloat(b.String(), 64)
|
||||
if err != nil {
|
||||
x.createErr(fmt.Sprintf("Expected float: %s", err))
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
yylval.f = float64(f)
|
||||
return FLOAT
|
||||
}
|
||||
|
||||
// lexString extracts a string from the input
|
||||
func (x *jsonLex) lexString(yylval *jsonSymType) int {
|
||||
var b bytes.Buffer
|
||||
for {
|
||||
c := x.next()
|
||||
if c == lexEOF {
|
||||
break
|
||||
}
|
||||
|
||||
// String end
|
||||
if c == '"' {
|
||||
break
|
||||
}
|
||||
|
||||
// If we're escaping a quote, then escape the quote
|
||||
if c == '\\' {
|
||||
n := x.next()
|
||||
switch n {
|
||||
case '"':
|
||||
c = n
|
||||
case 'n':
|
||||
c = '\n'
|
||||
case '\\':
|
||||
c = n
|
||||
default:
|
||||
x.backup()
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := b.WriteRune(c); err != nil {
|
||||
return lexEOF
|
||||
}
|
||||
}
|
||||
|
||||
yylval.str = b.String()
|
||||
return STRING
|
||||
}
|
||||
|
||||
// Return the next rune for the lexer.
|
||||
func (x *jsonLex) next() rune {
|
||||
if int(x.pos) >= len(x.Input) {
|
||||
x.width = 0
|
||||
return lexEOF
|
||||
}
|
||||
|
||||
r, w := utf8.DecodeRuneInString(x.Input[x.pos:])
|
||||
x.width = w
|
||||
x.pos += x.width
|
||||
|
||||
x.col += 1
|
||||
if x.line == 0 {
|
||||
x.line = 1
|
||||
}
|
||||
if r == '\n' {
|
||||
x.line += 1
|
||||
x.col = 0
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// peek returns but does not consume the next rune in the input
|
||||
func (x *jsonLex) peek() rune {
|
||||
r := x.next()
|
||||
x.backup()
|
||||
return r
|
||||
}
|
||||
|
||||
// backup steps back one rune. Can only be called once per next.
|
||||
func (x *jsonLex) backup() {
|
||||
x.col -= 1
|
||||
x.pos -= x.width
|
||||
}
|
||||
|
||||
// createErr records the given error
|
||||
func (x *jsonLex) createErr(msg string) {
|
||||
x.err = fmt.Errorf("Line %d, column %d: %s", x.line, x.col, msg)
|
||||
}
|
||||
|
||||
// The parser calls this method on a parse error.
|
||||
func (x *jsonLex) Error(s string) {
|
||||
x.createErr(s)
|
||||
}
|
||||
40
vendor/github.com/yudai/hcl/json/parse.go
generated
vendored
Normal file
40
vendor/github.com/yudai/hcl/json/parse.go
generated
vendored
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
package json
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/yudai/hcl/hcl"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
)
|
||||
|
||||
// jsonErrors are the errors built up from parsing. These should not
|
||||
// be accessed directly.
|
||||
var jsonErrors []error
|
||||
var jsonLock sync.Mutex
|
||||
var jsonResult *hcl.Object
|
||||
|
||||
// Parse parses the given string and returns the result.
|
||||
func Parse(v string) (*hcl.Object, error) {
|
||||
jsonLock.Lock()
|
||||
defer jsonLock.Unlock()
|
||||
jsonErrors = nil
|
||||
jsonResult = nil
|
||||
|
||||
// Parse
|
||||
lex := &jsonLex{Input: v}
|
||||
jsonParse(lex)
|
||||
|
||||
// If we have an error in the lexer itself, return it
|
||||
if lex.err != nil {
|
||||
return nil, lex.err
|
||||
}
|
||||
|
||||
// Build up the errors
|
||||
var err error
|
||||
if len(jsonErrors) > 0 {
|
||||
err = &multierror.Error{Errors: jsonErrors}
|
||||
jsonResult = nil
|
||||
}
|
||||
|
||||
return jsonResult, err
|
||||
}
|
||||
210
vendor/github.com/yudai/hcl/json/parse.y
generated
vendored
Normal file
210
vendor/github.com/yudai/hcl/json/parse.y
generated
vendored
Normal file
|
|
@ -0,0 +1,210 @@
|
|||
// This is the yacc input for creating the parser for HCL JSON.
|
||||
|
||||
%{
|
||||
package json
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/hashicorp/hcl/hcl"
|
||||
)
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
f float64
|
||||
num int
|
||||
str string
|
||||
obj *hcl.Object
|
||||
objlist []*hcl.Object
|
||||
}
|
||||
|
||||
%type <f> float
|
||||
%type <num> int
|
||||
%type <obj> number object pair value
|
||||
%type <objlist> array elements members
|
||||
%type <str> exp
|
||||
|
||||
%token <f> FLOAT
|
||||
%token <num> NUMBER
|
||||
%token <str> COLON COMMA IDENTIFIER EQUAL NEWLINE STRING
|
||||
%token <str> LEFTBRACE RIGHTBRACE LEFTBRACKET RIGHTBRACKET
|
||||
%token <str> TRUE FALSE NULL MINUS PERIOD EPLUS EMINUS
|
||||
|
||||
%%
|
||||
|
||||
top:
|
||||
object
|
||||
{
|
||||
jsonResult = $1
|
||||
}
|
||||
|
||||
object:
|
||||
LEFTBRACE members RIGHTBRACE
|
||||
{
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeObject,
|
||||
Value: hcl.ObjectList($2).Flat(),
|
||||
}
|
||||
}
|
||||
| LEFTBRACE RIGHTBRACE
|
||||
{
|
||||
$$ = &hcl.Object{Type: hcl.ValueTypeObject}
|
||||
}
|
||||
|
||||
members:
|
||||
pair
|
||||
{
|
||||
$$ = []*hcl.Object{$1}
|
||||
}
|
||||
| members COMMA pair
|
||||
{
|
||||
$$ = append($1, $3)
|
||||
}
|
||||
|
||||
pair:
|
||||
STRING COLON value
|
||||
{
|
||||
$3.Key = $1
|
||||
$$ = $3
|
||||
}
|
||||
|
||||
value:
|
||||
STRING
|
||||
{
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeString,
|
||||
Value: $1,
|
||||
}
|
||||
}
|
||||
| number
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
| object
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
| array
|
||||
{
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeList,
|
||||
Value: $1,
|
||||
}
|
||||
}
|
||||
| TRUE
|
||||
{
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeBool,
|
||||
Value: true,
|
||||
}
|
||||
}
|
||||
| FALSE
|
||||
{
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeBool,
|
||||
Value: false,
|
||||
}
|
||||
}
|
||||
| NULL
|
||||
{
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeNil,
|
||||
Value: nil,
|
||||
}
|
||||
}
|
||||
|
||||
array:
|
||||
LEFTBRACKET RIGHTBRACKET
|
||||
{
|
||||
$$ = nil
|
||||
}
|
||||
| LEFTBRACKET elements RIGHTBRACKET
|
||||
{
|
||||
$$ = $2
|
||||
}
|
||||
|
||||
elements:
|
||||
value
|
||||
{
|
||||
$$ = []*hcl.Object{$1}
|
||||
}
|
||||
| elements COMMA value
|
||||
{
|
||||
$$ = append($1, $3)
|
||||
}
|
||||
|
||||
number:
|
||||
int
|
||||
{
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeInt,
|
||||
Value: $1,
|
||||
}
|
||||
}
|
||||
| float
|
||||
{
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeFloat,
|
||||
Value: $1,
|
||||
}
|
||||
}
|
||||
| int exp
|
||||
{
|
||||
fs := fmt.Sprintf("%d%s", $1, $2)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeFloat,
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
| float exp
|
||||
{
|
||||
fs := fmt.Sprintf("%f%s", $1, $2)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
$$ = &hcl.Object{
|
||||
Type: hcl.ValueTypeFloat,
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
|
||||
int:
|
||||
MINUS int
|
||||
{
|
||||
$$ = $2 * -1
|
||||
}
|
||||
| NUMBER
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
|
||||
float:
|
||||
MINUS float
|
||||
{
|
||||
$$ = $2 * -1
|
||||
}
|
||||
| FLOAT
|
||||
{
|
||||
$$ = $1
|
||||
}
|
||||
|
||||
exp:
|
||||
EPLUS NUMBER
|
||||
{
|
||||
$$ = "e" + strconv.FormatInt(int64($2), 10)
|
||||
}
|
||||
| EMINUS NUMBER
|
||||
{
|
||||
$$ = "e-" + strconv.FormatInt(int64($2), 10)
|
||||
}
|
||||
|
||||
%%
|
||||
699
vendor/github.com/yudai/hcl/json/y.go
generated
vendored
Normal file
699
vendor/github.com/yudai/hcl/json/y.go
generated
vendored
Normal file
|
|
@ -0,0 +1,699 @@
|
|||
//line parse.y:3
|
||||
package json
|
||||
|
||||
import __yyfmt__ "fmt"
|
||||
|
||||
//line parse.y:5
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/yudai/hcl/hcl"
|
||||
)
|
||||
|
||||
//line parse.y:15
|
||||
type jsonSymType struct {
|
||||
yys int
|
||||
f float64
|
||||
num int
|
||||
str string
|
||||
obj *hcl.Object
|
||||
objlist []*hcl.Object
|
||||
}
|
||||
|
||||
const FLOAT = 57346
|
||||
const NUMBER = 57347
|
||||
const COLON = 57348
|
||||
const COMMA = 57349
|
||||
const IDENTIFIER = 57350
|
||||
const EQUAL = 57351
|
||||
const NEWLINE = 57352
|
||||
const STRING = 57353
|
||||
const LEFTBRACE = 57354
|
||||
const RIGHTBRACE = 57355
|
||||
const LEFTBRACKET = 57356
|
||||
const RIGHTBRACKET = 57357
|
||||
const TRUE = 57358
|
||||
const FALSE = 57359
|
||||
const NULL = 57360
|
||||
const MINUS = 57361
|
||||
const PERIOD = 57362
|
||||
const EPLUS = 57363
|
||||
const EMINUS = 57364
|
||||
|
||||
var jsonToknames = [...]string{
|
||||
"$end",
|
||||
"error",
|
||||
"$unk",
|
||||
"FLOAT",
|
||||
"NUMBER",
|
||||
"COLON",
|
||||
"COMMA",
|
||||
"IDENTIFIER",
|
||||
"EQUAL",
|
||||
"NEWLINE",
|
||||
"STRING",
|
||||
"LEFTBRACE",
|
||||
"RIGHTBRACE",
|
||||
"LEFTBRACKET",
|
||||
"RIGHTBRACKET",
|
||||
"TRUE",
|
||||
"FALSE",
|
||||
"NULL",
|
||||
"MINUS",
|
||||
"PERIOD",
|
||||
"EPLUS",
|
||||
"EMINUS",
|
||||
}
|
||||
var jsonStatenames = [...]string{}
|
||||
|
||||
const jsonEofCode = 1
|
||||
const jsonErrCode = 2
|
||||
const jsonMaxDepth = 200
|
||||
|
||||
//line parse.y:210
|
||||
|
||||
//line yacctab:1
|
||||
var jsonExca = [...]int{
|
||||
-1, 1,
|
||||
1, -1,
|
||||
-2, 0,
|
||||
}
|
||||
|
||||
const jsonNprod = 28
|
||||
const jsonPrivate = 57344
|
||||
|
||||
var jsonTokenNames []string
|
||||
var jsonStates []string
|
||||
|
||||
const jsonLast = 53
|
||||
|
||||
var jsonAct = [...]int{
|
||||
|
||||
12, 25, 24, 3, 20, 27, 28, 7, 13, 3,
|
||||
21, 22, 30, 17, 18, 19, 23, 25, 24, 26,
|
||||
25, 24, 36, 32, 13, 3, 10, 22, 33, 17,
|
||||
18, 19, 23, 35, 34, 23, 38, 9, 7, 39,
|
||||
5, 29, 6, 8, 37, 15, 2, 1, 4, 31,
|
||||
16, 14, 11,
|
||||
}
|
||||
var jsonPact = [...]int{
|
||||
|
||||
-9, -1000, -1000, 27, 30, -1000, -1000, 20, -1000, -4,
|
||||
13, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000, -1000,
|
||||
-16, -16, -3, 16, -1000, -1000, -1000, 28, 17, -1000,
|
||||
-1000, 29, -1000, -1000, -1000, -1000, -1000, -1000, 13, -1000,
|
||||
}
|
||||
var jsonPgo = [...]int{
|
||||
|
||||
0, 10, 4, 51, 45, 42, 0, 50, 49, 48,
|
||||
19, 47,
|
||||
}
|
||||
var jsonR1 = [...]int{
|
||||
|
||||
0, 11, 4, 4, 9, 9, 5, 6, 6, 6,
|
||||
6, 6, 6, 6, 7, 7, 8, 8, 3, 3,
|
||||
3, 3, 2, 2, 1, 1, 10, 10,
|
||||
}
|
||||
var jsonR2 = [...]int{
|
||||
|
||||
0, 1, 3, 2, 1, 3, 3, 1, 1, 1,
|
||||
1, 1, 1, 1, 2, 3, 1, 3, 1, 1,
|
||||
2, 2, 2, 1, 2, 1, 2, 2,
|
||||
}
|
||||
var jsonChk = [...]int{
|
||||
|
||||
-1000, -11, -4, 12, -9, 13, -5, 11, 13, 7,
|
||||
6, -5, -6, 11, -3, -4, -7, 16, 17, 18,
|
||||
-2, -1, 14, 19, 5, 4, -10, 21, 22, -10,
|
||||
15, -8, -6, -2, -1, 5, 5, 15, 7, -6,
|
||||
}
|
||||
var jsonDef = [...]int{
|
||||
|
||||
0, -2, 1, 0, 0, 3, 4, 0, 2, 0,
|
||||
0, 5, 6, 7, 8, 9, 10, 11, 12, 13,
|
||||
18, 19, 0, 0, 23, 25, 20, 0, 0, 21,
|
||||
14, 0, 16, 22, 24, 26, 27, 15, 0, 17,
|
||||
}
|
||||
var jsonTok1 = [...]int{
|
||||
|
||||
1,
|
||||
}
|
||||
var jsonTok2 = [...]int{
|
||||
|
||||
2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
|
||||
22,
|
||||
}
|
||||
var jsonTok3 = [...]int{
|
||||
0,
|
||||
}
|
||||
|
||||
var jsonErrorMessages = [...]struct {
|
||||
state int
|
||||
token int
|
||||
msg string
|
||||
}{}
|
||||
|
||||
//line yaccpar:1
|
||||
|
||||
/* parser for yacc output */
|
||||
|
||||
var (
|
||||
jsonDebug = 0
|
||||
jsonErrorVerbose = false
|
||||
)
|
||||
|
||||
type jsonLexer interface {
|
||||
Lex(lval *jsonSymType) int
|
||||
Error(s string)
|
||||
}
|
||||
|
||||
type jsonParser interface {
|
||||
Parse(jsonLexer) int
|
||||
Lookahead() int
|
||||
}
|
||||
|
||||
type jsonParserImpl struct {
|
||||
lookahead func() int
|
||||
}
|
||||
|
||||
func (p *jsonParserImpl) Lookahead() int {
|
||||
return p.lookahead()
|
||||
}
|
||||
|
||||
func jsonNewParser() jsonParser {
|
||||
p := &jsonParserImpl{
|
||||
lookahead: func() int { return -1 },
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
const jsonFlag = -1000
|
||||
|
||||
func jsonTokname(c int) string {
|
||||
if c >= 1 && c-1 < len(jsonToknames) {
|
||||
if jsonToknames[c-1] != "" {
|
||||
return jsonToknames[c-1]
|
||||
}
|
||||
}
|
||||
return __yyfmt__.Sprintf("tok-%v", c)
|
||||
}
|
||||
|
||||
func jsonStatname(s int) string {
|
||||
if s >= 0 && s < len(jsonStatenames) {
|
||||
if jsonStatenames[s] != "" {
|
||||
return jsonStatenames[s]
|
||||
}
|
||||
}
|
||||
return __yyfmt__.Sprintf("state-%v", s)
|
||||
}
|
||||
|
||||
func jsonErrorMessage(state, lookAhead int) string {
|
||||
const TOKSTART = 4
|
||||
|
||||
if !jsonErrorVerbose {
|
||||
return "syntax error"
|
||||
}
|
||||
|
||||
for _, e := range jsonErrorMessages {
|
||||
if e.state == state && e.token == lookAhead {
|
||||
return "syntax error: " + e.msg
|
||||
}
|
||||
}
|
||||
|
||||
res := "syntax error: unexpected " + jsonTokname(lookAhead)
|
||||
|
||||
// To match Bison, suggest at most four expected tokens.
|
||||
expected := make([]int, 0, 4)
|
||||
|
||||
// Look for shiftable tokens.
|
||||
base := jsonPact[state]
|
||||
for tok := TOKSTART; tok-1 < len(jsonToknames); tok++ {
|
||||
if n := base + tok; n >= 0 && n < jsonLast && jsonChk[jsonAct[n]] == tok {
|
||||
if len(expected) == cap(expected) {
|
||||
return res
|
||||
}
|
||||
expected = append(expected, tok)
|
||||
}
|
||||
}
|
||||
|
||||
if jsonDef[state] == -2 {
|
||||
i := 0
|
||||
for jsonExca[i] != -1 || jsonExca[i+1] != state {
|
||||
i += 2
|
||||
}
|
||||
|
||||
// Look for tokens that we accept or reduce.
|
||||
for i += 2; jsonExca[i] >= 0; i += 2 {
|
||||
tok := jsonExca[i]
|
||||
if tok < TOKSTART || jsonExca[i+1] == 0 {
|
||||
continue
|
||||
}
|
||||
if len(expected) == cap(expected) {
|
||||
return res
|
||||
}
|
||||
expected = append(expected, tok)
|
||||
}
|
||||
|
||||
// If the default action is to accept or reduce, give up.
|
||||
if jsonExca[i+1] != 0 {
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
for i, tok := range expected {
|
||||
if i == 0 {
|
||||
res += ", expecting "
|
||||
} else {
|
||||
res += " or "
|
||||
}
|
||||
res += jsonTokname(tok)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func jsonlex1(lex jsonLexer, lval *jsonSymType) (char, token int) {
|
||||
token = 0
|
||||
char = lex.Lex(lval)
|
||||
if char <= 0 {
|
||||
token = jsonTok1[0]
|
||||
goto out
|
||||
}
|
||||
if char < len(jsonTok1) {
|
||||
token = jsonTok1[char]
|
||||
goto out
|
||||
}
|
||||
if char >= jsonPrivate {
|
||||
if char < jsonPrivate+len(jsonTok2) {
|
||||
token = jsonTok2[char-jsonPrivate]
|
||||
goto out
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(jsonTok3); i += 2 {
|
||||
token = jsonTok3[i+0]
|
||||
if token == char {
|
||||
token = jsonTok3[i+1]
|
||||
goto out
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
if token == 0 {
|
||||
token = jsonTok2[1] /* unknown char */
|
||||
}
|
||||
if jsonDebug >= 3 {
|
||||
__yyfmt__.Printf("lex %s(%d)\n", jsonTokname(token), uint(char))
|
||||
}
|
||||
return char, token
|
||||
}
|
||||
|
||||
func jsonParse(jsonlex jsonLexer) int {
|
||||
return jsonNewParser().Parse(jsonlex)
|
||||
}
|
||||
|
||||
func (jsonrcvr *jsonParserImpl) Parse(jsonlex jsonLexer) int {
|
||||
var jsonn int
|
||||
var jsonlval jsonSymType
|
||||
var jsonVAL jsonSymType
|
||||
var jsonDollar []jsonSymType
|
||||
_ = jsonDollar // silence set and not used
|
||||
jsonS := make([]jsonSymType, jsonMaxDepth)
|
||||
|
||||
Nerrs := 0 /* number of errors */
|
||||
Errflag := 0 /* error recovery flag */
|
||||
jsonstate := 0
|
||||
jsonchar := -1
|
||||
jsontoken := -1 // jsonchar translated into internal numbering
|
||||
jsonrcvr.lookahead = func() int { return jsonchar }
|
||||
defer func() {
|
||||
// Make sure we report no lookahead when not parsing.
|
||||
jsonstate = -1
|
||||
jsonchar = -1
|
||||
jsontoken = -1
|
||||
}()
|
||||
jsonp := -1
|
||||
goto jsonstack
|
||||
|
||||
ret0:
|
||||
return 0
|
||||
|
||||
ret1:
|
||||
return 1
|
||||
|
||||
jsonstack:
|
||||
/* put a state and value onto the stack */
|
||||
if jsonDebug >= 4 {
|
||||
__yyfmt__.Printf("char %v in %v\n", jsonTokname(jsontoken), jsonStatname(jsonstate))
|
||||
}
|
||||
|
||||
jsonp++
|
||||
if jsonp >= len(jsonS) {
|
||||
nyys := make([]jsonSymType, len(jsonS)*2)
|
||||
copy(nyys, jsonS)
|
||||
jsonS = nyys
|
||||
}
|
||||
jsonS[jsonp] = jsonVAL
|
||||
jsonS[jsonp].yys = jsonstate
|
||||
|
||||
jsonnewstate:
|
||||
jsonn = jsonPact[jsonstate]
|
||||
if jsonn <= jsonFlag {
|
||||
goto jsondefault /* simple state */
|
||||
}
|
||||
if jsonchar < 0 {
|
||||
jsonchar, jsontoken = jsonlex1(jsonlex, &jsonlval)
|
||||
}
|
||||
jsonn += jsontoken
|
||||
if jsonn < 0 || jsonn >= jsonLast {
|
||||
goto jsondefault
|
||||
}
|
||||
jsonn = jsonAct[jsonn]
|
||||
if jsonChk[jsonn] == jsontoken { /* valid shift */
|
||||
jsonchar = -1
|
||||
jsontoken = -1
|
||||
jsonVAL = jsonlval
|
||||
jsonstate = jsonn
|
||||
if Errflag > 0 {
|
||||
Errflag--
|
||||
}
|
||||
goto jsonstack
|
||||
}
|
||||
|
||||
jsondefault:
|
||||
/* default state action */
|
||||
jsonn = jsonDef[jsonstate]
|
||||
if jsonn == -2 {
|
||||
if jsonchar < 0 {
|
||||
jsonchar, jsontoken = jsonlex1(jsonlex, &jsonlval)
|
||||
}
|
||||
|
||||
/* look through exception table */
|
||||
xi := 0
|
||||
for {
|
||||
if jsonExca[xi+0] == -1 && jsonExca[xi+1] == jsonstate {
|
||||
break
|
||||
}
|
||||
xi += 2
|
||||
}
|
||||
for xi += 2; ; xi += 2 {
|
||||
jsonn = jsonExca[xi+0]
|
||||
if jsonn < 0 || jsonn == jsontoken {
|
||||
break
|
||||
}
|
||||
}
|
||||
jsonn = jsonExca[xi+1]
|
||||
if jsonn < 0 {
|
||||
goto ret0
|
||||
}
|
||||
}
|
||||
if jsonn == 0 {
|
||||
/* error ... attempt to resume parsing */
|
||||
switch Errflag {
|
||||
case 0: /* brand new error */
|
||||
jsonlex.Error(jsonErrorMessage(jsonstate, jsontoken))
|
||||
Nerrs++
|
||||
if jsonDebug >= 1 {
|
||||
__yyfmt__.Printf("%s", jsonStatname(jsonstate))
|
||||
__yyfmt__.Printf(" saw %s\n", jsonTokname(jsontoken))
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case 1, 2: /* incompletely recovered error ... try again */
|
||||
Errflag = 3
|
||||
|
||||
/* find a state where "error" is a legal shift action */
|
||||
for jsonp >= 0 {
|
||||
jsonn = jsonPact[jsonS[jsonp].yys] + jsonErrCode
|
||||
if jsonn >= 0 && jsonn < jsonLast {
|
||||
jsonstate = jsonAct[jsonn] /* simulate a shift of "error" */
|
||||
if jsonChk[jsonstate] == jsonErrCode {
|
||||
goto jsonstack
|
||||
}
|
||||
}
|
||||
|
||||
/* the current p has no shift on "error", pop stack */
|
||||
if jsonDebug >= 2 {
|
||||
__yyfmt__.Printf("error recovery pops state %d\n", jsonS[jsonp].yys)
|
||||
}
|
||||
jsonp--
|
||||
}
|
||||
/* there is no state on the stack with an error shift ... abort */
|
||||
goto ret1
|
||||
|
||||
case 3: /* no shift yet; clobber input char */
|
||||
if jsonDebug >= 2 {
|
||||
__yyfmt__.Printf("error recovery discards %s\n", jsonTokname(jsontoken))
|
||||
}
|
||||
if jsontoken == jsonEofCode {
|
||||
goto ret1
|
||||
}
|
||||
jsonchar = -1
|
||||
jsontoken = -1
|
||||
goto jsonnewstate /* try again in the same state */
|
||||
}
|
||||
}
|
||||
|
||||
/* reduction by production jsonn */
|
||||
if jsonDebug >= 2 {
|
||||
__yyfmt__.Printf("reduce %v in:\n\t%v\n", jsonn, jsonStatname(jsonstate))
|
||||
}
|
||||
|
||||
jsonnt := jsonn
|
||||
jsonpt := jsonp
|
||||
_ = jsonpt // guard against "declared and not used"
|
||||
|
||||
jsonp -= jsonR2[jsonn]
|
||||
// jsonp is now the index of $0. Perform the default action. Iff the
|
||||
// reduced production is ε, $1 is possibly out of range.
|
||||
if jsonp+1 >= len(jsonS) {
|
||||
nyys := make([]jsonSymType, len(jsonS)*2)
|
||||
copy(nyys, jsonS)
|
||||
jsonS = nyys
|
||||
}
|
||||
jsonVAL = jsonS[jsonp+1]
|
||||
|
||||
/* consult goto table to find next state */
|
||||
jsonn = jsonR1[jsonn]
|
||||
jsong := jsonPgo[jsonn]
|
||||
jsonj := jsong + jsonS[jsonp].yys + 1
|
||||
|
||||
if jsonj >= jsonLast {
|
||||
jsonstate = jsonAct[jsong]
|
||||
} else {
|
||||
jsonstate = jsonAct[jsonj]
|
||||
if jsonChk[jsonstate] != -jsonn {
|
||||
jsonstate = jsonAct[jsong]
|
||||
}
|
||||
}
|
||||
// dummy call; replaced with literal code
|
||||
switch jsonnt {
|
||||
|
||||
case 1:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:39
|
||||
{
|
||||
jsonResult = jsonDollar[1].obj
|
||||
}
|
||||
case 2:
|
||||
jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
|
||||
//line parse.y:45
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeObject,
|
||||
Value: hcl.ObjectList(jsonDollar[2].objlist).Flat(),
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
|
||||
//line parse.y:52
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{Type: hcl.ValueTypeObject}
|
||||
}
|
||||
case 4:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:58
|
||||
{
|
||||
jsonVAL.objlist = []*hcl.Object{jsonDollar[1].obj}
|
||||
}
|
||||
case 5:
|
||||
jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
|
||||
//line parse.y:62
|
||||
{
|
||||
jsonVAL.objlist = append(jsonDollar[1].objlist, jsonDollar[3].obj)
|
||||
}
|
||||
case 6:
|
||||
jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
|
||||
//line parse.y:68
|
||||
{
|
||||
jsonDollar[3].obj.Key = jsonDollar[1].str
|
||||
jsonVAL.obj = jsonDollar[3].obj
|
||||
}
|
||||
case 7:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:75
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeString,
|
||||
Value: jsonDollar[1].str,
|
||||
}
|
||||
}
|
||||
case 8:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:82
|
||||
{
|
||||
jsonVAL.obj = jsonDollar[1].obj
|
||||
}
|
||||
case 9:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:86
|
||||
{
|
||||
jsonVAL.obj = jsonDollar[1].obj
|
||||
}
|
||||
case 10:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:90
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeList,
|
||||
Value: jsonDollar[1].objlist,
|
||||
}
|
||||
}
|
||||
case 11:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:97
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeBool,
|
||||
Value: true,
|
||||
}
|
||||
}
|
||||
case 12:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:104
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeBool,
|
||||
Value: false,
|
||||
}
|
||||
}
|
||||
case 13:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:111
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeNil,
|
||||
Value: nil,
|
||||
}
|
||||
}
|
||||
case 14:
|
||||
jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
|
||||
//line parse.y:120
|
||||
{
|
||||
jsonVAL.objlist = nil
|
||||
}
|
||||
case 15:
|
||||
jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
|
||||
//line parse.y:124
|
||||
{
|
||||
jsonVAL.objlist = jsonDollar[2].objlist
|
||||
}
|
||||
case 16:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:130
|
||||
{
|
||||
jsonVAL.objlist = []*hcl.Object{jsonDollar[1].obj}
|
||||
}
|
||||
case 17:
|
||||
jsonDollar = jsonS[jsonpt-3 : jsonpt+1]
|
||||
//line parse.y:134
|
||||
{
|
||||
jsonVAL.objlist = append(jsonDollar[1].objlist, jsonDollar[3].obj)
|
||||
}
|
||||
case 18:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:140
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeInt,
|
||||
Value: jsonDollar[1].num,
|
||||
}
|
||||
}
|
||||
case 19:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:147
|
||||
{
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeFloat,
|
||||
Value: jsonDollar[1].f,
|
||||
}
|
||||
}
|
||||
case 20:
|
||||
jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
|
||||
//line parse.y:154
|
||||
{
|
||||
fs := fmt.Sprintf("%d%s", jsonDollar[1].num, jsonDollar[2].str)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeFloat,
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
case 21:
|
||||
jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
|
||||
//line parse.y:167
|
||||
{
|
||||
fs := fmt.Sprintf("%f%s", jsonDollar[1].f, jsonDollar[2].str)
|
||||
f, err := strconv.ParseFloat(fs, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
jsonVAL.obj = &hcl.Object{
|
||||
Type: hcl.ValueTypeFloat,
|
||||
Value: f,
|
||||
}
|
||||
}
|
||||
case 22:
|
||||
jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
|
||||
//line parse.y:182
|
||||
{
|
||||
jsonVAL.num = jsonDollar[2].num * -1
|
||||
}
|
||||
case 23:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:186
|
||||
{
|
||||
jsonVAL.num = jsonDollar[1].num
|
||||
}
|
||||
case 24:
|
||||
jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
|
||||
//line parse.y:192
|
||||
{
|
||||
jsonVAL.f = jsonDollar[2].f * -1
|
||||
}
|
||||
case 25:
|
||||
jsonDollar = jsonS[jsonpt-1 : jsonpt+1]
|
||||
//line parse.y:196
|
||||
{
|
||||
jsonVAL.f = jsonDollar[1].f
|
||||
}
|
||||
case 26:
|
||||
jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
|
||||
//line parse.y:202
|
||||
{
|
||||
jsonVAL.str = "e" + strconv.FormatInt(int64(jsonDollar[2].num), 10)
|
||||
}
|
||||
case 27:
|
||||
jsonDollar = jsonS[jsonpt-2 : jsonpt+1]
|
||||
//line parse.y:206
|
||||
{
|
||||
jsonVAL.str = "e-" + strconv.FormatInt(int64(jsonDollar[2].num), 10)
|
||||
}
|
||||
}
|
||||
goto jsonstack /* stack new state and value */
|
||||
}
|
||||
31
vendor/github.com/yudai/hcl/lex.go
generated
vendored
Normal file
31
vendor/github.com/yudai/hcl/lex.go
generated
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package hcl
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
)
|
||||
|
||||
type lexModeValue byte
|
||||
|
||||
const (
|
||||
lexModeUnknown lexModeValue = iota
|
||||
lexModeHcl
|
||||
lexModeJson
|
||||
)
|
||||
|
||||
// lexMode returns whether we're going to be parsing in JSON
|
||||
// mode or HCL mode.
|
||||
func lexMode(v string) lexModeValue {
|
||||
for _, r := range v {
|
||||
if unicode.IsSpace(r) {
|
||||
continue
|
||||
}
|
||||
|
||||
if r == '{' {
|
||||
return lexModeJson
|
||||
} else {
|
||||
return lexModeHcl
|
||||
}
|
||||
}
|
||||
|
||||
return lexModeHcl
|
||||
}
|
||||
22
vendor/github.com/yudai/hcl/parse.go
generated
vendored
Normal file
22
vendor/github.com/yudai/hcl/parse.go
generated
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
package hcl
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/yudai/hcl/hcl"
|
||||
"github.com/yudai/hcl/json"
|
||||
)
|
||||
|
||||
// Parse parses the given input and returns the root object.
|
||||
//
|
||||
// The input format can be either HCL or JSON.
|
||||
func Parse(input string) (*hcl.Object, error) {
|
||||
switch lexMode(input) {
|
||||
case lexModeHcl:
|
||||
return hcl.Parse(input)
|
||||
case lexModeJson:
|
||||
return json.Parse(input)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("unknown config format")
|
||||
}
|
||||
21
vendor/github.com/yudai/umutex/LICENSE
generated
vendored
Normal file
21
vendor/github.com/yudai/umutex/LICENSE
generated
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Iwasaki Yudai
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
53
vendor/github.com/yudai/umutex/README.md
generated
vendored
Normal file
53
vendor/github.com/yudai/umutex/README.md
generated
vendored
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
# Unblocking Mutex
|
||||
|
||||
This simple package provides unblocking mutexes for those who don't want to write many `select` clauses or get confused by numerous channels.
|
||||
|
||||
## Usage Example
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/yudai/umutex"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// Create mutex
|
||||
mutex := umutex.New()
|
||||
|
||||
// First time, try should succeed
|
||||
if mutex.TryLock() {
|
||||
fmt.Println("SUCCESS")
|
||||
} else {
|
||||
fmt.Println("FAILURE")
|
||||
}
|
||||
|
||||
// Second time, try should fail as it's locked
|
||||
if mutex.TryLock() {
|
||||
fmt.Println("SUCCESS")
|
||||
} else {
|
||||
fmt.Println("FAILURE")
|
||||
}
|
||||
|
||||
// Unclock mutex
|
||||
mutex.Unlock()
|
||||
|
||||
// Third time, try should succeed again
|
||||
if mutex.TryLock() {
|
||||
fmt.Println("SUCCESS")
|
||||
} else {
|
||||
fmt.Println("FAILURE")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The output is;
|
||||
|
||||
```sh
|
||||
SUCCESS
|
||||
FAILURE
|
||||
SUCCESS
|
||||
```
|
||||
|
||||
`ForceLock()` method is also availale for normal blocking lock.
|
||||
38
vendor/github.com/yudai/umutex/umutex.go
generated
vendored
Normal file
38
vendor/github.com/yudai/umutex/umutex.go
generated
vendored
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// Package umutex provides unblocking mutex
|
||||
package umutex
|
||||
|
||||
// UnblockingMutex represents an unblocking mutex.
|
||||
type UnblockingMutex struct {
|
||||
// Raw channel
|
||||
C chan bool
|
||||
}
|
||||
|
||||
// New returnes a new unblocking mutex instance.
|
||||
func New() *UnblockingMutex {
|
||||
return &UnblockingMutex{
|
||||
C: make(chan bool, 1),
|
||||
}
|
||||
}
|
||||
|
||||
// TryLock tries to lock the mutex.
|
||||
// When the mutex is free at the time, the function locks the mutex and return
|
||||
// true. Otherwise false will be returned. In the both cases, this function
|
||||
// doens't block and return the result immediately.
|
||||
func (m UnblockingMutex) TryLock() (result bool) {
|
||||
select {
|
||||
case m.C <- true:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Unlock unclocks the mutex.
|
||||
func (m UnblockingMutex) Unlock() {
|
||||
<-m.C
|
||||
}
|
||||
|
||||
// ForceLock surely locks the mutex, however, this function blocks when the mutex is locked at the time.
|
||||
func (m UnblockingMutex) ForceLock() {
|
||||
m.C <- false
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue