Commit Graph

40 Commits

Author SHA1 Message Date
Martin Atkins
b878a4ef98 json: parse strings as zclsyntax templates
This is the same idea as our existing HIL template support, but uses the
zclsyntax template parser instead of HIL's parser.
2017-06-12 07:25:09 -07:00
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
57d8ff0c1b json: update tokentype_string for recent new token types 2017-05-30 19:01:40 -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
1535d4b708 Ability to look up the variables in an expression 2017-05-22 18:54:23 -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
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
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
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
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
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
Martin Atkins
17d372677d json: Generalize "keywordSuggestion" for general name suggestions
keywordSuggestion is now a wrapper around nameSuggestion with a predefined
list of names.
2017-05-20 09:45:15 -07:00
Martin Atkins
aa13eab21f json: Don't suppress parser return value on errors
Even if errors were encountered during parsing, it is helpful to still
return a partial AST if possible since that allows for the source code
analysis features to still (partially) work in the face of errors.
2017-05-20 09:30:04 -07:00
Martin Atkins
69164859c8 json: Tests for Body.PartialContent 2017-05-20 08:56:55 -07:00
Martin Atkins
8883fb76ce json: include NameRange and ExprRange in returned attributes 2017-05-20 08:56:41 -07:00
Martin Atkins
d2c9089812 json: ContextString implementation
This JSON-flavored ContextString implementation returns a chain of
property names using JavaScript-style attribute access syntax.
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
160f56abb1 json: beginnings of parsing JSON into File objects
The returned file objects are not actually functional yet, but this
establishes the interface.
2017-05-18 07:57:04 -07:00
Martin Atkins
eca76d650c json: Detect and report extraneous data at EOF 2017-05-17 07:59:41 -07:00
Martin Atkins
0ef4932962 json: parsing of arrays
(and assorted bugfixes in parsing of objects that were found in the
process of adapting that code for arrays.)
2017-05-17 07:55:21 -07:00
Martin Atkins
b073937523 json: Basic parsing of number values 2017-05-17 07:34:33 -07:00
Martin Atkins
4100bdfd2f json: Parsing of strings and objects 2017-05-16 08:00:07 -07:00
Martin Atkins
8dfc3c4bbe json: fix overly-greedy keyword scanning
Logic error in the scanner caused it to always consume the remainder of
the string.
2017-05-16 07:23:33 -07:00
Martin Atkins
66c38447d3 json: fix buggy peeker.Read 2017-05-16 06:51:19 -07:00
Martin Atkins
f6bd122f4b json: parsing of keywords 2017-05-16 06:51:19 -07:00
Martin Atkins
f754328a91 json: beginnings of parser
Only supports parsing objects right now, and even then doesn't really
because objects have to contain strings and that isn't implemented yet.
2017-05-15 08:35:32 -07:00
Martin Atkins
377e20b7b8 json: AST node types 2017-05-15 08:34:35 -07:00
Martin Atkins
838a0332e6 json: token peeker
This will help our hand-written recursive-descent parser walk the tokens
with one token of lookahead.
2017-05-15 08:34:00 -07:00
Martin Atkins
45d426b99c json: Generate EOF tokens marking the end of scanning
This helps the parser include a good position when it needs to generate
"unexpected EOF" diagnostics.
2017-05-15 07:15:53 -07:00
Martin Atkins
b5ce4360cd json: initial scanner implementation
Currently lacking correct support for unicode text segmentation into
grapheme clusters, so it miscounts "Column" in positions. This will be
addressed later.
2017-05-15 07:02:13 -07:00