Commit Graph

481 Commits

Author SHA1 Message Date
Martin Atkins
53944335f1 zclsyntax: identifiers in the scanner 2017-05-28 09:16:53 -07:00
Martin Atkins
6362354c87 zclsyntax: scanning of numeric literals 2017-05-28 08:56:43 -07:00
Martin Atkins
187d7b8045 zclsyntax: re-organize and simplify the scanner 2017-05-28 08:38:13 -07:00
Martin Atkins
b8db08bf04 zclsyntax: use stringer for TokenType stringification 2017-05-28 07:38:17 -07:00
Martin Atkins
63fcfd6b7d zclsyntax: include a token for the end of a template sequence
Although this end symbol appears as just a close-brace in source, it's
worth differentiating it because the scanner must differentiate it anyway
(to recognize moving back into template-scanning mode) and it avoids the
parser from having to similarly re-recognize the difference.
2017-05-28 07:20:39 -07:00
Martin Atkins
76c0ca70f0 zclsyntax: scanner to return whole token slice at once
On reflection, it seems easier to maintain the necessary state we need
by doing all of the scanning in a single pass, since we can then just
use local variables within the scanner function.
2017-05-28 07:11:24 -07:00
Martin Atkins
d57901de5f zclsyntax: start of a ragel-based scanner
Using Ragel here because the scanner is going to be somewhat complex due
to the need to switch back and forth between normal and template states,
etc. This should be easier to maintain than a hand-written scanner, while
ragel gives us the extra features we need to implement things that would
normally be too complex for a "regular" scanner generator.
2017-05-27 19:01:43 -07:00
Martin Atkins
e65eafbe83 zclsyntax: define the initial set of language tokens for the scanner 2017-05-27 19:00:00 -07:00
Martin Atkins
6bf26fc9cc Update cty references to its new home in the zclconf github account 2017-05-27 17:35:44 -07:00
Martin Atkins
308eb3a291 Relocate into the "zclconf" github account 2017-05-27 17:33:09 -07:00
Martin Atkins
42b18cc7c6 json: count whole grapheme clusters as columns for position purposes
This means we can actually point at a column in the console without it
getting misaligned by multi-byte UTF-8 sequences and Unicode combining
characters.
2017-05-27 17:10:51 -07:00
Martin Atkins
2cb0bd7e83 Travis-CI test configuration 2017-05-25 08:15:49 -07:00
Martin Atkins
2b442985cd zclsyntax: FunctionCallExpr.Value
This is the first non-trivial expression Value implementation. Lots of
code here, so hopefully while implementing other expressions some
opportunities emerge to factor out some of these details.
2017-05-25 08:14:43 -07:00
Martin Atkins
8437058b60 zclsyntax: "Did you mean ...?" helper function 2017-05-25 07:14:29 -07:00
Martin Atkins
31caa36b9a zclsyntax: stub of FunctionCallExpr
This was added mainly just to spin the wheels of the Variables method
generator. Its implementation is not yet complete.
2017-05-24 08:51:34 -07:00
Martin Atkins
bae8f83298 zclsyntax: Generate "Variables" implementations for all Expressions
The implementation of Variables will be identical for every Expression
implementation since we just wrap our AST-walk-based "Variables" function
to do the work.

Rather than manually copy-pasting the declaration for each expression
type, instead we'll generate this programmatically using "go generate".
This will need to be re-run each time a new expression node type is
added, in order to make it actually implement the Expression interface.
2017-05-24 08:50:44 -07:00
Martin Atkins
007b38797b zclsyntax: Expression.Variables implementation using AST walk
This function is effectively the implementation of Variables for all
expressions, but unfortunately we still need to declare a wrapper around
it as a method on every single expression type.
2017-05-24 08:05:52 -07:00
Martin Atkins
dabdb3d059 zclsyntax: Structural AST nodes (blocks, bodies, etc) 2017-05-24 08:04:54 -07:00
Martin Atkins
a5640a0948 zclparse: actually be called zclparse
The package name was missed when this was reorganized out into a top-level
package, from ./zcl/parser where it had been previously.
2017-05-23 08:06:44 -07:00
Martin Atkins
e957bff8de zclsyntax: Start to stub out the zclsyntax package
This package will grow to contain all of the gory details of the native
zcl syntax, including it AST, parser, etc. Most callers should access
this via the simpler API in the top-level package, which then gives
automatic support for other syntaxes too.
2017-05-23 08:05:44 -07:00
Martin Atkins
1535d4b708 Ability to look up the variables in an expression 2017-05-22 18:54:23 -07:00
Martin Atkins
73b5ba8089 TraverseSplat Traverser placeholder
This will eventually deal with splats in traversals, but isn't yet
properly implemented.
2017-05-22 18:48:06 -07:00
Martin Atkins
a2d829cafc TraverseIndex traverser implementation 2017-05-22 17:54:58 -07:00
Martin Atkins
c1815fd6e4 Start of work on Traversals
Traversals are a generalized way to talk about paths taken from the scope
and from arbitrary values. These will be used for various analysis tasks,
such as determining what needs to be placed into a scope.
2017-05-22 08:05:19 -07:00
Martin Atkins
2c0a126fe6 hclhil: documentation typo 2017-05-21 22:37:15 -07:00
Martin Atkins
2cfc08c632 json: Allow strings to be treated as HIL templates
Eventually zcl will have its own native template format that we'll use
by default, but for applications migrating from HCL/HIL we can instead
parse strings as HIL templates, for compatibility with how JSON configs
would've been processed in a HCL/HIL app.

