Commit Graph

473 Commits

Author SHA1 Message Date
Martin Atkins
cdefa254c9 zclparse: new package for the primary parser API
Although the actual parsing code will be split across multiple packages,
it's convenient for the public interface to be in a single package. The
parsers are accessed through a "Parser" type, which both wraps the
real parsers and maintains a registry of parsed files to ensure that
the same file isn't parsed more than once (which might be confusing if
there are different results) and to provide raw source code for
diagnostic-printing functions.

The parser API is in a separate package both due to the fundamental
problem that it would create an import cycle if included in the main
package and also because it's expected that calling applications will
deal with parsing once in a central place (a single file depending on
zclparse) but the resulting objects will be used broadly across the
application, causing many files to depend on the main zcl package.
2017-05-18 08:41:48 -07:00
Martin Atkins
1ecde9204c Interface for treating several files as one file
Some applications treat an entire directory as a configuration, merging
the configurations from all of the files in a directory and treating them
as one.

MergeFiles supports this idea by wrapping the bodies of the several files.
It's not yet implemented here, but once implemented it will act as an
aggregator of the content of the wrapped bodies, delegating to them for
actual body content and then merging the returned body content in a
well-defined way.
2017-05-18 08:10:21 -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
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
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
b5a78fd826 Helper for determining if a Diagnostics contains errors
Checking if it's non-nil, as we would for Go errors, doesn't work here
because there may be warnings.
2017-05-16 07:58:34 -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
bd0cbc1c81 more detailed default stringification of diagnostics 2017-05-16 07:22:56 -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
0c1a99df48 Utilities for constructing diagnostics
Wrangling diagnostics is a common concern in the parsers and evaluator,
and these helper functions are intended to make that code more concise.
2017-05-15 08:33:22 -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
Martin Atkins
b9183e85e4 Initial stubs of the public API 2017-05-13 17:44:11 -07:00
Martin Atkins
bde4c176b9 LICENSE 2017-05-13 08:51:32 -07:00
Martin Atkins
fb168c8128 Why, hello! 2017-05-13 08:50:05 -07:00