From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id uK45LW9+CGfQVQEAe85BDQ:P1 (envelope-from ) for ; Fri, 11 Oct 2024 03:25:03 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id uK45LW9+CGfQVQEAe85BDQ (envelope-from ) for ; Fri, 11 Oct 2024 03:25:03 +0200 X-Envelope-To: patches@johnnyrichard.com Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=Zl7ulwgE; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=cTbabCa0; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht ARC-Seal: i=1; s=key1; d=johnnyrichard.com; t=1728609903; a=rsa-sha256; cv=none; b=c94dKiegON2TGtZUVh5ZzWbPQrxE2A9VPGDokqdPJEb7rc1YIkcnJy+beM7Me7Uq7Sf7m9 hf8QHXl1xFMfNtu0ylZqapai+o2oSD++TzLDkErmZF2Q3HufZONUOYtUioEv4EaX2aipDD 34TYCe0TeMqasv4YWTP71VTt1/l8Hb1kn4JQzeGGrW4URaQ5Z+9Fcwg8LN48LKBdZ/gR3W vbLLQPGzCEuasFJEtZ7F9m5xr8VdQYb+VNWZmyx6nieKF6UiS2V5+yNNWTKCfwrzAAjpHz evz6LMJwgVARgLkP+ysvhSa3KQQunuqhMNKyx1kCO+Y7gEv4hCNaUhW5KlKLdA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=lists.sr.ht header.s=20240113 header.b=Zl7ulwgE; dkim=pass header.d=johnnyrichard.com header.s=key1 header.b=cTbabCa0; dmarc=pass (policy=quarantine) header.from=johnnyrichard.com; spf=pass (aspmx1.migadu.com: domain of lists@sr.ht designates 46.23.81.152 as permitted sender) smtp.mailfrom=lists@sr.ht ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1728609903; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=PXZs4qe/zTy2jh8eCYbwKgg/KCJKGdaaB5fvTz43p2k=; b=vv04Hj6gSu+C5y9ywFlOwj1J0QZhbtFxECHGIBEMs8Bzd6lxYQYzIMVld265aJXtedn92s 2m04ZTVYDhufUknDQQFwnr1nLj/6x2kJzitT+frAfFvU7lrXOLriKHzkVJn9WqSStQ+7bM SOLi72sgEwXggG2U1aCqMTybQX3/c5qFuhoAa6LlNpTj1XxTmZgQXqK6WvipR3xFCkubWR gud5YFtBJAuVUDdcno3mDY1BnLREBA1A04eNBOjzG2OQzBIboJg07QdpTL+NS1puhg10MF vKcahTcjPRXbC2nd677nWggUvcLBo35++uumThjrZi8HMJ6IDfDrip0TNu8TvQ== Received: from mail-a.sr.ht (mail-a.sr.ht [46.23.81.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 2431F1BA19 for ; Fri, 11 Oct 2024 03:25:02 +0200 (CEST) DKIM-Signature: a=rsa-sha256; bh=aCHam7o6qihlX+WDaNVNpjX/ZOTB0vZksYkTR9Fpm0M=; c=simple/simple; d=lists.sr.ht; h=From:To:Cc:Subject:Date:List-Unsubscribe:List-Subscribe:List-Archive:List-Post:List-ID; q=dns/txt; s=20240113; t=1728609901; v=1; b=Zl7ulwgEyJhxPyV4CgGlEG8lqI0qwjFNIpj10tGTkE4WNeA/Yuu4p5OD1AASa1KA4KDS/2D9 vs9kUGkil9B3QMw8vP9sMJQmg6S1b7BEY+a7zmuLZkDf27FuXuCy6xVuWrAVkKOMlsYXcgqts5P Zw3zuQi/EOwY6liiLRQK9BtC6BhsYb5aIUJ3J/maaYO6psMTMoaxgvkKwkSAOGq58dKzenDvJdn clOZxofFJ9n1ByzAmwpep1lPNCwieXcxXm2T4KRflp8bN7/EWnMfohLFHBwbmI3QhaXNsWmKkBC jv5zVsi3MFSV99bR2ncXJxJJaBFLpZo1cOP1KiRTf2FFQ== Received: from lists.sr.ht (unknown [46.23.81.154]) by mail-a.sr.ht (Postfix) with ESMTPSA id 9F84620237 for ; Fri, 11 Oct 2024 01:25:01 +0000 (UTC) Received: from out-178.mta1.migadu.com (out-178.mta1.migadu.com [95.215.58.178]) by mail-a.sr.ht (Postfix) with ESMTPS id EBA172022B for <~johnnyrichard/olang-devel@lists.sr.ht>; Fri, 11 Oct 2024 01:25:00 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=johnnyrichard.com; s=key1; t=1728609900; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=PXZs4qe/zTy2jh8eCYbwKgg/KCJKGdaaB5fvTz43p2k=; b=cTbabCa0EuWgzlfas3nCCikJZLFbTaOKfICXJJecxYzgBU61DLOCf0ZTmDNM0pifSJmrOs GJ1OOnzVz09VK8VUtEoqcIZWoZGrjSmni/uoJe5eQyT2YIidrtHwdLh2fKQEtVOaUExAbQ hqpBd5MPXRnhEJTHEGcTE3CLJWTub1WTnu1uN6agaI6PYQ+4Aka+rIIYdSKxnq8JtjgG2X CIrqvPwo+hIJCCdydzKjiAyVesMjFnOP10I/hMip4rr9DaAsaPTF2Ug711az5hy620RQ/H ts8x5jctIBiDkXrEAISqUsUqprsiBY9HDO7FRMRL30PATYJKKC5Cy0dYdpaytA== From: Johnny Richard To: ~johnnyrichard/olang-devel@lists.sr.ht Cc: Johnny Richard Subject: [PATCH olang v1] spec: add contrib bin script for validating olang spec Date: Fri, 11 Oct 2024 05:24:01 +0200 Message-ID: <20241011032423.102012-1-johnny@johnnyrichard.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Sourcehut-Patchset-Status: PROPOSED List-Unsubscribe: List-Subscribe: List-Archive: Archived-At: List-Post: List-ID: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel.lists.sr.ht> Sender: ~johnnyrichard/olang-devel <~johnnyrichard/olang-devel@lists.sr.ht> X-Migadu-Flow: FLOW_IN X-Migadu-Country: NL X-Migadu-Spam-Score: -0.80 X-Spam-Score: -0.80 X-Migadu-Queue-Id: 2431F1BA19 X-Migadu-Scanner: mx12.migadu.com X-TUID: uNjiE/Cs1Cgd 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 --- .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 . + +(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 . + +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 *) + ::= | + +(* Variables *) + ::= 'var' ':' ? + ::= 'const' ':' + ::= + ::= '=' + +(* Functions *) + ::= 'fn' '(' ( | ) ')' ':' + ::= + ::= ':' ( ',' )* + ::= + ::= + ::= '{' ( )* ? '}' + ::= ( ',' )* + ::= '(' ( | ) ')' + ::= | | | | + ::= 'if' ( 'else' ( | ) )? + ::= 'while' + ::= 'return' + +(* Statements *) + ::= ';' | + ::= | | + ::= '=' + | '*=' + | '/=' + | '%=' + | '+=' + | '-=' + | '<<=' + | '>>=' + | '&=' + | '^=' + | '|=' + +(* Expressions *) + ::= + ::= + ::= ( )* + ::= ( '||' )* + ::= ( '&&' )* + ::= ( '|' )* + ::= ( '^' )* + ::= ( '&' )* + ::= ( ('==' | '!=') )* + ::= ( ('<' | '>' | '<=' | '>=') )* + ::= ( ('<<' | '>>') )* + ::= ( ('+' | '-') )* + ::= ( ('*' | '/' | '%') )* + ::= + | + | + | + | '(' ')' + ::= + ::= '&' + | '*' + | '+' + | '-' + | '~' + | '!' + +(* Identifiers *) + ::= ('u8' | 'u16' | 'u32' | 'u64') ( '*')* + + ::= ( | '_') ( | | '_')* + +(* Literals *) + ::= | + ::= #'[1-9]' ( | '_')* | '0' + ::= #'0[Xx]' ( | '_')* + +(* Utilities *) + ::= '#' #'[^\n]*' + ::= + + ::= * + ::= | + ::= #'[\n\v\f\r]' | '\r\n' + ::= #'[ \t]' + ::= #'[a-zA-Z]' + ::= #'[0-9]' + ::= | #'[a-fA-F]' + ::= #'$' 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 *) - ::= | - -(* Variables *) - ::= 'var' ':' ? - ::= 'const' ':' - ::= - ::= '=' - -(* Functions *) - ::= 'fn' '(' ( | ) ')' ':' - ::= - ::= ':' ( ',' )* - ::= - ::= - ::= '{' ( )* ? '}' - ::= ( ',' )* - ::= '(' ( | ) ')' - ::= | | | | - ::= 'if' ( 'else' ( | ) )? - ::= 'while' - ::= 'return' - -(* Statements *) - ::= ';' | - ::= | | - ::= '=' - | '*=' - | '/=' - | '%=' - | '+=' - | '-=' - | '<<=' - | '>>=' - | '&=' - | '^=' - | '|=' - -(* Expressions *) - ::= - ::= - ::= ( )* - ::= ( '||' )* - ::= ( '&&' )* - ::= ( '|' )* - ::= ( '^' )* - ::= ( '&' )* - ::= ( ('==' | '!=') )* - ::= ( ('<' | '>' | '<=' | '>=') )* - ::= ( ('<<' | '>>') )* - ::= ( ('+' | '-') )* - ::= ( ('*' | '/' | '%') )* - ::= - | - | - | - | '(' ')' - - ::= - ::= '&' - | '*' - | '+' - | '-' - | '~' - | '!' - -(* Identifiers *) - ::= 'u32' - ::= ( | '_') ( | | '_')* - -(* Literals *) - ::= | - ::= #'[1-9]' ( | '_')* | '0' - ::= #'0[Xx]' ( | '_')* - -(* Utilities *) - ::= + - ::= * - ::= | - ::= #'[\n\v\f\r]' | '\r\n' - ::= #'[ \t]' - ::= #'[a-zA-Z]' - ::= #'[0-9]' - ::= | #'[a-fA-F]' - ::= #'$' -@end verbatim +@verbatiminclude olang.ebnf base-commit: 3c15dde88c22d4d4703b23cbb1b29490371e9128 -- 2.46.0