SCLParser (scl_parser v1.0.0)
A line-aware SCL parser that includes line/col info in the final AST.
Overview
This parser has three main stages:
- Tokenization – Converts raw input string into a list of tokens (with line/col).
- Parsing – Converts the list of tokens into a "raw" AST that reflects the SCL structure (blocks, key-value lines, etc.).
- Interpretation – Converts the raw AST into a final typed AST.
Highlights
- Typed Values in the final AST:
- Booleans (
true/false) - Numbers (floats/ints)
- Atoms (
:atom) - Strings (quoted
"...", triple..., single'...', backtick`...`, or unquoted)
- Booleans (
- Block Names can have multiple attributes (e.g.,
config 1, true, "extra"), stored as[1, true, "extra"]in the final AST. - Line/Column info is included for every key, block, and value in the AST.
Final AST Form
- Key-Value =>
{{:key_atom, lineK, colK}, {value, lineV, colV}}- If multiple comma-separated values appear, the value is a list of tuples instead:
{{:key_atom, lineK, colK}, [{val1, l1, c1}, {val2, l2, c2}, ... ]}.
- If multiple comma-separated values appear, the value is a list of tuples instead:
- Block =>
{{:block_atom, lineB, colB}, {block_name_or_list, lineN, colN}, block_contents}
Usage
iex> SCLParser.parse("foo 42")
{:ok, [{{:foo, 1, 1}, {42, 1, 5}}]}
iex> SCLParser.parse("my_block 3.14 { nested true }")
{:ok,
[
{
{:my_block, 1, 1},
{3.14, 1, 15},
[
{{:nested, 1, 17}, {true, 1, 24}}
]
}
]}
Summary
Functions
Converts the raw AST from parse_tokens/1 into a final typed AST with
booleans, numbers, atoms, etc. in the correct Elixir data types.
Parses input (an SCL document) into an AST with line/col info.
Converts a list of tokens into a raw internal AST that retains
line/col info.
Tokenizes the input string into a list of tokens (including line/col info).
Functions
Converts the raw AST from parse_tokens/1 into a final typed AST with
booleans, numbers, atoms, etc. in the correct Elixir data types.
Parses input (an SCL document) into an AST with line/col info.
Returns
{:ok, ast}on success{:error, {message, line, col}}on failure
Converts a list of tokens into a raw internal AST that retains
line/col info.
Returns {:ok, raw_ast} or {:error, {message, line, col}}.
Tokenizes the input string into a list of tokens (including line/col info).
Returns {:ok, tokens} or {:error, {message, line, col}}.