How hashicorp/hcl works
HCL is a Go toolkit for defining structured configuration languages. The principal workflow is an application supplying configuration text, parsing it as native HCL or HCL JSON, then decoding its attributes and blocks into application values; native expressions can also use application-provided variables and functions. The map includes declarative and struct decoders, dynamic-block and expression extensions, plus source-preserving writing and formatting. Edges follow README statements and shown imports or calls; unsampled subsystem links are omitted rather than inferred.
Main entry points: hclsyntax/parser.go Native syntax · hclsimple.go One-step decode · main.go hcldec CLI · hclparse/parser.go Parser facade
Components 19
Parsing
- Parser facade
hclparse/parser.go - Native syntax
hclsyntax/parser.go - HCL JSON
json/structure.go
Language model
- Body and schema
schema.go - Expressions
hclsyntax/expression.go - Expression evaluation
eval_context.go
Decoding
- One-step decode
hclsimple/hclsimple.go - Go struct decoder
gohcl/decode.go - Spec decoder
hcldec/spec.go
Extensions
- Dynamic blocks
ext/dynblock/expand_body.go - Custom expressions
ext/customdecode/customdecode.go - Type expressions
ext/typeexpr/get_type.go - User functions
ext/userfunc/public.go - Try functions
ext/tryfunc/tryfunc.go
Authoring tools
- Source-preserving writer
hclwrite/parser.go - Formatting
hclwrite/format.go - hcldec CLI
cmd/hcldec/main.go - CLI spec parser
cmd/hcldec/spec.go
Other components
- Calling application
Connections 27
- Calling application → Parser facade: submits config
- Parser facade → Native syntax: parses HCL
hclparse/parser.go - Parser facade → HCL JSON: parses JSON
hclparse/parser.go - Native syntax → Body and schema: produces structure
- HCL JSON → Body and schema: produces structure
- Native syntax → Expressions: parses expressions
- Calling application → One-step decode: loads config
- One-step decode → Native syntax: parses HCL
hclsimple/hclsimple.go - One-step decode → HCL JSON: parses JSON
hclsimple/hclsimple.go - One-step decode → Go struct decoder: decodes body
hclsimple/hclsimple.go - Calling application → Go struct decoder: decodes to structs
- Calling application → Spec decoder: decodes by spec
- Spec decoder → Body and schema: consumes body
hcldec/spec.go - Calling application → Expression evaluation: provides variables
- Expressions → Expression evaluation: evaluates values
- Calling application → Dynamic blocks: uses extension
- Try functions → Custom expressions: evaluates closures
ext/tryfunc/tryfunc.go - Calling application → Type expressions: uses extension
- Calling application → User functions: uses extension
- Calling application → Source-preserving writer: edits configuration
- Source-preserving writer → Native syntax: parses tokens
hclwrite/parser.go - Calling application → Formatting: formats source
- Formatting → Source-preserving writer: formats tokens
hclwrite/format.go - Calling application → hcldec CLI: runs decoder CLI
- hcldec CLI → Spec decoder: decodes by spec
cmd/hcldec/main.go - hcldec CLI → Parser facade: parses inputs
cmd/hcldec/main.go - hcldec CLI → CLI spec parser: loads spec