Commit Graph

25 Commits

Author SHA1 Message Date
Martin Atkins
2506450b6e zclsyntax: correct evaluation of the for expression "group" mode
This further alters the object-construction mode so that rather than
producing a flat object it instead produces an object of tuples. All
items that produce the same key are grouped together under the same
key in the result, allowing projections that flip the orientation of
a key/value sequence where the new keys are not necessarily unique.
2017-06-18 08:45:45 -07:00
Martin Atkins
833ff9ecd7 zclsyntax: evaluation of ForExpr into a tuple 2017-06-18 08:14:36 -07:00
Martin Atkins
78db663590 zclsyntax: evaluation of splat expressions 2017-06-16 08:31:01 -07:00
Martin Atkins
b2e6e2d0d0 zclsyntax: look in parent EvalContexts for functions
If we can't find a function in the given EvalContext, we must traverse
the context chain until either we run out of contexts or we find a
matching function.

At present there is no reason for a non-root context to have any
functions, so this will always traverse to the root. This may change in
future if we introduce constructs that define local functions.
2017-06-16 07:28:29 -07:00
Martin Atkins
4ab33cdce0 zclsyntax: "expanding" function arguments
This syntax func(arg...) allows the final argument to be a sequence-typed
value that then expands to be one argument for each element of the
value.

This allows applications to define variadic functions where that's
user-friendly while still allowing users to pass tuples to those functions
in situations where the args are chosen dynamically.
2017-06-15 08:18:00 -07:00
Martin Atkins
fa06f40141 zclsyntax: ForExpr.Value implementation for object construction
The tuple path is not yet implemented and will panic.
2017-06-14 08:56:28 -07:00
Martin Atkins
0cf39f0f62 zclsyntax: FIXME to support parent ctx in function call 2017-06-14 08:54:53 -07:00
Martin Atkins
51945b4e0c zclsyntax: In Variables, don't return traversals in child scopes
The purpose of the Variables function is to tell a calling application
what symbols need to be present in the _root_ scope, so it would be
unhelpful to include child scope traversals. Child scopes are populated
by the nodes that create them, and are thus not interesting to the
calling application (for this purpose, at least).
2017-06-14 08:03:32 -07:00
Martin Atkins
54fcc09ed4 zclsyntax: AST node for the "for" expression
This expression is used to project collections into other collections.
2017-06-13 08:42:36 -07:00
Martin Atkins
34be20cc5d zclsyntax: ScopeTraversalExpr.Value implementation, and tests 2017-06-05 08:02:54 -07:00
Martin Atkins
ace387f5f9 zclsyntax: evaluation of relative traversal and index nodes 2017-06-05 07:41:02 -07:00
Martin Atkins
0266334560 zclsyntax: handle case where functions are not allowed
Previously this would panic.
2017-06-05 07:31:09 -07:00
Martin Atkins
bca573d3d0 zclsyntax: parsing of the index operator
This can either be a traversal or a first-class node depending on whether
the given expression is a literal. This exception is made to allow
applications to conditionally populate only part of a potentially-large
collection if the config is only requesting one or two distinct indices.

In particular, it allows the following to be considered a single traversal
from the scope:

    foo.bar[0].baz
2017-06-05 07:09:04 -07:00
Martin Atkins
0d0404867c zclsyntax: RelativeTraversalExpr
This is similar to ScopeTraversalExpr, but it traverses relative to the
result of another expression rather than relative to a variable in the
scope.
2017-06-04 18:40:15 -07:00
Martin Atkins
6f2bd0009c zclsyntax: parsing and evaluation for object constructors 2017-06-04 16:14:02 -07:00
Martin Atkins
c3f4694e06 zclsyntax: parsing and evaluation of tuple constructors 2017-06-04 14:22:51 -07:00
Martin Atkins
8f26a22933 zclsyntax: convert condition expr to bool in ConditionalExpr 2017-05-31 19:30:17 -07:00
Martin Atkins
2fc14b729a zclsyntax: start of expression parsing
Conditional expression parsing is ostensibly implemented, but since it
depends on the rest of the expression parsers -- not yet implemented --
it cannot be tested in isolation.

Also includes an initial implementation of the conditional expression
node, but this is also not yet tested and so may need further revisions
once we're in a better position to test it.
2017-05-31 08:37:17 -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
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
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
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