From a9d652b938ef63335dd6ca2370807c5a29f1bd16 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Sat, 20 Jan 2024 12:34:58 +0300 Subject: [PATCH 1/3] chore(tooling): Add developer targets to convert grammar to EBNF --- Makefile.am | 7 ++++++- configure.ac | 1 + documentation/c03-input.sil | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index 44377e867..307c6ec22 100644 --- a/Makefile.am +++ b/Makefile.am @@ -76,7 +76,7 @@ EXTRA_DIST += default.nix flake.nix flake.lock shell.nix build-aux/pkg.nix EXTRA_DIST += package.json # imported by both Nix and Docker EXTRA_DIST += $(MANUAL) $(FIGURES) EXTRA_DIST += src/embed.rs.in -EXTRA_DIST += sil.abnf +EXTRA_DIST += sil.abnf sil.ebnf BUILT_SOURCES = $(BUILT_LUA_SOURCES) Makefile-distfiles @@ -87,6 +87,11 @@ include $(top_srcdir)/build-aux/rust_boilerplate.mk Makefile-distfiles: $(wildcard .version .tarball-version) | $(LUAMODLOCK) $(SHELL) build-aux/list-dist-files.sh > $@ +BUILT_SOURCES += sil.ebnf +sil.ebnf: sil.abnf + $(EBNF_CONVERT) -f none $< | + $(SED) -E '1,2d;4,$$s/^([a-z])/\n\1/' > $@ + if EMBEDED_RESOURCES _EMBEDED_SOURCES = src/embed.rs src/embed-includes.rs nodist_sile_SOURCES = $(_EMBEDED_SOURCES) diff --git a/configure.ac b/configure.ac index 5d221d056..044c52984 100644 --- a/configure.ac +++ b/configure.ac @@ -217,6 +217,7 @@ AM_COND_IF([DEPENDENCY_CHECKS], [ AX_PROGVAR([delta]) AX_PROGVAR([diff]) AX_PROGVAR([docker]) + AX_PROGVAR([ebnf_convert], [ebnf-convert]) AX_PROGVAR([git]) AX_PROGVAR([grep]) AX_PROGVAR([head]) diff --git a/documentation/c03-input.sil b/documentation/c03-input.sil index 525a74c2c..0fd928fbc 100644 --- a/documentation/c03-input.sil +++ b/documentation/c03-input.sil @@ -234,8 +234,8 @@ However, in some cases the environment form of the command will be easier to rea The official grammar for the SIL flavor is the LPEG reference implementation. That being said the reference implementation has some idiosyncrasies and is not the easiest to read. -For convenience an ABNF grammar is also provided in the source tree, see \code{sil.abnf}. -This grammar does not completely express the language as it cannot express the way SIL can embed other syntaxes, but it is a decent approximation. +For convenience ABNF and EBNF format grammars are also provided in the source tree, see \code{sil.abnf} and \code{sil.ebnf}. +These grammars do not completely express the language as they cannot express the way SIL can embed other syntaxes, but it is a decent approximation. The intent behind many of the syntax choices is to make it easy to have parity with XML flavors. This means limiting commands to valid XML identifiers (e.g. starting with an ASCII letter, not a digit or special character), requiring a single top level command as the document, and so forth. From 548a78301c6a6c5bac8a3e76be848507e0b9a322 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Tue, 30 Jan 2024 14:11:33 +0300 Subject: [PATCH 2/3] chore(build): Bundle core ABNF rules for parsers that don't assume them --- Makefile.am | 2 +- build-aux/rfc-5234-core.abnf | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 build-aux/rfc-5234-core.abnf diff --git a/Makefile.am b/Makefile.am index 307c6ec22..9a204f214 100644 --- a/Makefile.am +++ b/Makefile.am @@ -76,7 +76,7 @@ EXTRA_DIST += default.nix flake.nix flake.lock shell.nix build-aux/pkg.nix EXTRA_DIST += package.json # imported by both Nix and Docker EXTRA_DIST += $(MANUAL) $(FIGURES) EXTRA_DIST += src/embed.rs.in -EXTRA_DIST += sil.abnf sil.ebnf +EXTRA_DIST += sil.abnf sil.ebnf build-aux/rfc-5234-core.abnf BUILT_SOURCES = $(BUILT_LUA_SOURCES) Makefile-distfiles diff --git a/build-aux/rfc-5234-core.abnf b/build-aux/rfc-5234-core.abnf new file mode 100644 index 000000000..1d1a99b8d --- /dev/null +++ b/build-aux/rfc-5234-core.abnf @@ -0,0 +1,19 @@ +; Augmented BNF for Syntax Specifications: ABNF +; RFC-5234 Core Rules + +ALPHA = %x41-5A / %x61-7A +BIT = "0" / "1" +CHAR = %x01-7F +CR = %x0D +CRLF = CR LF +CTL = %x00-1F / %x7F +DIGIT = %x30-39 +DQUOTE = %x22 +HEXDIG = DIGIT / "A" / "B" / "C" / "D" / "E" / "F" +HTAB = %x09 +LF = %x0A +LWSP = *(WSP / CRLF WSP) +OCTET = %x00-FF +SP = %x20 +VCHAR = %x21-7E +WSP = SP / HTAB From 6c334064e42f9e141716110b6a32c600831b5a54 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Wed, 31 Jan 2024 01:21:47 +0300 Subject: [PATCH 3/3] chore(tooling): Add developer targets for generated parsers --- Makefile.am | 13 +++++++++++++ configure.ac | 3 +++ 2 files changed, 16 insertions(+) diff --git a/Makefile.am b/Makefile.am index 9a204f214..024d8bd51 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,6 +77,7 @@ EXTRA_DIST += package.json # imported by both Nix and Docker EXTRA_DIST += $(MANUAL) $(FIGURES) EXTRA_DIST += src/embed.rs.in EXTRA_DIST += sil.abnf sil.ebnf build-aux/rfc-5234-core.abnf +EXTRA_DIST += sil.c sil.h sil.js sil.py BUILT_SOURCES = $(BUILT_LUA_SOURCES) Makefile-distfiles @@ -92,6 +93,18 @@ sil.ebnf: sil.abnf $(EBNF_CONVERT) -f none $< | $(SED) -E '1,2d;4,$$s/^([a-z])/\n\1/' > $@ +BUILT_SOURCES += sil.c sil.h +sil.c sil.h: sil.abnf build-aux/rfc-5234-core.abnf + $(APG_C) -i <(cat $^) -o $(basename $@) + +BUILT_SOURCES += sil.js +sil.js: sil.abnf build-aux/rfc-5234-core.abnf + $(APG_JS) -i <(cat $^) -o $@ + +BUILT_SOURCES += sil.py +sil.py: sil.abnf build-aux/rfc-5234-core.abnf + $(APG_PY) -i <(cat $^) -o $@ + if EMBEDED_RESOURCES _EMBEDED_SOURCES = src/embed.rs src/embed-includes.rs nodist_sile_SOURCES = $(_EMBEDED_SOURCES) diff --git a/configure.ac b/configure.ac index 044c52984..dd0ce5c54 100644 --- a/configure.ac +++ b/configure.ac @@ -211,6 +211,9 @@ AM_COND_IF([DEPENDENCY_CHECKS], [ ]) AM_COND_IF([DEVELOPER], [ + AX_PROGVAR([apg_c], [apg-c]) + AX_PROGVAR([apg_js], [apg-js]) + AX_PROGVAR([apg_py], [apg-py]) AX_PROGVAR([busted]) AX_PROGVAR([cmp]) AX_PROGVAR([curl])