Commit Graph

19 Commits

Author SHA1 Message Date
Martin Atkins
9db880accf
ext/typeexpr: correct examples in the README 2018-04-05 19:34:53 -07:00
Martin Atkins
be66a72aa8 ext/typeexpr: HCL extension for "type expressions"
This uses the expression static analysis features to interpret
a combination of static calls and static traversals as the description
of a type.

This is intended for situations where applications need to accept type
information from their end-users, providing a concise syntax for doing
so.

Since this is implemented using static analysis, the type vocabulary is
constrained only to keywords representing primitive types and type
construction functions for complex types. No other expression elements
are allowed.

A separate function is provided for parsing type constraints, which allows
the additonal keyword "any" to represent the dynamic pseudo-type.

Finally, a helper function is provided to convert a type back into a
string representation resembling the original input, as an aid to
applications that need to produce error messages relating to user-entered
types.
2018-03-04 14:45:25 -08:00
Martin Atkins
18a92d222b ext/userfunc: use bare identifiers for param names
Now that we have the necessary functions to deal with this in the
low-level HCL API, it's more intuitive to use bare identifiers for these
parameter names. This reinforces the idea that they are symbols being
defined rather than arbitrary string expressions.
2018-02-04 11:20:42 -08:00
Martin Atkins
b1a8ce3a09 ext/userfunc: update stale references to "zcl" 2018-01-27 11:03:05 -08:00
Martin Atkins
19d9927d4b ext/include: update stale reference to "zcl" 2018-01-27 11:03:05 -08:00
Martin Atkins
34e27c038a hcl: UnwrapExpression and UnwrapExpressionUntil
A pattern has emerged of wrapping Expression instances with other
Expressions in order to subtly modify their behavior. A key example of
this is in ext/dynblock, where wrap an expression in order to introduce
our additional iteration variable for expressions in dynamic blocks.

Rather than having each wrapper expression implement wrapping
implementations for our various syntax-level-analysis functions (like
ExprList and AbsTraversalForExpr), instead we define a standard mechanism
to unwrap expressions back to the lowest-level object -- usually an AST
node -- and then use this in all of our analyses that look at the
expression's structure rather than its value.
2018-01-27 09:10:18 -08:00
Martin Atkins
d6fc633aa0 ext/dynblock: ForEachVariablesHCLDec helper
For applications already using hcldec, a decoder specification can be used
to automatically drive the recursive variable detection walk that begins
with WalkForEachVariables, allowing all "for_each" and "labels" variables
in a recursive block structure to be detected in a single call.
2018-01-27 09:10:18 -08:00
Martin Atkins
45c6cc83f0 ext/dynblock: A more arduous way to find variables required to expand
The previous ForEachVariables method was flawed because it didn't have
enough information to properly analyze child blocks. Since the core HCL
API requires a schema for any body analysis, and since a schema only
describes one level of configuration structure at a time, we must require
callers to drive a recursive walk through their nested block structure so
that the correct schema can be provided at each level.

This API is rather more complex than is ideal, but is the best we can do
with the HCL Body API as currently defined, and it's currently defined
that way in order to properly support ambiguous syntaxes like JSON.
2018-01-27 09:10:18 -08:00
Martin Atkins
da95646a33 ext/dynblock: dynamic blocks extension
This extension allows an application to support dynamic generation of
child blocks based on expressions in certain contexts. This is done using
a new block type called "dynamic", which contains an iteration value
(which must be a collection) and a specification of how to construct a
child block for each element of that collection.
2018-01-27 09:10:18 -08:00
Martin Atkins
bdf1e7c6e6 gohcl: rename struct tag prefix from "zcl:" to "hcl:" 2017-09-11 17:29:56 -07:00
Martin Atkins
b8b5e0be6d hclparse: rename ParseZCL to ParseHCL 2017-09-11 17:22:10 -07:00
Martin Atkins
46b20d40af Update doc comments and readmes for zcl -> HCL. 2017-09-11 16:56:31 -07:00
Martin Atkins
708abb8c97 Move the zcl package and its two parsing subpackages to "hcl" names
This is a super-invasive update since the "zcl" package in particular
is referenced all over.

There are probably still a few zcl references hanging around in comments,
etc but this takes care of most of it.
2017-09-11 16:40:37 -07:00
Martin Atkins
0dc3a6015c Rename the ancillary packages from "zcl" to "hcl".
The main "zcl" package requires a bit more care because of how many
callers it has and because of its two subpackages, so we'll take care
of that one separately.
2017-09-11 16:00:31 -07:00
Martin Atkins
c3ca111fff Adjust import paths for hashicorp/hcl2 repo
This begins 'the great fork' of zcl to HCL.
2017-09-11 15:38:42 -07:00
Martin Atkins
523939034f ext/include: extension for including bodies into other bodies
This package implements a language extension that allows configuration
authors to include the content of another file into a body, using syntax
like this:

  include {
    path = "./foo.zcl"
  }

This is implemented as a transform.Transformer so that it can be used
as part of a transform chain when decoding nested block structures to
allow includes at any arbitrary point.

This capability is not built into the language because certain
applications will offer higher-level constructs for connecting multiple
separate config files, which may e.g. have a separate evaluation scope
for each file, etc.
2017-07-27 18:15:56 -07:00
Martin Atkins
fffca3d205 ext/transform: helper package for applying transforms to bodies
This utility is intended to support the extension packages that are
siblings of this package, along with third-party extensions, by providing
a way to transform bodies in arbitrary ways.

The "Deep" function then provides a means to apply a particular transform
recursively to a nested block tree, allowing a particular extension to
be supported at arbitrary nesting levels.

This functionality is provided in terms of the standard zcl.Body
interface, so that transform results can be used with any code that
operates generically on bodies. This includes the zcldec and gozcl
packages, so files with extensions can still be decoded in the usual
way.
2017-07-27 16:23:20 -07:00
Martin Atkins
26f1e48014 ext/userfunc: extension for user-defined functions
This package provides helper function that looks in a given body for
blocks that define functions, returning a function map suitable for use
in a zcl.EvalContext.
2017-07-25 18:34:56 -07:00
Martin Atkins
f03b4a0acd ext: A directory for packages implementing zcl language extensions
These will provide additional language features that are implemented in
terms of the basic zcl functionality, so that applications can opt-in to
some more-dynamic behavior if desired.

The general pattern here will be to provide a function that
partially-decodes a given zcl.Body to look for certain block types and
then returns its result along with a zcl.Body representing the remaining,
as-yet-unprocessed content.
2017-07-25 18:30:59 -07:00