* [PATCH olang v1] spec: add contrib bin script for validating olang spec
@ 2024-10-11 3:24 Johnny Richard
2024-10-11 1:25 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-11 1:27 ` [PATCH olang v1] spec: add contrib bin script for validating olang spec Carlos Maniero
0 siblings, 2 replies; 4+ messages in thread
From: Johnny Richard @ 2024-10-11 3:24 UTC (permalink / raw)
To: ~johnnyrichard/olang-devel; +Cc: Johnny Richard
The new contrib script was executed against all tests files and few
adjustments on the spec was made:
1) Add comments support
2) New unsigned types added
3) Types support pointers (*)
4) Optional spaces over functions params and args
Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
---
.build.yml | 3 ++
contrib/bin/ebnf.clj | 42 +++++++++++++++++
contrib/bin/run-ebnf | 22 +++++++++
docs/info/olang.ebnf | 89 +++++++++++++++++++++++++++++++++++
docs/info/specification.texi | 91 +-----------------------------------
5 files changed, 157 insertions(+), 90 deletions(-)
create mode 100644 contrib/bin/ebnf.clj
create mode 100755 contrib/bin/run-ebnf
create mode 100644 docs/info/olang.ebnf
diff --git a/.build.yml b/.build.yml
index 8265da2..9c8eaa5 100644
--- a/.build.yml
+++ b/.build.yml
@@ -21,6 +21,9 @@ tasks:
- check: |
cd olang
make check
+ - check-spec: |
+ cd olang
+ ./contrib/bin/run-ebnf <(find tests/olc/ -name '*.ol' | xargs -L1 grep -Ev '(^#|^$)' | cat) 1> /dev/null
- docs-publish: |
cd olang
if [ "$BUILD_REASON" = "" ]
diff --git a/contrib/bin/ebnf.clj b/contrib/bin/ebnf.clj
new file mode 100644
index 0000000..b972c1f
--- /dev/null
+++ b/contrib/bin/ebnf.clj
@@ -0,0 +1,42 @@
+; Copyright (C) 2024 olang mantainers
+;
+; This program is free software: you can redistribute it and/or modify
+; it under the terms of the GNU General Public License as published by
+; the Free Software Foundation, either version 3 of the License, or
+; (at your option) any later version.
+;
+; This program is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+; GNU General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+(require '[clojure.pprint :refer [pprint]])
+(require '[instaparse.core :refer [parser]])
+(require '[instaparse.failure :refer [pprint-failure]])
+
+(def olang-file (System/getenv "FILE"))
+
+(def olang-parser (parser (slurp *in*)))
+
+(def parser-result (olang-parser (slurp olang-file)))
+
+(defn println-err
+ ([ ] (.println *err* ""))
+ ([s] (.println *err* s)))
+
+(defn print-err
+ ([ ] (.print *err* ""))
+ ([s] (.print *err* s)))
+
+(defn main []
+ (if (:reason parser-result)
+ (with-redefs [clojure.core/println println-err
+ clojure.core/print print-err]
+ (pprint-failure parser-result)
+ (System/exit 1))
+ (pprint parser-result)))
+
+(main)
diff --git a/contrib/bin/run-ebnf b/contrib/bin/run-ebnf
new file mode 100755
index 0000000..4b2b559
--- /dev/null
+++ b/contrib/bin/run-ebnf
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Copyright (C) 2024 olang mantainers
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+BASEDIR="$(dirname "$0")"
+
+DEPS='{:deps {instaparse/instaparse {:mvn/version "1.5.0"}}}'
+
+cat $BASEDIR/../../docs/info/olang.ebnf | sed 's/<\([a-z-]*\)>/\1/g' | FILE="$1" clj -Sdeps "$DEPS" -M $BASEDIR/ebnf.clj
diff --git a/docs/info/olang.ebnf b/docs/info/olang.ebnf
new file mode 100644
index 0000000..76a5c2f
--- /dev/null
+++ b/docs/info/olang.ebnf
@@ -0,0 +1,89 @@
+(* Entry Point *)
+<translation-unit> ::= (<ows> (<external-declaration> | <comment>) <ows> (<end-of-statement> | <end-of-file>))*
+
+(* Translation Unit *)
+<external-declaration> ::= <common-statement> | <function-definition>
+
+(* Variables *)
+<variable-definition> ::= 'var' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>?
+<constant-definition> ::= 'const' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>
+<variable-name> ::= <identifier>
+<variable-initializer> ::= '=' <ows> <expression>
+
+(* Functions *)
+<function-definition> ::= 'fn' <ws> <function-name> <ows> '(' ( <ows> | <ows> <function-params> <ows> ) ')' <ows> ':' <ows> <return-type> <ows> <function-body>
+<function-name> ::= <identifier>
+<function-params> ::= <identifier> <ows> ':' <ows> <type> ( <ows> ',' <ows> <function-params>)*
+<return-type> ::= <type>
+<function-body> ::= <block>
+<block> ::= '{' <ows> <statement> <ows> (<end-of-statement> <ows> <statement> <ows>)* <end-of-statement>? <ows> '}'
+<function-args> ::= <expression> (<ows> ',' <ows> <function-args>)*
+<function-call> ::= <function-name> <ows> '(' ( <ows> | <ows> <function-args> <ows> ) ')'
+<statement> ::= <common-statement> | <if-statement> | <while-statement> | <return-statement> | <function-call>
+<if-statement> ::= 'if' <ws> <expression> <ows> <block> ( <ows> 'else' ( <ows> <block> | <ows> <if-statement> ) )?
+<while-statement> ::= 'while' <ws> <expression> <ows> <block>
+<return-statement> ::= 'return' <ws> <expression>
+
+(* Statements *)
+<end-of-statement> ::= ';' | <line-break>
+<common-statement> ::= <variable-definition> | <constant-definition> | <expression>
+<assignment-operator> ::= '='
+ | '*='
+ | '/='
+ | '%='
+ | '+='
+ | '-='
+ | '<<='
+ | '>>='
+ | '&='
+ | '^='
+ | '|='
+
+(* Expressions *)
+<expression> ::= <binary-expression>
+<binary-expression> ::= <assignment-expression>
+<assignment-expression> ::= <logical-or-expression> (<ows> <assignment-operator> <ows> <logical-or-expression>)*
+<logical-or-expression> ::= <logical-and-expression> (<ows> '||' <ows> <logical-and-expression>)*
+<logical-and-expression> ::= <bitwise-or-expression> (<ows> '&&' <ows> <bitwise-or-expression>)*
+<bitwise-or-expression> ::= <bitwise-xor-expression> (<ows> '|' <ows> <bitwise-xor-expression>)*
+<bitwise-xor-expression> ::= <bitwise-and-expression> (<ows> '^' <ows> <bitwise-and-expression>)*
+<bitwise-and-expression> ::= <cmp-equality-expression> (<ows> '&' <ows> <cmp-equality-expression>)*
+<cmp-equality-expression> ::= <cmp-relational-expression> (<ows> ('==' | '!=') <ows> <cmp-relational-expression>)*
+<cmp-relational-expression> ::= <bitwise-shift-expression> (<ows> ('<' | '>' | '<=' | '>=') <ows> <bitwise-shift-expression>)*
+<bitwise-shift-expression> ::= <additive-expression> (<ows> ('<<' | '>>') <ows> <additive-expression>)*
+<additive-expression> ::= <multiplicative-expression> (<ows> ('+' | '-') <ows> <multiplicative-expression>)*
+<multiplicative-expression> ::= <primary-expression> (<ows> ('*' | '/' | '%') <ows> <primary-expression>)*
+<primary-expression> ::= <integer-literal>
+ | <variable-name>
+ | <function-call>
+ | <unary-expression>
+ | '(' <ows> <expression> <ows> ')'
+<unary-expression> ::= <unary-operator> <ows> <primary-expression>
+<unary-operator> ::= '&'
+ | '*'
+ | '+'
+ | '-'
+ | '~'
+ | '!'
+
+(* Identifiers *)
+<type> ::= ('u8' | 'u16' | 'u32' | 'u64') (<ows> '*')*
+
+<identifier> ::= (<alpha> | '_') (<alpha> | <digit> | '_')*
+
+(* Literals *)
+<integer-literal> ::= <integer-base10> | <integer-base16>
+<integer-base10> ::= #'[1-9]' (<digit> | '_')* | '0'
+<integer-base16> ::= #'0[Xx]' <hex-digit> (<hex-digit> | '_')*
+
+(* Utilities *)
+<comment> ::= '#' #'[^\n]*'
+<ws> ::= <white-space>+
+<ows> ::= <white-space>*
+<white-space> ::= <linear-space> | <line-break>
+<line-break> ::= #'[\n\v\f\r]' | '\r\n'
+<linear-space> ::= #'[ \t]'
+<alpha> ::= #'[a-zA-Z]'
+<digit> ::= #'[0-9]'
+<hex-digit> ::= <digit> | #'[a-fA-F]'
+<end-of-file> ::= #'$'
diff --git a/docs/info/specification.texi b/docs/info/specification.texi
index e1c9d76..707d932 100644
--- a/docs/info/specification.texi
+++ b/docs/info/specification.texi
@@ -19,93 +19,4 @@ This is the O Programming Language EBNF grammar specification[^1]
NOTE: This grammar spec is a DRAFT and it covers only a small portion of the
language.
-@verbatim
-(* Entry Point *)
-<translation-unit> ::= (<ows> <external-declaration> <ows> (<end-of-statement> | <end-of-file>))*
-
-(* Translation Unit *)
-<external-declaration> ::= <common-statement> | <function-definition>
-
-(* Variables *)
-<variable-definition> ::= 'var' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>?
-<constant-definition> ::= 'const' <ws> <variable-name> <ows> ':' <ows> <type> <ows> <variable-initializer>
-<variable-name> ::= <identifier>
-<variable-initializer> ::= '=' <ows> <expression>
-
-(* Functions *)
-<function-definition> ::= 'fn' <ws> <function-name> <ows> '(' ( <ows> | <ows> <function-params> <ows> ) ')' <ows> ':' <ows> <return-type> <ows> <function-body>
-<function-name> ::= <identifier>
-<function-params> ::= <identifier> <ows> ':' <ows> <type> ( <ows> ',' <function-params>)*
-<return-type> ::= <type>
-<function-body> ::= <block>
-<block> ::= '{' <ows> <statement> <ows> (<end-of-statement> <ows> <statement> <ows>)* <end-of-statement>? <ows> '}'
-<function-args> ::= <expression> (<ows> ',' <function-args>)*
-<function-call> ::= <function-name> <ows> '(' ( <ows> | <ows> <function-args> <ows> ) ')'
-<statement> ::= <common-statement> | <if-statement> | <while-statement> | <return-statement> | <function-call>
-<if-statement> ::= 'if' <ws> <expression> <ows> <block> ( <ows> 'else' ( <ows> <block> | <ows> <if-statement> ) )?
-<while-statement> ::= 'while' <ws> <expression> <ows> <block>
-<return-statement> ::= 'return' <ws> <expression>
-
-(* Statements *)
-<end-of-statement> ::= ';' | <line-break>
-<common-statement> ::= <variable-definition> | <constant-definition> | <expression>
-<assignment-operator> ::= '='
- | '*='
- | '/='
- | '%='
- | '+='
- | '-='
- | '<<='
- | '>>='
- | '&='
- | '^='
- | '|='
-
-(* Expressions *)
-<expression> ::= <binary-expression>
-<binary-expression> ::= <assignment-expression>
-<assignment-expression> ::= <logical-or-expression> (<ows> <assignment-operator> <ows> <logical-or-expression>)*
-<logical-or-expression> ::= <logical-and-expression> (<ows> '||' <ows> <logical-and-expression>)*
-<logical-and-expression> ::= <bitwise-or-expression> (<ows> '&&' <ows> <bitwise-or-expression>)*
-<bitwise-or-expression> ::= <bitwise-xor-expression> (<ows> '|' <ows> <bitwise-xor-expression>)*
-<bitwise-xor-expression> ::= <bitwise-and-expression> (<ows> '^' <ows> <bitwise-and-expression>)*
-<bitwise-and-expression> ::= <cmp-equality-expression> (<ows> '&' <ows> <cmp-equality-expression>)*
-<cmp-equality-expression> ::= <cmp-relational-expression> (<ows> ('==' | '!=') <ows> <cmp-relational-expression>)*
-<cmp-relational-expression> ::= <bitwise-shift-expression> (<ows> ('<' | '>' | '<=' | '>=') <ows> <bitwise-shift-expression>)*
-<bitwise-shift-expression> ::= <additive-expression> (<ows> ('<<' | '>>') <ows> <additive-expression>)*
-<additive-expression> ::= <multiplicative-expression> (<ows> ('+' | '-') <ows> <multiplicative-expression>)*
-<multiplicative-expression> ::= <primary-expression> (<ows> ('*' | '/' | '%') <ows> <primary-expression>)*
-<primary-expression> ::= <integer-literal>
- | <variable-name>
- | <function-call>
- | <unary-expression>
- | '(' <ows> <expression> <ows> ')'
-
-<unary-expression> ::= <unary-operator> <ows> <primary-expression>
-<unary-operator> ::= '&'
- | '*'
- | '+'
- | '-'
- | '~'
- | '!'
-
-(* Identifiers *)
-<type> ::= 'u32'
-<identifier> ::= (<alpha> | '_') (<alpha> | <digit> | '_')*
-
-(* Literals *)
-<integer-literal> ::= <integer-base10> | <integer-base16>
-<integer-base10> ::= #'[1-9]' (<digit> | '_')* | '0'
-<integer-base16> ::= #'0[Xx]' <hex-digit> (<hex-digit> | '_')*
-
-(* Utilities *)
-<ws> ::= <white-space>+
-<ows> ::= <white-space>*
-<white-space> ::= <linear-space> | <line-break>
-<line-break> ::= #'[\n\v\f\r]' | '\r\n'
-<linear-space> ::= #'[ \t]'
-<alpha> ::= #'[a-zA-Z]'
-<digit> ::= #'[0-9]'
-<hex-digit> ::= <digit> | #'[a-fA-F]'
-<end-of-file> ::= #'$'
-@end verbatim
+@verbatiminclude olang.ebnf
base-commit: 3c15dde88c22d4d4703b23cbb1b29490371e9128
--
2.46.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-10-11 1:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-10-11 3:24 [PATCH olang v1] spec: add contrib bin script for validating olang spec Johnny Richard
2024-10-11 1:25 ` [olang/patches/.build.yml] build success builds.sr.ht
2024-10-11 1:27 ` [PATCH olang v1] spec: add contrib bin script for validating olang spec Carlos Maniero
2024-10-11 3:28 ` Johnny Richard
Code repositories for project(s) associated with this public inbox
https://git.johnnyrichard.com/olang.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox