Skip to content

STELF's grammar

The grammar of STELF was designed with a couple goals in mind:

  • To be parsable with a finite amount of lookahead (usually only 1 token)

  • Produce at most one output
  • Substituting one identifier for another will either change only the output at that identifier, or cause the parser to fail (all identifiers are syntactically equivalent), where an identifier is a sequence of non-whitespace charecters excluding ()[]{}%

Apart from this, there are a couple of other design choices that were made, including making STELF literate by default (per as a matter of fact STELF starts in markup mode)

The core lexical syntax of STELF involves a couple different lexical classes.

  1. Whitespace: any sequence of charecters that have the property White_Space=yes TODO
  2. Commands any sequence of non-whitespace charecters that begins with % and does not contain ()[]{}%
  3. Identifiers: any sequence of non-whitespace charecters that does not begin with % and does not contain ()[]{}%, this uses the longest match rule.
  4. Special characters: ()[]{}%
  5. Outer: any sequence of charecters up to %
  6. String literals, %[, with variants %[[, %[[[, etc, that are terminated by %] with the same number of ]s as [s. String literals can contain any charecters, including newlines and special characters, except %

The complete grammar, as expressed by the tree-sitter parser:

source_file ::=
outer_text ::= ([^%]|\%\%\%)+
comment ::=
%[ \t][^\n]*
ident ::= [^ \t\n(){}\[\]%]+
nat ::= [0-9]+
qualified ::=
_expr1 ::=
lam ::=
impl ::=
_expr_trail ::=
ascription ::=
arrow_chain ::=
backarrow_chain ::=
arg ::=
pdecl ::=
sdecl ::=
bdecl ::=
mode ::=
%in%out%out1%star
mode_dec ::=
id_list ::=
order_list ::=
_expr1_list ::= <_expr1> +
_decl ::= <decl>
_term_trailing ::= <_expr_trail>
_term_small ::= <_expr1>
_expr_trailing ::= <_expr_trail>
_any ::= .+?
stop ::= %.
sort_cmd ::=
term_cmd ::=
mode_cmd ::=
worlds_cmd ::=
%worlds() <expr>
total_cmd ::=
terminates_cmd ::=
reduces_cmd ::=
%reduces
<=
>=
<>=
<_expr1> +
query_cmd ::=
qtab_cmd ::=
adhoc_query ::=
define_cmd ::=
decl_cmd ::=
inline_cmd ::=
unique_cmd ::=
%unique <expr>
prec_cmd ::=
%prec
%left%right%prefix%postfix%middle%none
<nat> <id_list>
block_cmd ::=
union_cmd ::=
repl_cmd ::=
%quit
%help
%version
name_cmd ::=
symbol_cmd ::=
freeze_cmd ::=
thaw_cmd ::=
deterministic_cmd ::=
%deterministic <id_list>
use_cmd ::=
open_cmd ::=
eval_cmd ::=
%eval%{%}
covers_cmd ::=