Commit Graph

15 Commits

Author SHA1 Message Date
Martin Atkins
c9ac91aa84 Add MissingItemRange to zcl.BodyContent
This allows code that only deals with BodyContent (post-decoding) to
still be able to report on missing items within the associated body while
providing a suitable source location.
2017-06-03 16:46:49 -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
1535d4b708 Ability to look up the variables in an expression 2017-05-22 18:54:23 -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
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
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
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
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
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
a940c30903 Mechanism for introspection of source code for editors
The new "Nav" member on a zcl.File is an opaque object that can be
populated by parsers with an object that supports certain interfaces
that are not part of the main API but are useful for integration with
editors and other tooling.

As a first example of this, we replace the hack for getting context in
the diagnostic package with a new ContextString interface, which can
then be optionally implemented by a given parser to return a contextual
string native to the source language.
2017-05-19 19:33:58 -07:00
Martin Atkins
1168f36be5 json: start of low-level decoding 2017-05-19 19:33:58 -07:00
Martin Atkins
41527d1a3c Retain the bytes used to construct a file
Later on this will be useful when printing diagnostics with source code
snippets as context.
2017-05-18 08:07:52 -07:00
Martin Atkins
87677ae03a Rename "Element" to "Block"
The term "element" is already used for an item from a collection in cty,
so we'll use "block" to talk about the nested blocks in a zcl config to
reduce confusion.
2017-05-18 07:21:21 -07:00
Martin Atkins
b9183e85e4 Initial stubs of the public API 2017-05-13 17:44:11 -07:00