When this mode is not enabled, we still just treat strings as literals,
pending the implementation of the zcl template parser.
2017-05-21 22:34:23 -07:00
Martin Atkins
e4fdbb6b15 hclhil: interface to treat HIL templates as expressions 2017-05-21 22:09:17 -07:00
Martin Atkins
fde586e193 hclhil: Expression.Value implementation
Currently only deals with the literal HCL structure. Later we will also
support HIL parsing and evaluation within strings, to achieve parity with
existing uses of HCL/HIL together. For now, this has parity with uses of
HCL alone, with the exception that float and int values are not
distinguished, because cty does not make this distinction.
2017-05-21 18:42:39 -07:00
Martin Atkins
0b8f6498ff hclhil: Body.Content and Body.PartialContent implementations 2017-05-21 17:45:31 -07:00
Martin Atkins
764e4c465b hclhil: Parsing and JustAttributes for HCL 2017-05-21 16:13:04 -07:00
Martin Atkins
c5df265cd0 Define Body.JustAttributes as returning Attributes
This was missed when updating the previous direct references to
map[string]*Attribute.
2017-05-21 15:43:41 -07:00
Martin Atkins
e765ff422a zclparse: Stub API for HCL/HIL file parsing
This is intended as a backward-compatibility interface, allowing
applications that previously used HCL/HIL to adopt zcl while still being
able to parse their old HCL/HIL-based configuration file formats.
2017-05-21 13:04:33 -07:00
Martin Atkins
49641f2a9a gozcl: decoding of bodies into structs and maps 2017-05-21 12:44:07 -07:00
Martin Atkins
cd019809a4 json: detect and report insufficient object levels for block labels
When decoding a block with labels, the right number of object levels must
be present to populate the labels.
2017-05-21 12:42:42 -07:00
Martin Atkins
8654cf0361 Body.MissingItemRange method
When producing diagnostics about missing attributes or bodies it's
necessary to have a range representing the place where the missing thing
might be inserted.

There's not always a single reasonable value for this, so some liberty
can be taken about what exactly is returned as long as it's somewhere
the user can relate back to the construct producing the error.
2017-05-21 11:46:58 -07:00
Martin Atkins
5fa767a43a json: mark properties as used after blocks are decoded from them 2017-05-21 11:03:47 -07:00
Martin Atkins
64c1036f80 Remove "ExprRange" from zcl.Attribute
Now that expressions themselves have Range and StartRange methods, this
is redundant.
2017-05-21 09:50:29 -07:00
Martin Atkins
4fcad1f493 json: Respect hiddenAttrs in JustAttributes
Previously it was leaking out hidden attributes.
2017-05-21 09:46:50 -07:00
Martin Atkins
a291478c78 "Attributes" type for map[string]*Attribute
This is primarily for symmetry with "Blocks", but perhaps it will also
get some useful methods later.
2017-05-21 09:05:06 -07:00
Martin Atkins
5b8d54380b gozcl: DecodeExpression implementation
This is really just a wrapper around converting the value to a Go native
value with gocty, but is convenient to provide since it can attempt
type conversion and produce diagnostics automatically.
2017-05-21 08:47:05 -07:00
Martin Atkins
bb5044d015 Range and StartRange methods on Expression
This gives us some contextual information to use for error handling when
working generically with expressions.
2017-05-20 17:40:03 -07:00
Martin Atkins
802ea19d72 gozcl: stub of the Decode functions 2017-05-20 17:30:02 -07:00
Martin Atkins
17cf497b6e gozcl: ImpliedBodySchema derives a body schema from a Go struct 2017-05-20 16:47:14 -07:00
Martin Atkins
0612bb9843 gozcl: new package for decoding zcl data into native Go values 2017-05-20 16:46:54 -07:00
Martin Atkins
dfafa6fc00 Flesh out interface for evaluating expressions
Expressions can now be evaluated within an "EvalContext", which provides
the variable and function scopes. The JSON implementation of this
currently ignores the context entirely and just returns literal values,
since we've not yet implemented the template language parser that would
be needed for the JSON parser to properly support expressions.
2017-05-20 15:17:56 -07:00
Martin Atkins
92e407e672 Body.JustAttributes method
The Content and PartialContent methods deal with the case where the caller
knows what structure is expected within the body, but sometimes the
structure of a body is just a free-form set of attributes that the caller
needs to enumerate.

The idea here is that the block in question must contain only attributes,
and no child blocks. For JSON this just entails interpreting every
property as an attribute. For native syntax later this will mean
producing an error diagnostic if any blocks appear within the body.
2017-05-20 14:35:19 -07:00
Martin Atkins
4bbfa6d6ab json: recovery behavior for the parser
When using the parser to do static analysis and editor integrations, it's
still useful to be able to get the incomplete AST resulting from a parse
error.

Callers that intend to use the returned value to take real actions (as
opposed to just analysis) must check diags.HasError() to determine if
the returned file can be considered valid.
2017-05-20 13:32:12 -07:00
Martin Atkins
341223612b MergeBodies return value now works as a Body
Its implementation calls into each of the child bodies in turn and merges
the result to produce a single BodyContent. This is intended to support
the case of a directory being the unit of configuration rather than a
file, with the calling application discovering and parsing each of the
files in its workspace and then merging them together for processing as
a single configuration.
2017-05-20 12:45:43 -07:00
Martin Atkins
873a4d07b5 json: improve error message for duplicate property
We need to be careful to keep straight the distinction between JSON
properties and zcl body attributes here, since properties can represent
both attributes _and_ blocks.
2017-05-20 11:12:03 -07:00
Martin Atkins
45f97bf427 json: Implement Body.Content
This is a wrapper around Body.PartialContent that generates additional
error diagnostics if any object properties are left over after decoding,
helping the config author to catch typos that would otherwise have caused
a property to be silently ignored.
2017-05-20 09:50:48 -07:00