hcl/README.md

41 lines
1.9 KiB
Markdown
Raw Normal View History

2015-10-25 16:57:07 +00:00
# hcl [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/fatih/hcl) [![Build Status](http://img.shields.io/travis/fatih/hcl.svg?style=flat-square)](https://travis-ci.org/fatih/hcl)
2015-10-25 16:27:26 +00:00
HCL is a lexer and parser family written in Go for
[HCL](https://github.com/hashicorp/hcl) (Hashicorp Configuration Language). It
has several components, similar to Go's own parser family. It provides a set of
packages to write tools and customize files written in HCL. For example both
2015-10-25 22:34:41 +00:00
[`hclfmt`](https://github.com/fatih/hclfmt) and `hcl2json` (coming soon) is
written based on these tools.
2015-10-25 16:27:26 +00:00
## API
If you are already familiar with Go's own parser family it's really easy to
2015-10-25 22:34:41 +00:00
dive. It basically resembles the same logic. However there are several differences
and the implementation is completely different. Right now it contains the
2015-10-25 16:27:26 +00:00
following packages:
2015-10-25 22:34:41 +00:00
* `token`: defines constants representing the lexical tokens for a scanned HCL file.
2015-10-25 16:27:26 +00:00
* `scanner`: scanner is a lexical scanner. It scans a given HCL file and
returns a stream of tokens.
2015-10-25 22:34:41 +00:00
* `ast`: declares the types used to represent the syntax tree for parsed HCL files.
2015-10-25 16:27:26 +00:00
* `parser`: parses a given HCL file and creates a AST representation
2015-10-25 22:34:41 +00:00
* `printer`: prints any given AST node and formats
2015-10-25 16:27:26 +00:00
2015-10-25 22:34:41 +00:00
## Why
2015-10-25 16:27:26 +00:00
2015-10-25 22:34:41 +00:00
The whole parser family was created because I wanted a `hclfmt` command, which
like `gofmt` would format a HCL file. I didn't want to use the package
[github/hashicorp/hcl](https://github.com/hashicorp/hcl) in the first place,
because the lexer and parser is generated and it doesn't expose any kind of
flexibility.
2015-10-25 16:27:26 +00:00
Another reason was that I wanted to learn and experience how to implement a
2015-10-25 22:34:41 +00:00
proper lexer and parser in Go. It was really fun and I think it was worth it.
2015-10-25 16:27:26 +00:00
## License
2015-10-25 16:30:31 +00:00
The BSD 3-Clause License - see
2015-10-25 16:57:07 +00:00
[`LICENSE`](https://github.com/fatih/hcl/blob/master/LICENSE) for more
2015-10-25 16:27:26 +00:00
details