The Aether grammar language
Aether describes a language completely in one file: its tokens, its syntax, how whitespace is treated and which parts of a match are kept. Upper-case names are tokens, matched by a lexer; lower-case names are rules, matched by a parser over those tokens.
A first look
This grammar reads a small settings file — lines of name = value, with comments:
@grammar "settings" @root document @skip TRIVIA COMMENT := "#" (!"\n" .)* TRIVIA := (SPACE | COMMENT)* TRUE := "true" FALSE := "false" NAME := [a-z_] [a-z0-9_]* NUMBER := DIGIT+ STRING := "\"" (!"\"" .)* "\"" document := entry* entry := key:NAME "=" value:value value := TRUE | FALSE | NUMBER | STRING
@grammarnames the grammar and@rootthe rule matching starts from. Both are required, in that order.@skip TRIVIAlets whitespace and comments stand between any two parts of a rule, and before and after the whole input.COMMENTtoSTRINGare tokens.TRUEcomes beforeNAMEon purpose: both matchtrue, and the earlier one wins.document,entryandvalueare rules. The quoted"="becomes a token of its own without being declared.key:andvalue:name the parts of an entry that matter to whatever processes the match.
# service port = 8080 debug = true name = "api"
ok
true = 1
1:1: unexpected "true" -- expected NAME 1 | true = 1 | ^
Design
- Lexer and parser in one file. Spelling decides which is which, so there is no separate token file to keep in step.
- Two stages, always. Tokens take the longest match, rules take the first alternative that fits — each stage keeps its own simple rule.
- Whitespace is a setting, not a chore. One pragma makes every rule tolerate it; one prefix forbids it where two parts must touch.
- Syntax only. A grammar says what is valid and names the parts; what they mean is decided elsewhere.
- Escape hatches, clearly marked. Where a language changes its own syntax mid-file,
@nativehands one token or rule to hand-written code.
File facts
| Property | Value |
|---|---|
| Extension | .aether |
| Encoding | UTF-8; names are ASCII, strings and classes may hold any character |
| Header | @grammar "name", then @root rule — mandatory, in that order |
| Comments | ; to the end of the line |
| Result | A lexer and a parser — PEG by default, LR or GLR on request |
| Implementations | Ichor in Elixir, the reference, and its port to Praxis — see below |
Implementations
| Implementation | Language | Version | Reads .aether with |
|---|---|---|---|
| Ichor, the reference | Elixir | 0.7.3 on hex.pm, with ichor_runtime 0.6.3 | Aether.Lexer, Aether.Reader |
the Praxis port, libs_prx/ichor in the Praxis repository | Praxis | 0.7.0, not released on its own: Ichor 0.6.0 plus one step, the move to Praxis; it moves with each Elixir release | ichor.aether.lexer, ichor.aether.reader |
Ichor’s README opens with a warning: it is under heavy development and not for production use before 1.0.0. Until then the library and the language it reads can change between any two releases, which is why Aether is marked as in development here.
The port is a reimplementation, not a fork: the same three engines, the same five importers and the same VM, written in Praxis. Both readers are written by hand, and each is held by its own test to the same Aether-in-Aether grammar. The Ichor Conformance Suite, kept in the Praxis workspace for now, gives every implementation the same grammars and inputs and compares the trees and errors that come out, interpreted and generated alike.
Written in Aether
| Grammar | Defines | Used by |
|---|---|---|
casc.aether | the CASC configuration format — grammar | cooper and its Praxis port; node-cooper and php-cooper follow it by hand |
dxn.aether | the DXN text format — grammar | dextrin and its Praxis port |
praxis.aether | the surface of the Praxis language, the reference for its reader | Praxis |
logos.aether | the reader of Logos, a Clojure-flavoured Lisp | logos |
grammar.aether | Prolog clauses, with op/3 directives that change the operator table mid-file | aletheia |
quire.aether | well-formed markup with {{ … }} holes | quire, a Praxis library |
xeger.aether | regular expressions | xeger |
abnf.aether … | ABNF, BNF, ISO and W3C EBNF, and PEG | the importers of both Ichor implementations |
On these pages
- File structure — header, pragmas, comments, names, definitions and predefined tokens.
- Expressions — operators, strings, character classes, repetition, lookahead and regex literals.
- Lexing and parsing — longest match, ordered choice, whitespace, captures, layout, engines and error reports.
- Escape hatches —
@keywords,@refineand@native. - Grammar — Aether written in Aether, the grammar both implementations test their readers against.