From 5718c319424a21b64e1b50dbb6aae644715b9e85 Mon Sep 17 00:00:00 2001 From: Adrian Thurston Date: Sun, 8 Mar 2020 22:21:58 +0200 Subject: forked off ragel, keeping libfsm and rlhc in colm repository Split off ragel, leaving behind libfsm and the rlhc code. Intend to use both of those components in colm. --- Makefile.am | 2 +- configure.ac | 4 +- ragel/.gitignore | 1 - ragel/Makefile.am | 82 +----- ragel/host-asm/.gitignore | 13 - ragel/host-asm/CMakeLists.txt | 24 -- ragel/host-asm/Makefile.am | 30 -- ragel/host-asm/main.cc | 33 --- ragel/host-asm/rlparse.lm | 204 ------------- ragel/host-c/.gitignore | 14 - ragel/host-c/CMakeLists.txt | 34 --- ragel/host-c/Makefile.am | 32 -- ragel/host-c/main.cc | 47 --- ragel/host-c/rlhc.lm | 462 ----------------------------- ragel/host-c/rlparse.lm | 203 ------------- ragel/host-crack/.gitignore | 13 - ragel/host-crack/CMakeLists.txt | 34 --- ragel/host-crack/Makefile.am | 32 -- ragel/host-crack/main.cc | 63 ---- ragel/host-crack/ragel-crack.lm | 150 ---------- ragel/host-crack/rlhc.lm | 536 ---------------------------------- ragel/host-crack/rlparse.lm | 202 ------------- ragel/host-csharp/.gitignore | 13 - ragel/host-csharp/CMakeLists.txt | 34 --- ragel/host-csharp/Makefile.am | 32 -- ragel/host-csharp/main.cc | 72 ----- ragel/host-csharp/rlhc.lm | 480 ------------------------------ ragel/host-csharp/rlparse.lm | 202 ------------- ragel/host-d/.gitignore | 13 - ragel/host-d/CMakeLists.txt | 34 --- ragel/host-d/Makefile.am | 32 -- ragel/host-d/main.cc | 72 ----- ragel/host-d/rlhc.lm | 511 -------------------------------- ragel/host-d/rlparse.lm | 211 -------------- ragel/host-go/.gitignore | 13 - ragel/host-go/CMakeLists.txt | 34 --- ragel/host-go/Makefile.am | 34 --- ragel/host-go/main.cc | 70 ----- ragel/host-go/out-go.lm | 47 --- ragel/host-go/rlhc.lm | 407 -------------------------- ragel/host-go/rlparse.lm | 202 ------------- ragel/host-java/.gitignore | 13 - ragel/host-java/CMakeLists.txt | 34 --- ragel/host-java/Makefile.am | 32 -- ragel/host-java/main.cc | 64 ---- ragel/host-java/rlhc.lm | 504 -------------------------------- ragel/host-java/rlparse.lm | 202 ------------- ragel/host-js/.gitignore | 13 - ragel/host-js/CMakeLists.txt | 34 --- ragel/host-js/Makefile.am | 32 -- ragel/host-js/main.cc | 66 ----- ragel/host-js/rlhc.lm | 504 -------------------------------- ragel/host-js/rlparse.lm | 202 ------------- ragel/host-julia/.gitignore | 13 - ragel/host-julia/CMakeLists.txt | 34 --- ragel/host-julia/Makefile.am | 32 -- ragel/host-julia/main.cc | 60 ---- ragel/host-julia/rlhc.lm | 561 ------------------------------------ ragel/host-julia/rlparse.lm | 202 ------------- ragel/host-ocaml/.gitignore | 13 - ragel/host-ocaml/CMakeLists.txt | 34 --- ragel/host-ocaml/Makefile.am | 34 --- ragel/host-ocaml/main.cc | 59 ---- ragel/host-ocaml/rlhc.lm | 609 --------------------------------------- ragel/host-ocaml/rlparse.lm | 204 ------------- ragel/host-ruby/.gitignore | 13 - ragel/host-ruby/CMakeLists.txt | 34 --- ragel/host-ruby/Makefile.am | 32 -- ragel/host-ruby/main.cc | 58 ---- ragel/host-ruby/rlhc.lm | 527 --------------------------------- ragel/host-ruby/rlparse.lm | 203 ------------- ragel/host-ruby/ruby.dsc | 2 - ragel/host-rust/.gitignore | 13 - ragel/host-rust/CMakeLists.txt | 34 --- ragel/host-rust/Makefile.am | 32 -- ragel/host-rust/main.cc | 60 ---- ragel/host-rust/rlhc.lm | 522 --------------------------------- ragel/host-rust/rlparse.lm | 202 ------------- ragel/rlhc-c.lm | 462 +++++++++++++++++++++++++++++ ragel/rlhc-crack.lm | 536 ++++++++++++++++++++++++++++++++++ ragel/rlhc-csharp.lm | 480 ++++++++++++++++++++++++++++++ ragel/rlhc-d.lm | 511 ++++++++++++++++++++++++++++++++ ragel/rlhc-go.lm | 453 +++++++++++++++++++++++++++++ ragel/rlhc-java.lm | 504 ++++++++++++++++++++++++++++++++ ragel/rlhc-js.lm | 504 ++++++++++++++++++++++++++++++++ ragel/rlhc-julia.lm | 561 ++++++++++++++++++++++++++++++++++++ ragel/rlhc-ocaml.lm | 609 +++++++++++++++++++++++++++++++++++++++ ragel/rlhc-ruby.lm | 527 +++++++++++++++++++++++++++++++++ ragel/rlhc-rust.lm | 522 +++++++++++++++++++++++++++++++++ 89 files changed, 5676 insertions(+), 10008 deletions(-) delete mode 100644 ragel/host-asm/.gitignore delete mode 100644 ragel/host-asm/CMakeLists.txt delete mode 100644 ragel/host-asm/Makefile.am delete mode 100644 ragel/host-asm/main.cc delete mode 100644 ragel/host-asm/rlparse.lm delete mode 100644 ragel/host-c/.gitignore delete mode 100644 ragel/host-c/CMakeLists.txt delete mode 100644 ragel/host-c/Makefile.am delete mode 100644 ragel/host-c/main.cc delete mode 100644 ragel/host-c/rlhc.lm delete mode 100644 ragel/host-c/rlparse.lm delete mode 100644 ragel/host-crack/.gitignore delete mode 100644 ragel/host-crack/CMakeLists.txt delete mode 100644 ragel/host-crack/Makefile.am delete mode 100644 ragel/host-crack/main.cc delete mode 100644 ragel/host-crack/ragel-crack.lm delete mode 100644 ragel/host-crack/rlhc.lm delete mode 100644 ragel/host-crack/rlparse.lm delete mode 100644 ragel/host-csharp/.gitignore delete mode 100644 ragel/host-csharp/CMakeLists.txt delete mode 100644 ragel/host-csharp/Makefile.am delete mode 100644 ragel/host-csharp/main.cc delete mode 100644 ragel/host-csharp/rlhc.lm delete mode 100644 ragel/host-csharp/rlparse.lm delete mode 100644 ragel/host-d/.gitignore delete mode 100644 ragel/host-d/CMakeLists.txt delete mode 100644 ragel/host-d/Makefile.am delete mode 100644 ragel/host-d/main.cc delete mode 100644 ragel/host-d/rlhc.lm delete mode 100644 ragel/host-d/rlparse.lm delete mode 100644 ragel/host-go/.gitignore delete mode 100644 ragel/host-go/CMakeLists.txt delete mode 100644 ragel/host-go/Makefile.am delete mode 100644 ragel/host-go/main.cc delete mode 100644 ragel/host-go/out-go.lm delete mode 100644 ragel/host-go/rlhc.lm delete mode 100644 ragel/host-go/rlparse.lm delete mode 100644 ragel/host-java/.gitignore delete mode 100644 ragel/host-java/CMakeLists.txt delete mode 100644 ragel/host-java/Makefile.am delete mode 100644 ragel/host-java/main.cc delete mode 100644 ragel/host-java/rlhc.lm delete mode 100644 ragel/host-java/rlparse.lm delete mode 100644 ragel/host-js/.gitignore delete mode 100644 ragel/host-js/CMakeLists.txt delete mode 100644 ragel/host-js/Makefile.am delete mode 100644 ragel/host-js/main.cc delete mode 100644 ragel/host-js/rlhc.lm delete mode 100644 ragel/host-js/rlparse.lm delete mode 100644 ragel/host-julia/.gitignore delete mode 100644 ragel/host-julia/CMakeLists.txt delete mode 100644 ragel/host-julia/Makefile.am delete mode 100644 ragel/host-julia/main.cc delete mode 100644 ragel/host-julia/rlhc.lm delete mode 100644 ragel/host-julia/rlparse.lm delete mode 100644 ragel/host-ocaml/.gitignore delete mode 100644 ragel/host-ocaml/CMakeLists.txt delete mode 100644 ragel/host-ocaml/Makefile.am delete mode 100644 ragel/host-ocaml/main.cc delete mode 100644 ragel/host-ocaml/rlhc.lm delete mode 100644 ragel/host-ocaml/rlparse.lm delete mode 100644 ragel/host-ruby/.gitignore delete mode 100644 ragel/host-ruby/CMakeLists.txt delete mode 100644 ragel/host-ruby/Makefile.am delete mode 100644 ragel/host-ruby/main.cc delete mode 100644 ragel/host-ruby/rlhc.lm delete mode 100644 ragel/host-ruby/rlparse.lm delete mode 100644 ragel/host-ruby/ruby.dsc delete mode 100644 ragel/host-rust/.gitignore delete mode 100644 ragel/host-rust/CMakeLists.txt delete mode 100644 ragel/host-rust/Makefile.am delete mode 100644 ragel/host-rust/main.cc delete mode 100644 ragel/host-rust/rlhc.lm delete mode 100644 ragel/host-rust/rlparse.lm create mode 100644 ragel/rlhc-c.lm create mode 100644 ragel/rlhc-crack.lm create mode 100644 ragel/rlhc-csharp.lm create mode 100644 ragel/rlhc-d.lm create mode 100644 ragel/rlhc-go.lm create mode 100644 ragel/rlhc-java.lm create mode 100644 ragel/rlhc-js.lm create mode 100644 ragel/rlhc-julia.lm create mode 100644 ragel/rlhc-ocaml.lm create mode 100644 ragel/rlhc-ruby.lm create mode 100644 ragel/rlhc-rust.lm diff --git a/Makefile.am b/Makefile.am index 056db215..792f276a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,7 +19,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -SUBDIRS = colm ragel doc test +SUBDIRS = aapl colm ragel doc test DIST_SUBDIRS = $(SUBDIRS) aapl dist_doc_DATA = colm.vim diff --git a/configure.ac b/configure.ac index 8a518f8b..1eec5a06 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ dnl -dnl Copyright 2006-2018 Adrian Thurston +dnl Copyright 2006-2020 Adrian Thurston dnl dnl Permission is hereby granted, free of charge, to any person obtaining a copy @@ -20,7 +20,7 @@ dnl LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM dnl OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE dnl SOFTWARE. -AC_INIT(colm-suite, 1) +AC_INIT(colm, 0.14) RAGEL_VERSION="7.0" RAGEL_PUBDATE="January 2020" diff --git a/ragel/.gitignore b/ragel/.gitignore index d31bf206..78db4968 100644 --- a/ragel/.gitignore +++ b/ragel/.gitignore @@ -16,7 +16,6 @@ /rlhc.c /*.lo -/include # Parsing /parse.c diff --git a/ragel/Makefile.am b/ragel/Makefile.am index f247fba2..12c82946 100644 --- a/ragel/Makefile.am +++ b/ragel/Makefile.am @@ -1,6 +1,3 @@ -SUBDIRS = . host-ruby host-asm host-julia host-ocaml host-c \ - host-d host-csharp host-go host-java host-rust host-crack host-js - COLM_BIN = ../colm/colm COLM_WRAP = ../colm/colm-wrap COLM_LA = ../colm/libcolm.la @@ -12,12 +9,7 @@ RAGEL = @RAGEL@ # libfsm contains only the FSM construction code and the backend code # generators. It is useful for building code generators in programs not # connected to the ragel language. -# -# libragel contains the parse tree and other parsing support code. Everything -# except the reducers, which are specific to the frontends. -lib_LTLIBRARIES = libfsm.la libragel.la - -bin_PROGRAMS = ragel +lib_LTLIBRARIES = libfsm.la pkginclude_HEADERS = \ action.h fsmgraph.h ragel.h common.h \ @@ -25,7 +17,9 @@ pkginclude_HEADERS = \ # nodist_pkginclude_HEADERS = config.h -data_DATA = ragel.lm +data_DATA = ril.lm rlhc-main.lm \ + rlhc-c.lm rlhc-csharp.lm rlhc-go.lm rlhc-js.lm rlhc-ruby.lm \ + rlhc-crack.lm rlhc-d.lm rlhc-java.lm rlhc-julia.lm rlhc-ocaml.lm rlhc-rust.lm # # libfsm: state machine construction and direct code generation. @@ -57,21 +51,8 @@ nodist_libfsm_la_SOURCES = \ libfsm_la_LDFLAGS = -no-undefined -# -# libragel: ragel program minus host-specific code -# -libragel_la_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/colm/include -DBINDIR='"@bindir@"' - -dist_libragel_la_SOURCES = \ - parsedata.h parsetree.h inputdata.h pcheck.h reducer.h rlscan.h load.h \ - parsetree.cc longest.cc parsedata.cc inputdata.cc load.cc reducer.cc - -libragel_la_LDFLAGS = -no-undefined -libragel_la_LIBADD = libfsm.la $(COLM_LA) - if LINKER_NO_UNDEFINED libfsm_la_LDFLAGS += -Wl,--no-undefined -libragel_la_LDFLAGS += -Wl,--no-undefined endif # @@ -85,30 +66,6 @@ dist_ragel_SOURCES = \ nodist_ragel_SOURCES = \ parse.c rlreduce.cc -ragel_LDADD = libragel.la libfsm.la $(COLM_LA) -ragel_DEPENDENCIES = libragel.la libfsm.la $(COLM_LIBDEP) - -BUILT_SOURCES = \ - version.h \ - parse.c rlreduce.cc \ - include/ragel - -include/ragel: - mkdir -p include - ln -s .. include/ragel - -if WITH_RAGEL_KELBT -nodist_ragel_SOURCES += \ - rlscan.cc rlparse.cc rlparse.h - -BUILT_SOURCES += \ - rlscan.cc rlparse.cc rlparse.h -endif - -version.h: Makefile - echo '#define RAGEL_VERSION "@RAGEL_VERSION@"' > version.h - echo '#define RAGEL_PUBDATE "@RAGEL_PUBDATE@"' >> version.h - EXTRA_DIST = \ $(RAGEL_LM) \ rlscan.rl \ @@ -119,39 +76,8 @@ EXTRA_DIST = \ CLEANFILES = parse.c commit.cc rlhc.c -if WITH_RAGEL_KELBT -CLEANFILES += rlscan.cc rlparse.cc rlparse.h -endif - RAGEL_LM = \ rlparse.lm \ ragel.lm \ rlreduce.lm -parse.pack: $(RAGEL_LM) $(COLM_BINDEP) - $(COLM_WRAP) -c -b rlparseC -o $@ -p parse.c -m rlreduce.cc $< - -rlreduce.cc: parse.pack - $(COLM_WRAP) -o $@ $< - -parse.c: parse.pack - $(COLM_WRAP) -o $@ $< - -if WITH_RAGEL_KELBT - -# This dependency comes from the import of the parser defines into the scanner. -rlscan.cc: rlparse.h -inputdata.cc: rlparse.h - -ragel-rlscan.$(OBJEXT): rlscan.cc - -rlscan.cc: rlscan.rl - $(RAGEL) -G2 -I$(builddir) -o $@ $< - -rlparse.h: rlparse.kh - $(KELBT) -o $@ $< - -rlparse.cc: rlparse.kl rlparse.kh - $(KELBT) -o $@ $< - -endif diff --git a/ragel/host-asm/.gitignore b/ragel/host-asm/.gitignore deleted file mode 100644 index aac24809..00000000 --- a/ragel/host-asm/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile.in -/Makefile -/.deps -/.libs -/ragel-asm -/ragel-asm.exe -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake - diff --git a/ragel/host-asm/CMakeLists.txt b/ragel/host-asm/CMakeLists.txt deleted file mode 100644 index d1f22faa..00000000 --- a/ragel/host-asm/CMakeLists.txt +++ /dev/null @@ -1,24 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseAsm - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-asm main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-asm PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-asm - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-asm/Makefile.am b/ragel/host-asm/Makefile.am deleted file mode 100644 index 3a2ac07d..00000000 --- a/ragel/host-asm/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-asm - -ragel_asm_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_asm_SOURCES = main.cc - -nodist_ragel_asm_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_asm_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc - -EXTRA_DIST = rlparse.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseAsm -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - diff --git a/ragel/host-asm/main.cc b/ragel/host-asm/main.cc deleted file mode 100644 index 21f8a515..00000000 --- a/ragel/host-asm/main.cc +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" -#include "asm.h" - -extern struct colm_sections rlparseAsm; - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangAsm, &rlparseAsm, 0 ); - return id.main( argc, argv ); -} - diff --git a/ragel/host-asm/rlparse.lm b/ragel/host-asm/rlparse.lm deleted file mode 100644 index 911e3ea6..00000000 --- a/ragel/host-asm/rlparse.lm +++ /dev/null @@ -1,204 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-c/.gitignore b/ragel/host-c/.gitignore deleted file mode 100644 index 55892c4f..00000000 --- a/ragel/host-c/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -/.deps/ -/.libs/ -/Makefile -/Makefile.in -/ragel-c -/ragel-c.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc -/rlparse.pack - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-c/CMakeLists.txt b/ragel/host-c/CMakeLists.txt deleted file mode 100644 index 1c97a41c..00000000 --- a/ragel/host-c/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseC - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcC - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-c main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-c PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-c - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-c/Makefile.am b/ragel/host-c/Makefile.am deleted file mode 100644 index 680a09fe..00000000 --- a/ragel/host-c/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-c - -ragel_c_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_c_SOURCES = main.cc rlhc.c - -nodist_ragel_c_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_c_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseC -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcC -o $@ $< diff --git a/ragel/host-c/main.cc b/ragel/host-c/main.cc deleted file mode 100644 index 20c7e6da..00000000 --- a/ragel/host-c/main.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseC; -extern struct colm_sections rlhcC; - -const HostLang hostLangC_translated = -{ - hostTypesC, - 8, - 0, - true, - false, /* loopLabels */ - Translated, - GotoFeature, - &makeCodeGen, - &defaultOutFnC, - &genLineDirectiveTrans -}; - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangC_translated, &rlparseC, &rlhcC ); - return id.rlhcMain( argc, argv ); -} - diff --git a/ragel/host-c/rlhc.lm b/ragel/host-c/rlhc.lm deleted file mode 100644 index 0a2b6d97..00000000 --- a/ragel/host-c/rlhc.lm +++ /dev/null @@ -1,462 +0,0 @@ -include 'ril.lm' - -namespace c_out - - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`{ _IN_ item* _EX_ `} ] - - def c_out - [_IN_ _EX_ item*] -end - -namespace c_gen - global _: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case Stmt { - "{ - " [stmt_list( StmtList )] - "} - } - case Expr { - "([expr( Expr )])" - } - case Escape { - Str: str = $escape - "[Str.suffix( 1 )]" - } - default { - [Tok] - } - } - } - - void embedded_host( EmbeddedHost: embedded_host ) - { - switch EmbeddedHost - case Expr - { - "([tok_list( TL )])" - } - case Stmt - { - "{ - " [tok_list( TL )] - "} - } - case Bare - { - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case [EH: embedded_host] - { - [embedded_host( EH )] - } - case Paren - { - "([expr( expr )])" - } - case ArraySub - { - "[ident]\[[expr( expr )]\]" - } - case ArraySubField - { - "[ident]\[[expr( expr )]\].[Field]" - } - case Offset - { - "[ident] + [expr( expr )]" - } - case Deref - { - "(*( [expr(expr)] )) - } - case [`TRUE] - { - "1" - } - case [`FALSE] - { - "1" - } - case [N: `nil] - { - "0" - } - case [Number: number] - { - number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast `( T: type `) F: expr_factor] - { - "( [type( T )] ) [expr_factor( F )]" - } - default { - # Catches cases not specified - [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - [embedded_host( EH )] - } - case [ident O: `[ TL: expr C: `]] - { - [ident O expr( TL ) C] - } - case [I: ident `[ E: expr `] `. F: ident] - { - "[I]\[[ expr( E )]\].[F] - } - case [E1: embedded_host `-> E2: lvalue] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - lvalue( E2 ) - } - default { - # Catches cases not specified - [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - ['!' expr_factor_op( _expr_factor_op )] - } - case [T: `~ expr_factor_op] - { - ['~' expr_factor_op( _expr_factor_op )] - } - case [expr_factor] - { - [expr_factor( expr_factor )] - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - [expr_bitwise( _expr_bitwise ) A expr_factor_op( expr_factor_op )] - } - case [expr_factor_op] - { - [expr_factor_op( expr_factor_op )] - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - [expr_mult( _expr_mult ) T expr_bitwise( expr_bitwise )] - } - case [expr_bitwise] - { - [expr_bitwise( expr_bitwise )] - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - [expr_add( _expr_add ) Op expr_mult( expr_mult )] - } - case [expr_mult] - { - [expr_mult( expr_mult )] - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - [expr_shift( _expr_shift ) Op expr_add( expr_add )] - } - case [expr_add] - { - [expr_add( expr_add )] - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - [expr_test( _expr_test ) Op expr_shift( expr_shift )] - } - case [expr_shift] - { - [expr_shift( expr_shift )] - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case S8 - ['signed char '] - case S16 - ['short '] - case S32 - ['int '] - case S64 - ['long '] - case S128 - ['long long '] - case "uint" - ['unsigned int '] - default - [Type] - } - - void number( Number: number ) - { - switch Number - case Unsigned - "[uint]u" - default - [Number] - } - - void num_list( NumList: num_list ) - { - for Number: number in NumList - "[number( Number )], " - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - [embedded_host( EH )] - } - case [A: static_array] { - "static const [type(A.type)] " - "[A.ident] \[\] = { [num_list(A.num_list)] }; - } - case [V: static_value] { - "static const [V.type] [V.ident] = [V.number]; - } - case [ - `if `( IfExpr: expr `) - IfStmt: stmt - ElseIfClauseList: else_if_clause* - ElseClauseOpt: else_clause? - ] { - "if ( [expr(IfExpr)] ) - " [stmt(IfStmt)] - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - [`else `if `( ElseIfExpr: expr `) ElseIfStmt: stmt] - - "else if ( [expr(ElseIfExpr)] ) - " [stmt(ElseIfStmt)] - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - "else - " [stmt(ElseStmt)] - } - } - case [`while `( WhileExpr: expr `) WhileStmt: stmt] { - "while ( [expr(WhileExpr)] ) - " [stmt(WhileStmt)] - } - case [M: match_stmt] { - "switch ( [expr(M.E)] ) { - - for PB: pat_block in repeat( M.P ) { - "case [expr( PB.expr )]: - "[stmt_list( PB._repeat_stmt )] - "break; - } - - if match M.D [D: default_block] { - "default: - "[stmt_list( D._repeat_stmt )] - "break; - } - - "} - } - case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { - "switch ( [expr(SwitchExpr)] ) { - " [stmt_list(StmtList)] - "} - } - case [ES: expr_stmt] { - "[expr(ES.expr)]; - } - case [B: block] { - "{ - " [stmt_list(B.StmtList)] - "} - } - case [ - OptConst: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - "[OptConst] [type(Type)] [Ident]" - - if match OptInit [`= Init: expr] { - " = [expr(Init)] - } - - "; - } - case [Export: export_stmt] - { - "#define [Export.ident] [number(Export.number)] - } - case [fallthrough] - { - # Nothing needed here. - # C falls through by default. - } - case [Index: index_stmt] - { - "const [type(Index.type)] *[Index.ident] - - if match Index.opt_init [E: `= expr] { - [E expr(Index.opt_init.expr)] - } - - "; - } - case [CB: case_block] - { - "case [expr( CB.expr )]: - "[stmt_list( CB._repeat_stmt )] - "break; - } - case [DB: default_block] - { - "default: - "[stmt_list( DB._repeat_stmt )] - "break; - } - case [CL: case_label] - { - "case [expr( CL.expr )]: - } - case [AS: assign_stmt] - { - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - default { - # catches unspecified cases - [Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - _ = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - CO: c_out::c_out = _->finish() - - if CO { - send Output - [CO] - } - else { - send stderr - "failed to parse output: [_->error] - } - } -end - -void trans( Output: stream, Start: start ) -{ - c_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-c/rlparse.lm b/ragel/host-c/rlparse.lm deleted file mode 100644 index 0fd61bbf..00000000 --- a/ragel/host-c/rlparse.lm +++ /dev/null @@ -1,203 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end -end - - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-crack/.gitignore b/ragel/host-crack/.gitignore deleted file mode 100644 index a68a8a97..00000000 --- a/ragel/host-crack/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-crack -/ragel-crack.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-crack/CMakeLists.txt b/ragel/host-crack/CMakeLists.txt deleted file mode 100644 index e28b4fa7..00000000 --- a/ragel/host-crack/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseCrack - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcCrack - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-crack main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-crack PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-crack - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-crack/Makefile.am b/ragel/host-crack/Makefile.am deleted file mode 100644 index 676c7f25..00000000 --- a/ragel/host-crack/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-crack - -ragel_crack_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_crack_SOURCES = main.cc rlhc.c - -nodist_ragel_crack_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_crack_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseCrack -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcCrack -o $@ $< diff --git a/ragel/host-crack/main.cc b/ragel/host-crack/main.cc deleted file mode 100644 index dd45fd1b..00000000 --- a/ragel/host-crack/main.cc +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseCrack; -extern struct colm_sections rlhcCrack; - -/* - * Crack - */ -const char *defaultOutFnCrack( const char *inputFileName ) -{ - return fileNameFromStem( inputFileName, ".crk" ); -} - -HostType hostTypesCrack[] = -{ - { "byte", 0, "byte", false, true, true, 0, 0, 0, UCHAR_MAX, 1 }, - { "int32", 0, "int32", true, true, false, S32BIT_MIN, S32BIT_MAX, 0, 0, 4 }, - { "uint32", 0, "uint32", false, true, false, 0, 0, 0, U32BIT_MAX, 4 }, - { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, sizeof(int) }, - { "uint", 0, "uint", false, true, false, 0, 0, 0, UINT_MAX, sizeof(int) }, -}; - -const HostLang hostLangCrack = -{ - hostTypesCrack, - 5, - 0, - true, - false, /* loopLabels */ - Translated, - BreakFeature, - &makeCodeGen, - &defaultOutFnCrack, - &genLineDirectiveTrans -}; - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangCrack, &rlparseCrack, &rlhcCrack ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-crack/ragel-crack.lm b/ragel/host-crack/ragel-crack.lm deleted file mode 100644 index b6480012..00000000 --- a/ragel/host-crack/ragel-crack.lm +++ /dev/null @@ -1,150 +0,0 @@ -namespace crack_inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token c_any / any / - end - - def inline_expr - [expr_item*] - - def expr_item - [expr_any] :ExprAny - | [expr_symbol] :ExprSymbol - | [expr_interpret] :ExprInterpret - - def expr_any - [whitespace] - | [comment] - | [string] - | [number] - | [hex_number] - | [ident] - | [c_any] - - def expr_symbol - [`,] | [`(] | [`)] | [`*] | [`::] - - def expr_interpret - [`fpc] :Fpc - | [`fc] :Fc - | [`fcurs] :Fcurs - | [`ftargs] :Ftargs - | [`fentry `( state_ref srlex::`)] :Fentry - - def state_ref - [opt_name_sep state_ref_names] - - def opt_name_sep - [srlex::`::] :ColonColon - | [] :Empty - - # List of names separated by :: - def state_ref_names - [state_ref_names srlex::`:: srlex::word] :Rec - | [srlex::word] :Base - - def inline_block - [block_item*] - - def block_item - [expr_any] :ExprAny - | [block_symbol] :BlockSymbol - | [block_interpret] :BlockInterpret - | [`{ inline_block `}] :RecBlock - - def block_symbol - [`,] | [`;] | [`(] | [`)] | [`*] | [`::] - - def block_interpret - [expr_interpret] :ExprInterpret - | [`fhold whitespace? `;] :Fhold - | [`fgoto whitespace? `* inline_expr `;] :FgotoExpr - | [`fnext whitespace? `* inline_expr `;] :FnextExpr - | [`fcall whitespace? `* inline_expr `;] :FcallExpr - | [`fncall whitespace? `* inline_expr `;] :FncallExpr - | [`fexec inline_expr `;] :Fexec - | [`fgoto state_ref srlex::`;] :FgotoSr - | [`fnext state_ref srlex::`;] :FnextSr - | [`fcall state_ref srlex::`;] :FcallSr - | [`fncall state_ref srlex::`;] :FncallSr - | [`fret `;] :Fret - | [`fnret `;] :Fnret - | [`fbreak `;] :Fbreak - | [`fnbreak `;] :Fnbreak -end - - -namespace crack_host - lex - literal `%%{ - - token slr /'%%' [^{] [^\n]* '\n'/ - { - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "\n}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - rl bt_literal - / '`' ([^`\\] | NL | '\\' (any | NL))* '`' / - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - /c_comment | cpp_comment/ - - token string - / s_literal | d_literal | bt_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [ident] - | [number] - | [hex_number] - | [comment] - | [string] - | [whitespace] - | [c_any] - - def section - [`%%{ ragel::ragel_start ragel::`}%%] :MultiLine - | [tok] :Tok -end - - diff --git a/ragel/host-crack/rlhc.lm b/ragel/host-crack/rlhc.lm deleted file mode 100644 index bebe7cd5..00000000 --- a/ragel/host-crack/rlhc.lm +++ /dev/null @@ -1,536 +0,0 @@ -include 'ril.lm' - -namespace crack_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" | - "`" ( [^`\\] | '\\' any ) * "`" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`{ _IN_ item* _EX_ `} ] - - def crack_out - [_IN_ _EX_ item*] -end - -namespace crack_gen - - global Parser: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] { - send Parser - "if ( 1 ) { - " [stmt_list( StmtList )] - "} - } - case [host::`={ Expr: expr host::`}=] { - send Parser - "([expr( Expr )])" - } - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default { - send Parser - [Tok] - } - } - } - - void embedded_host( EmbeddedHost: embedded_host ) - { - switch EmbeddedHost - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - "if ( 1 ) { - " [tok_list( TL )] - "} - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [`( E: expr `)] - { - send Parser - "([expr(E)])" - } - case [I: ident `[ E: expr `]] - { - send Parser - "[I]\[[expr( E )]\]" - } - case [`offset `( ident `, expr `)] - { - send Parser - [expr( ExprFactor.expr )] - } - case [`deref `( ident `, expr `)] - { - send Parser - [ ExprFactor.ident '[' expr( ExprFactor.expr ) ']'] - } - case [`TRUE] - { - send Parser "1" - } - case [`FALSE] - { - send Parser "1" - } - case [N: `nil] - { - send Parser "0" - } - case [Number: number] - { - number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast `( T: type `) F: expr_factor] - { - send Parser - "[type( T )] ( [expr_factor( F )] )" - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' E ']'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case [E1: embedded_host `-> E2: lvalue] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - lvalue( E2 ) - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' E ']'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [T: `~ expr_factor_op] - { - send Parser [T] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - expr_bitwise( ExprBitwise._expr_bitwise ) - send Parser [A] - expr_factor_op( ExprBitwise.expr_factor_op ) - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - send Parser [Op] - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - send Parser [Op] - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case "s8" - send Parser ['int16 '] - case "s16" - send Parser ['int16 '] - case "s32" - send Parser ['int32 '] - case "s64" - send Parser ['int64 '] - case "s128" - send Parser ['long long '] - case "uint" - send Parser ['uint32 '] - default - send Parser [Type] - } - - void number( Number: number ) - { - switch Number - case [`u `( uint `) ] - send Parser "[Number.uint]u" - case [`c `( uint `) ] - send Parser "[Number.uint]" - default - send Parser [Number] - } - - void num_list( NumList: num_list ) - { - for Number: number in NumList - send Parser "[number( Number )], " - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [Array: static_array] { - send Parser - "const array\[[type(Array.type)]\] " - "[Array.ident] = \[ [num_list(Array.num_list)] \]; - } - case [Value: static_value] { - send Parser - "const [Value.type] [Value.ident] = [Value.number]; - } - case [ - `if `( IfExpr: expr `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if ( [expr(IfExpr)] ) - " [flow_stmt(IfStmt)] - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] - - send Parser - "else if ( [expr(ElseIfExpr)] ) - " [flow_stmt(ElseIfStmt)] - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else - " [flow_stmt(ElseStmt)] - } - } - case [`while `( WhileExpr: expr `) WhileStmt: stmt] { - send Parser - "while ( [expr(WhileExpr)] ) - " [flow_stmt(WhileStmt)] - } - case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { - - require StmtList - [`case E1: expr `{ Inner: stmt* `} Rest: stmt*] - - send Parser - "if ( [expr(SwitchExpr)] == [expr(E1)] ) { - " [stmt_list(Inner)] - "} - - for S: stmt in repeat(Rest) { - switch S - case [`case E1: expr `{ Inner: stmt* `}] - { - send Parser - "else if ( [expr(SwitchExpr)] == [expr(E1)] ) { - " [stmt_list(Inner)] - "} - } - case - [`default `{ Inner: stmt* `}] - { - send Parser - "else { - " [stmt_list(Inner)] - "} - } - } - - send Parser - "; - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr(ExprExpr) Semi] - } - case [`{ TL: stmt* `}] { - send Parser - "if ( 1 ) { - " [stmt_list(TL)] - "} - } - case [ - TypeList: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - send Parser - [TypeList type(Type) Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - - send Parser - [Semi] - } - case [Export: export_stmt] - { - send Parser - "#define [Export.ident] [number(Export.number)] - } - case ['fallthrough' ';'] - { - # Nothing needed here. - } - case [Index: index_stmt] - { - send Parser - "int [Index.ident] - - if match Index.opt_init [E: `= expr] { - send Parser - [E expr(Index.opt_init.expr)] - } - else { - send Parser - " = 0" - } - - send Parser "; - } - case [case_block] - { - send Parser - "case [expr( Stmt.case_block.expr )]: - "[stmt_list( Stmt.case_block._repeat_stmt )] - "break; - } - case [default_block] - { - send Parser - "default: - "[stmt_list( Stmt.default_block._repeat_stmt )] - "break; - } - case [case_label] - { - send Parser - "case [expr( Stmt.case_label.expr )]: - } - case [AS: assign_stmt] - { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - default { - # catches unspecified cases - send Parser [Stmt] - } - } - - void flow_stmt( Stmt: stmt ) - { - switch Stmt - case [`{ TL: stmt* `}] { - send Parser - "{ - " [stmt_list(TL)] - "} - } - default { - stmt( Stmt ) - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - Parser = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - CO: crack_out::crack_out = Parser->finish() - - if CO { - send Output - [CO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } - } -end - -void trans( Output: stream, Start: start ) -{ - crack_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-crack/rlparse.lm b/ragel/host-crack/rlparse.lm deleted file mode 100644 index 100a9223..00000000 --- a/ragel/host-crack/rlparse.lm +++ /dev/null @@ -1,202 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-csharp/.gitignore b/ragel/host-csharp/.gitignore deleted file mode 100644 index 26f12644..00000000 --- a/ragel/host-csharp/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-csharp -/ragel-csharp.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-csharp/CMakeLists.txt b/ragel/host-csharp/CMakeLists.txt deleted file mode 100644 index 8d70e5a6..00000000 --- a/ragel/host-csharp/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseCSharp - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcCSharp - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-csharp main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-csharp PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-csharp - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-csharp/Makefile.am b/ragel/host-csharp/Makefile.am deleted file mode 100644 index e4f4fd71..00000000 --- a/ragel/host-csharp/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-csharp - -ragel_csharp_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_csharp_SOURCES = main.cc rlhc.c - -nodist_ragel_csharp_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_csharp_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseCSharp -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcCSharp -o $@ $< diff --git a/ragel/host-csharp/main.cc b/ragel/host-csharp/main.cc deleted file mode 100644 index fa5cb5a9..00000000 --- a/ragel/host-csharp/main.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseCSharp; -extern struct colm_sections rlhcCSharp; - -/* - * C# - */ - -const char *defaultOutFnCSharp( const char *inputFileName ) -{ - const char *ext = findFileExtension( inputFileName ); - if ( ext != 0 && strcmp( ext, ".rh" ) == 0 ) - return fileNameFromStem( inputFileName, ".h" ); - else - return fileNameFromStem( inputFileName, ".cs" ); -} - -HostType hostTypesCSharp[] = -{ - { "sbyte", 0, "sbyte", true, true, false, CHAR_MIN, CHAR_MAX, 0, 0, 1 }, - { "byte", 0, "byte", false, true, false, 0, 0, 0, UCHAR_MAX, 1 }, - { "short", 0, "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, 2 }, - { "ushort", 0, "ushort", false, true, false, 0, 0, 0, USHRT_MAX, 2 }, - { "char", 0, "char", false, true, true, 0, 0, 0, USHRT_MAX, 2 }, - { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, 4 }, - { "uint", 0, "uint", false, true, false, 0, 0, 0, UINT_MAX, 4 }, - { "long", 0, "long", true, true, false, LONG_MIN, LONG_MAX, 0, 0, 8 }, - { "ulong", 0, "ulong", false, true, false, 0, 0, 0, ULONG_MAX, 8 }, -}; - -const HostLang hostLangCSharp = -{ - hostTypesCSharp, - 9, - 4, - true, - false, /* loopLabels */ - Translated, - GotoFeature, - &makeCodeGen, - &defaultOutFnCSharp, - &genLineDirectiveTrans -}; - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangCSharp, &rlparseCSharp, &rlhcCSharp ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-csharp/rlhc.lm b/ragel/host-csharp/rlhc.lm deleted file mode 100644 index 078157c5..00000000 --- a/ragel/host-csharp/rlhc.lm +++ /dev/null @@ -1,480 +0,0 @@ -include 'ril.lm' - -namespace csharp_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`{ _IN_ item* _EX_ `} ] - - def csharp_out - [_IN_ _EX_ item*] -end - -namespace csharp_gen - - global Parser: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] - send Parser "{[stmt_list( StmtList )]}" - case [host::`={ Expr: expr host::`}=] - send Parser "([expr( Expr )])" - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default { - send Parser [Tok] - } - } - } - - void embedded_host( EH: embedded_host ) - { - switch EH - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - "{[tok_list( TL )]} - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case - [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [O:`( TL: expr C: `)] - { - send Parser - [O expr(TL) C] - } - case [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case ['offset' '(' ident ',' expr ')'] - { - send Parser - [expr( ExprFactor.expr )] - } - case ['deref' '(' ident ',' expr ')'] - { - send Parser - [ ExprFactor.ident '[' expr( ExprFactor.expr ) ']'] - } - case [T: `TRUE] - { - T.data = 'true' - send Parser [T] - } - case [F: `FALSE] - { - F.data = 'false' - send Parser [F] - } - case [N: `nil] - { - N.data = '0' - send Parser [N] - } - case [Number: number] - { - number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast Open: `( Type: type Close: `) expr_factor] - { - send Parser [Open] - type( Type ) - send Parser [Close] - expr_factor( ExprFactor._expr_factor ) - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case [E1: embedded_host `-> E2: lvalue] - { - embedded_host( E1 ) - lvalue( E2 ) - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [T: `~ expr_factor_op] - { - send Parser [T] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - expr_bitwise( ExprBitwise._expr_bitwise ) - send Parser [A] - expr_factor_op( ExprBitwise.expr_factor_op ) - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - send Parser [Op] - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - send Parser [Op] - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case "s8" - send Parser ['sbyte '] - case "s16" - send Parser ['short '] - case "s32" - send Parser ['int '] - case "s64" - send Parser ['long '] - case "s128" - send Parser ['long long '] - case "uint" - send Parser ['uint '] - default - send Parser [Type] - } - - void number( Number: number ) - { - switch Number - case [`c `( uint `) ] { - Str: str = $Number.uint - send Parser "'\\u[sprintf( "%04x", Str.atoi() )]'" - } - case [`u `( uint `) ] { - send Parser [$Number.uint] - } - default { - send Parser [$Number.sint] - } - } - - void num_list( NumList: num_list ) - { - for Number: number in NumList - send Parser "[number( Number )], " - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [A: static_array] { - send Parser - "static readonly [type(A.type)] \[\]" - "[A.ident] = { [num_list( A.num_list )] }; - } - case [V: static_value] { - send Parser - "static readonly [V.type] [V.ident] = [V.number]; - } - case [ - 'if' O: `( IfExpr: expr C: `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if ( [expr(IfExpr)] ) - " [stmt(IfStmt)] - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] - - send Parser - "else if ( [expr(ElseIfExpr)] ) - " [stmt(ElseIfStmt)] - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else - " [stmt(ElseStmt)] - } - } - case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { - send Parser - "while ( [expr(WhileExpr)] ) - " [stmt(WhileStmt)] - } - case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { - send Parser - "switch ( [expr(SwitchExpr)] ) { - " [stmt_list(StmtList)] - "} - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr(ExprExpr) Semi] - } - case [L: `{ TL: stmt* R: `}] { - send Parser - [L stmt_list(TL) R] - } - case [ - TypeList: opt_const Type: type Ident: ident - OptInit: opt_init Semi: `; - ] - { - send Parser - [TypeList type(Type) Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - - send Parser - [Semi] - } - case [Export: export_stmt] - { - send Parser - "#define [Export.ident] [Export.number] - } - case ['fallthrough' ';'] - { - # Nothing needed here. - } - case [Index: index_stmt] - { - send Parser - "int [Index.ident]" - - if match Index.opt_init [E: `= expr] { - send Parser - [E expr(Index.opt_init.expr)] - } - - send Parser ";" - } - case [case_block] - { - send Parser - "case [expr( Stmt.case_block.expr )]: - "[stmt_list( Stmt.case_block._repeat_stmt )] - "break; - } - case [default_block] - { - send Parser - "default: - "[stmt_list( Stmt.default_block._repeat_stmt )] - "break; - } - case [case_label] - { - send Parser - "case [expr( Stmt.case_label.expr )]: - } - case [AS: assign_stmt] - { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - default { - # catches unspecified cases - send Parser [Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - Parser = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - CSO: csharp_out::csharp_out = Parser->finish() - - if CSO { - send Output - [CSO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } - } -end - -void trans( Output: stream, Start: start ) -{ - csharp_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-csharp/rlparse.lm b/ragel/host-csharp/rlparse.lm deleted file mode 100644 index 100a9223..00000000 --- a/ragel/host-csharp/rlparse.lm +++ /dev/null @@ -1,202 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-d/.gitignore b/ragel/host-d/.gitignore deleted file mode 100644 index 353df34b..00000000 --- a/ragel/host-d/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-d -/ragel-d.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-d/CMakeLists.txt b/ragel/host-d/CMakeLists.txt deleted file mode 100644 index c302fabc..00000000 --- a/ragel/host-d/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseD - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcD - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-d main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-d PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-d - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-d/Makefile.am b/ragel/host-d/Makefile.am deleted file mode 100644 index aae8d6fe..00000000 --- a/ragel/host-d/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-d - -ragel_d_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_d_SOURCES = main.cc rlhc.c - -nodist_ragel_d_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_d_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseD -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcD -o $@ $< diff --git a/ragel/host-d/main.cc b/ragel/host-d/main.cc deleted file mode 100644 index f6eb7cbe..00000000 --- a/ragel/host-d/main.cc +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseD; -extern struct colm_sections rlhcD; - -/* - * D - */ - -const char *defaultOutFnD( const char *inputFileName ) -{ - const char *ext = findFileExtension( inputFileName ); - if ( ext != 0 && strcmp( ext, ".rh" ) == 0 ) - return fileNameFromStem( inputFileName, ".h" ); - else - return fileNameFromStem( inputFileName, ".d" ); -} - -HostType hostTypesD[] = -{ - { "byte", 0, "byte", true, true, false, CHAR_MIN, CHAR_MAX, 0, 0, 1 }, - { "ubyte", 0, "ubyte", false, true, false, 0, 0, 0, UCHAR_MAX, 1 }, - { "char", 0, "char", false, true, false, 0, 0, 0, UCHAR_MAX, 1 }, - { "short", 0, "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, 2 }, - { "ushort", 0, "ushort", false, true, false, 0, 0, 0, USHRT_MAX, 2 }, - { "wchar", 0, "wchar", false, true, false, 0, 0, 0, USHRT_MAX, 2 }, - { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, 4 }, - { "uint", 0, "uint", false, true, false, 0, 0, 0, UINT_MAX, 4 }, - { "dchar", 0, "dchar", false, true, false, 0, 0, 0, UINT_MAX, 4 }, -}; - -const HostLang hostLangD = -{ - hostTypesD, - 9, - 2, - true, - false, /* loopLabels */ - Translated, - GotoFeature, - &makeCodeGen, - &defaultOutFnD, - &genLineDirectiveTrans -}; - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangD, &rlparseD, &rlhcD ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-d/rlhc.lm b/ragel/host-d/rlhc.lm deleted file mode 100644 index 2a047e68..00000000 --- a/ragel/host-d/rlhc.lm +++ /dev/null @@ -1,511 +0,0 @@ -include 'ril.lm' - -namespace d_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`{ _IN_ item* _EX_ `} ] - - def d_out - [_IN_ _EX_ item*] -end - -namespace d_gen - - global Parser: parser - - global HasDefault: list = new list() - - void pushHasDef( H: int ) - { - HasDefault->push( H ) - } - - int popHasDef() - { - return HasDefault->pop() - } - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] - send Parser "{[stmt_list( StmtList )]}" - case [host::`={ Expr: expr host::`}=] - send Parser "([expr( Expr )])" - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default { - send Parser [Tok] - } - } - } - - void embedded_host( EmbeddedHost: embedded_host ) - { - switch EmbeddedHost - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - "{[tok_list( TL )]} - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host(EH)] - } - case - [O:`( TL: expr C: `)] - { - send Parser - [O expr( TL ) C] - } - case - [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr(TL) C] - } - case - [`offset `( ident `, expr `)] - { - send Parser - "& [ExprFactor.ident] \[ [expr(ExprFactor.expr)] \] - } - case - [`deref `( ident `, expr `)] - { - send Parser - "(*( [expr(ExprFactor.expr)] )) - } - case - [T: `TRUE] - { - T.data = '1' - send Parser [T] - } - case - [F: `FALSE] - { - F.data = '0' - send Parser [F] - } - case - [N: `nil] - { - N.data = 'null' - send Parser [N] - } - case - [Number: number] - { - number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast Open: `( Type: type Close: `) expr_factor] - { - send Parser ['cast' Open] - type( Type ) - send Parser [Close] - expr_factor( ExprFactor._expr_factor ) - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host(EH)] - } - case - [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr(TL) C] - } - case [E1: embedded_host `-> E2: lvalue] - { - embedded_host( E1 ) - lvalue( E2 ) - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [T: `~ expr_factor_op] - { - send Parser [T] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - expr_bitwise( ExprBitwise._expr_bitwise ) - send Parser [A] - expr_factor_op( ExprBitwise.expr_factor_op ) - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - send Parser [Op] - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - send Parser [Op] - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case "s8" - send Parser ['byte '] - case "s16" - send Parser ['short '] - case "s32" - send Parser ['int '] - case "s64" - send Parser ['long '] - case "s128" - send Parser ['long long '] - default - send Parser [Type] - } - - void number( Number: number ) - { - switch Number - case [`u `( uint `) ] - send Parser "[Number.uint]u" - default - send Parser [Number] - } - - void num_list( NumList: num_list ) - { - for Number: number in NumList - send Parser "[number( Number )], " - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host(EH)] - } - case [A: static_array] { - send Parser - "static const [type(A.type)]\[\] " - "[A.ident] = \[ [num_list( A.num_list )] \]; - } - case [V: static_value] { - send Parser - "static const [V.type] [V.ident] = [V.number]; - } - case [ - `if `( IfExpr: expr `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if ( [expr(IfExpr)] ) - " [stmt(IfStmt)] - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - [`else `if `( ElseIfExpr: expr `) ElseIfStmt: stmt] - - send Parser - "else if ( [expr(ElseIfExpr)] ) - " [stmt(ElseIfStmt)] - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else - " [stmt(ElseStmt)] - } - } - case [`while `( WhileExpr: expr `) WhileStmt: stmt] { - send Parser - "while ( [expr(WhileExpr)] ) - " [stmt(WhileStmt)] - } - case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { - pushHasDef( 0 ) - - send Parser - "switch ( [expr(SwitchExpr)] ) { - " [stmt_list(StmtList)] - - if ( popHasDef() == 0 ) { - send Parser - " default: break; - } - - send Parser - "} - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr( ExprExpr ) Semi] - } - case [L: `{ TL: stmt* R: `}] { - send Parser - [L stmt_list( TL ) R] - } - case [ - OptConst: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - if match OptConst ['const'] { - send Parser - "const( [type( Type )] ) - } - else { - type( Type ) - } - - send Parser [Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - - send Parser [Semi] - } - case [case_block] - { - send Parser - "case [expr( Stmt.case_block.expr )]: - "[stmt_list( Stmt.case_block._repeat_stmt )] - "break; - } - case [default_block] - { - send Parser - "default: - "[stmt_list( Stmt.default_block._repeat_stmt )] - "break; - - popHasDef() - pushHasDef( 1 ) - } - case [case_label] - { - send Parser - "case [expr( Stmt.case_label.expr )]: - } - case [export_stmt] - { - send Parser - "static const [type(Stmt.export_stmt.type)] " - "[Stmt.export_stmt.ident] = [number(Stmt.export_stmt.number)]; - } - case ['fallthrough' ';'] - { - send Parser "goto case;" - } - case [Index: index_stmt] - { - send Parser - "const([type(Index.type)]) *[Index.ident]" - - if match Index.opt_init [E: `= expr] { - send Parser - [E expr(Index.opt_init.expr)] - } - - send Parser "; - } - case [AS: assign_stmt] - { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - default { - # catches unspecified cases - send Parser [Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - Parser = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - DO: d_out::d_out = Parser->finish() - - if DO { - send Output - [DO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } - } -end - -void trans( Output: stream, Start: start ) -{ - d_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-d/rlparse.lm b/ragel/host-d/rlparse.lm deleted file mode 100644 index 05b21ea2..00000000 --- a/ragel/host-d/rlparse.lm +++ /dev/null @@ -1,211 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - else - { - if ( includeDepth == 0 ) { - id->curItem->data.write( "define ", 7 ); - id->curItem->data.write( $ident->data, $ident->length ); - id->curItem->data.write( " ", 1 ); - id->curItem->data.write( $number->data, $number->length ); - } - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-go/.gitignore b/ragel/host-go/.gitignore deleted file mode 100644 index b7a6e0cc..00000000 --- a/ragel/host-go/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-go -/ragel-go.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-go/CMakeLists.txt b/ragel/host-go/CMakeLists.txt deleted file mode 100644 index 2ae44311..00000000 --- a/ragel/host-go/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseGo - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcGo - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-go main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-go PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-go - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-go/Makefile.am b/ragel/host-go/Makefile.am deleted file mode 100644 index e775096d..00000000 --- a/ragel/host-go/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-go - -data_DATA = out-go.lm - -ragel_go_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_go_SOURCES = main.cc rlhc.c - -nodist_ragel_go_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_go_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm out-go.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseGo -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcGo -o $@ $< diff --git a/ragel/host-go/main.cc b/ragel/host-go/main.cc deleted file mode 100644 index 99fb50d7..00000000 --- a/ragel/host-go/main.cc +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseGo; -extern struct colm_sections rlhcGo; - -/* - * Go - */ - -const char *defaultOutFnGo( const char *inputFileName ) -{ - return fileNameFromStem( inputFileName, ".go" ); -} - -HostType hostTypesGo[] = -{ - { "byte", 0, "uint8", false, true, false, 0, 0, U8BIT_MIN, U8BIT_MAX, 1 }, - { "int8", 0, "int8", true, true, false, S8BIT_MIN, S8BIT_MAX, 0, 0, 1 }, - { "uint8", 0, "uint8", false, true, false, 0, 0, U8BIT_MIN, U8BIT_MAX, 1 }, - { "int16", 0, "int16", true, true, false, S16BIT_MIN, S16BIT_MAX, 0, 0, 2 }, - { "uint16", 0, "uint16", false, true, false, 0, 0, U16BIT_MIN, U16BIT_MAX, 2 }, - { "int32", 0, "int32", true, true, false, S32BIT_MIN, S32BIT_MAX, 0, 0, 4 }, - { "uint32", 0, "uint32", false, true, false, 0, 0, U32BIT_MIN, U32BIT_MAX, 4 }, - { "int64", 0, "int64", true, true, false, S64BIT_MIN, S64BIT_MAX, 0, 0, 8 }, - { "uint64", 0, "uint64", false, true, false, 0, 0, U64BIT_MIN, U64BIT_MAX, 8 }, - { "rune", 0, "int32", true, true, true, S32BIT_MIN, S32BIT_MAX, 0, 0, 4 }, -}; - -const HostLang hostLangGo = -{ - hostTypesGo, - 10, - 0, - false, - false, /* loopLabels */ - Translated, - GotoFeature, - &makeCodeGen, - &defaultOutFnGo, - &genLineDirectiveTrans -}; - - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangGo, &rlparseGo, &rlhcGo ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-go/out-go.lm b/ragel/host-go/out-go.lm deleted file mode 100644 index 63d2731b..00000000 --- a/ragel/host-go/out-go.lm +++ /dev/null @@ -1,47 +0,0 @@ -namespace out_go - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`{ _IN_ item* _EX_ `} ] - - def out_go - [_IN_ _EX_ item*] -end - - diff --git a/ragel/host-go/rlhc.lm b/ragel/host-go/rlhc.lm deleted file mode 100644 index ab75477d..00000000 --- a/ragel/host-go/rlhc.lm +++ /dev/null @@ -1,407 +0,0 @@ -include 'ril.lm' - -include 'out-go.lm' - -namespace go_gen - - global _: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case Stmt { - "{ - stmt_list( StmtList ) - "} - } - case Expr { - "([expr( Expr )])" - } - case Escape { - Str: str = $Tok - "[Str.suffix( 1 )]" - } - default { - [Tok] - } - } - } - - void embedded_host( EmbeddedHost: embedded_host ) - { - switch EmbeddedHost - case Expr - { - ['(' tok_list( TL ) ')'] - } - case Stmt - { - ['{' tok_list( TL ) '}\n'] - } - case Bare - { - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case EmbeddedHost - { - [embedded_host(embedded_host)] - } - case Paren - { - ['( ' expr(expr) ' )'] - } - case ArraySub - { - [ident '[ ' expr( expr ) ' ]'] - } - case Offset - { - "int([expr(expr )]) - } - case Deref - { - [ident '[ ' expr( expr ) ' ]' ] - } - case True - { - "true" - } - case False - { - "false" - } - case Nil - { - "0" - } - case Access - { - embedded_host(embedded_host) - expr_factor(_expr_factor) - } - case Cast - { - [type(type) '( ' expr_factor(_expr_factor) ' )' ] - } - default { - # Catches cases not specified - [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - [embedded_host(EH)] - } - case [ident `[ TL: expr `]] - { - [ident '[' expr( TL ) ']'] - } - case [E1: embedded_host `-> E2: lvalue] - { - embedded_host( E1 ) - lvalue( E2 ) - } - default { - # Catches cases not specified - [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - ['! ' expr_factor_op( _expr_factor_op )] - } - case [T: `~ expr_factor_op] - { - ['^ ' expr_factor_op( _expr_factor_op )] - } - case [expr_factor] - { - [expr_factor( ExprFactorOp.expr_factor )] - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - [expr_bitwise( _expr_bitwise ) ' & ' expr_factor_op( expr_factor_op )] - } - case [expr_factor_op] - { - [expr_factor_op( ExprBitwise.expr_factor_op )] - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - [expr_mult( _expr_mult ) ' * ' expr_bitwise( expr_bitwise )] - } - case [expr_bitwise] - { - [expr_bitwise( expr_bitwise )] - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - [expr_add( _expr_add ) ' ' Op ' ' expr_mult( expr_mult )] - } - case [expr_mult] - { - [expr_mult( ExprAdd.expr_mult )] - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - [expr_shift( _expr_shift ) ' ' Op ' ' expr_add( expr_add )] - } - case [expr_add] - { - [expr_add( expr_add )] - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - [expr_test( _expr_test ) ' ' Op ' ' expr_shift( expr_shift )] - } - case [expr_shift] - { - [expr_shift( ExprTest.expr_shift )] - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case S8 - ['int8'] - case S16 - ['int16'] - case S32 - ['int32'] - case S64 - ['int64'] - case S128 - ['long long'] - default - [Type] - } - - void number( Number: number ) - { - switch Number - case Unsigned - [uint] - default - [Number] - } - - void num_list( NumList: num_list ) - { - number( NumList.number ) - for CommaNum: comma_num in NumList { - [', ' number( CommaNum.number )] - } - } - - # Go must have {} around if and for statements. We strip any blocks from - # these statments and force our own. - void strip_block_stmt( Stmt: stmt ) - { - if match Stmt [`{ StmtList: stmt* `}] - stmt_list(StmtList) - else - stmt( Stmt ) - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - [embedded_host(EH)] - } - case [A: static_array] { - "var [A.ident] = \[\] " - "[type(A.type)] { [num_list(A.num_list)] } - } - case [V: static_value] { - "var [V.ident] [type(V.type)] = [V.number] - "var _ = [V.ident] - } - case [ - 'if' O: `( IfExpr: expr C: `) IfStmt: stmt - ] { - # if-statements with only the if clause can go out as an if. - "if [expr(IfExpr)] { - strip_block_stmt(IfStmt) - "} - } - case [ - 'if' O: `( IfExpr: expr C: `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - # If the if-statement has more than just an if clause it goes out as a switch. - "if [expr( IfExpr )] { - strip_block_stmt( IfStmt ) - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] - - "} else if [expr(ElseIfExpr)] { - strip_block_stmt(ElseIfStmt) - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - "} else { - strip_block_stmt(ElseStmt) - } - - "} - } - case ["while ( TRUE )" WhileStmt: stmt] { - "for { - strip_block_stmt(WhileStmt) - "} - } - case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { - "for [expr(WhileExpr)] { - strip_block_stmt(WhileStmt) - "} - } - case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { - "switch [expr(SwitchExpr)] { - stmt_list(StmtList) - "} - } - case [ExprExpr: expr `;] { - [expr(ExprExpr) ';'] - } - case [B: block] { - "{ - stmt_list(B.StmtList) - "} - } - case [D: declaration] - { - "var [D.ident] [type(D.type)]" - - if match D.opt_init ['=' Expr: expr] { - " = [expr(Expr)]" - } - ['\n'] - } - case [ES: export_stmt] - { - "#define [ES.ident] [number(ES.number)] - } - case [fallthrough] - { - "fallthrough - } - case [Index: index_stmt] - { - "var [Index.ident] int" - - if match Index.opt_init ['=' Expr: expr] { - " = [expr(Expr)]" - } - - ['\n'] - } - case [CB: case_block] - { - "case [expr( CB.expr )]: - stmt_list( CB._repeat_stmt ) - } - case [DB: default_block] - { - "default: - stmt_list( DB._repeat_stmt ) - } - case [CL: case_label] - { - "case [expr( CL.expr )]: - } - case [AS: assign_stmt] - { - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - default { - # catches unspecified cases - "[Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - _ = new parser() - Input: _input = _->gets() - Input->auto_trim(true) - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - GO: out_go::out_go = _->finish() - - if GO { - send Output - [GO] - } - else { - send stderr - "failed to parse output: [_->error] - } - - } -end - -void trans( Output: stream, Start: start ) -{ - go_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-go/rlparse.lm b/ragel/host-go/rlparse.lm deleted file mode 100644 index 100a9223..00000000 --- a/ragel/host-go/rlparse.lm +++ /dev/null @@ -1,202 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-java/.gitignore b/ragel/host-java/.gitignore deleted file mode 100644 index 9b83d82e..00000000 --- a/ragel/host-java/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-java -/ragel-java.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-java/CMakeLists.txt b/ragel/host-java/CMakeLists.txt deleted file mode 100644 index eb9fb876..00000000 --- a/ragel/host-java/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseJava - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcJava - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-java main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-java PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-java - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-java/Makefile.am b/ragel/host-java/Makefile.am deleted file mode 100644 index 44521de1..00000000 --- a/ragel/host-java/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-java - -ragel_java_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_java_SOURCES = main.cc rlhc.c - -nodist_ragel_java_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_java_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseJava -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcJava -o $@ $< diff --git a/ragel/host-java/main.cc b/ragel/host-java/main.cc deleted file mode 100644 index d4efd3fc..00000000 --- a/ragel/host-java/main.cc +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseJava; -extern struct colm_sections rlhcJava; - -/* - * Java - */ - -const char *defaultOutFnJava( const char *inputFileName ) -{ - return fileNameFromStem( inputFileName, ".java" ); -} - -HostType hostTypesJava[] = -{ - { "byte", 0, "byte", true, true, false, CHAR_MIN, CHAR_MAX, 0, 0, 1 }, - { "short", 0, "short", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, 2 }, - { "char", 0, "char", false, true, false, 0, 0, 0, USHRT_MAX, 2 }, - { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, 4 }, -}; - -const HostLang hostLangJava = -{ - hostTypesJava, - 4, - 2, - false, - true, /* loopLabels */ - Translated, - BreakFeature, - &makeCodeGen, - &defaultOutFnJava, - &genLineDirectiveTrans -}; - - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangJava, &rlparseJava, &rlhcJava ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-java/rlhc.lm b/ragel/host-java/rlhc.lm deleted file mode 100644 index a458369f..00000000 --- a/ragel/host-java/rlhc.lm +++ /dev/null @@ -1,504 +0,0 @@ -include 'ril.lm' - -namespace java_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`{ _IN_ item* _EX_ `} ] - - def java_out - [_IN_ _EX_ item*] -end - -namespace java_gen - - global Parser: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] { - send Parser - "{ - " [stmt_list( StmtList )] - "} - } - case [host::`={ Expr: expr host::`}=] - send Parser "([expr( Expr )])" - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default { - send Parser [Tok] - } - } - } - - void embedded_host( EH: embedded_host ) - { - switch EH - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - "{ - " [tok_list( TL )] - "} - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case - [O:`( TL: expr C: `)] - { - send Parser - [O expr(TL) C] - } - case - [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case - ['offset' '(' ident ',' expr ')'] - { - send Parser - [expr( ExprFactor.expr )] - } - case - ['deref' '(' ident ',' expr ')'] - { - send Parser - [ ExprFactor.ident '[' expr( ExprFactor.expr ) ']'] - } - case - [T: `TRUE] - { - T.data = 'true' - send Parser [T] - } - case - [F: `FALSE] - { - F.data = 'false' - send Parser [F] - } - case - [N: `nil] - { - N.data = '0' - send Parser [N] - } - case - [Number: number] - { - number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast Open: `( Type: type Close: `) expr_factor] - { - send Parser [Open] - type( Type ) - send Parser [Close] - expr_factor( ExprFactor._expr_factor ) - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' E ']'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case - [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case [E1: embedded_host `-> E2: lvalue] - { - embedded_host( E1 ) - lvalue( E2 ) - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' E ']'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [T: `~ expr_factor_op] - { - send Parser [T] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - expr_bitwise( ExprBitwise._expr_bitwise ) - send Parser [A] - expr_factor_op( ExprBitwise.expr_factor_op ) - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - send Parser [Op] - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - send Parser [Op] - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case "s8" - send Parser ['byte '] - case "s16" - send Parser ['short '] - case "s32" - send Parser ['int '] - case "s64" - send Parser ['long '] - case "s128" - send Parser ['long long '] - case "uint" - send Parser ['int '] - default - send Parser [Type] - } - - void number( Number: number ) - { - switch Number - case [`u `( uint `) ] - send Parser "[Number.uint]" - default - send Parser [Number] - } - - void java_num_list( NumList: num_list ) - { - for Number: number in NumList - send Parser "[number( Number )], " - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [A: static_array] { - send Parser - "private static [type(A.type)] " - "[A.ident] \[\] = { [java_num_list(A.num_list)] }; - } - case [V: static_value] { - send Parser - "private static [V.type] [V.ident] = [V.number]; - } - case [ - 'if' O: `( IfExpr: expr C: `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if ( [expr(IfExpr)] ) - " [stmt(IfStmt)] - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] - - send Parser - "else if ( [expr(ElseIfExpr)] ) - " [stmt(ElseIfStmt)] - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else - " [stmt(ElseStmt)] - } - } - case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { - send Parser - "while ( [expr(WhileExpr)] ) - " [stmt(WhileStmt)] - } - case [BL: break_label? 'while' '(' WhileExpr: expr ')' '{' StmtList: stmt* '}' ] { - if match BL [bl: break_label] - send Parser "[bl.ident]: " - - send Parser - "while ( [expr(WhileExpr)] ) { - " [stmt_list(StmtList)] - "} - } - case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { - send Parser - "switch ( [expr(SwitchExpr)] ) { - " [stmt_list(StmtList)] - "} - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr(ExprExpr) Semi] - } - case [L: `{ TL: stmt* R: `}] { - send Parser - "{ - " [stmt_list(TL)] - "} - } - case [ - TypeList: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - send Parser - [TypeList type(Type) Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - - send Parser - [Semi] - } - case [Export: export_stmt] - { - send Parser - "static final char [Export.ident] = [number(Export.number)]; - } - case ['fallthrough' ';'] - { - # Nothing needed here. - } - case [Index: index_stmt] - { - send Parser - "int [Index.ident]" - - if match Index.opt_init [E: `= expr] { - send Parser - [E expr(Index.opt_init.expr)] - } - send Parser "; - - } - case [case_block] - { - send Parser - "case [expr( Stmt.case_block.expr )]: - "[stmt_list( Stmt.case_block._repeat_stmt )] - "break; - } - case [default_block] - { - send Parser - "default: - "[stmt_list( Stmt.default_block._repeat_stmt )] - "break; - } - case [goto_label] { } - case [G: goto_stmt] { } - case [AS: assign_stmt] - { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - default { - # catches unspecified cases - send Parser [Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - Parser = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - JO: java_out::java_out = Parser->finish() - - if JO { - send Output - [JO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } - } -end - -void trans( Output: stream, Start: start ) -{ - java_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-java/rlparse.lm b/ragel/host-java/rlparse.lm deleted file mode 100644 index 100a9223..00000000 --- a/ragel/host-java/rlparse.lm +++ /dev/null @@ -1,202 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-js/.gitignore b/ragel/host-js/.gitignore deleted file mode 100644 index 6721152a..00000000 --- a/ragel/host-js/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-js -/ragel-js.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-js/CMakeLists.txt b/ragel/host-js/CMakeLists.txt deleted file mode 100644 index f0795f36..00000000 --- a/ragel/host-js/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseJs - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcJs - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-js main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-js PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-js - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-js/Makefile.am b/ragel/host-js/Makefile.am deleted file mode 100644 index db08d249..00000000 --- a/ragel/host-js/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-js - -ragel_js_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_js_SOURCES = main.cc rlhc.c - -nodist_ragel_js_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_js_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseJs -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcJs -o $@ $< diff --git a/ragel/host-js/main.cc b/ragel/host-js/main.cc deleted file mode 100644 index 44796436..00000000 --- a/ragel/host-js/main.cc +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseJs; -extern struct colm_sections rlhcJs; - -/* - * JavaScript - */ - -const char *defaultOutFnJs( const char *inputFileName ) -{ - return fileNameFromStem( inputFileName, ".js" ); -} - -HostType hostTypesJS[] = -{ - { "s8", 0, "int8", true, true, false, CHAR_MIN, CHAR_MAX, 0, 0, 1 }, - { "u8", 0, "uint8", false, true, false, 0, 0, 0, UCHAR_MAX, 1 }, - { "s16", 0, "int16", true, true, false, SHRT_MIN, SHRT_MAX, 0, 0, 2 }, - { "u16", 0, "uint16", false, true, false, 0, 0, 0, USHRT_MAX, 2 }, - { "i32", 0, "int32", true, true, false, INT_MIN, INT_MAX, 0, 0, 4 }, - { "u32", 0, "uint32", false, true, false, 0, 0, 0, UINT_MAX, 4 }, - { "number", 0, "number", true, true, false, LONG_MIN, LONG_MAX, 0, 0, 8 }, -}; - -const HostLang hostLangJS = -{ - hostTypesJS, - 7, - 1, - false, - true, /* loopLabels */ - Translated, - BreakFeature, - &makeCodeGen, - &defaultOutFnJs, - &genLineDirectiveTrans -}; - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangJS, &rlparseJs, &rlhcJs ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-js/rlhc.lm b/ragel/host-js/rlhc.lm deleted file mode 100644 index 29a61346..00000000 --- a/ragel/host-js/rlhc.lm +++ /dev/null @@ -1,504 +0,0 @@ -include 'ril.lm' - -namespace js_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`{ _IN_ item* _EX_ `} ] - - def js_out - [_IN_ _EX_ item*] -end - -namespace js_gen - - global Parser: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] { - send Parser - "{ - " [stmt_list( StmtList )] - "} - } - case [host::`={ Expr: expr host::`}=] { - send Parser - "([expr( Expr )])" - } - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default { - send Parser - [Tok] - } - } - } - - void embedded_host( EmbeddedHost: embedded_host ) - { - switch EmbeddedHost - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - "{ - " [tok_list( TL )] - "} - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [O:`( TL: expr C: `)] - { - send Parser - [O expr(TL) C] - } - case [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case ['offset' '(' ident ',' expr ')'] - { - send Parser - [expr( ExprFactor.expr )] - } - case ['deref' '(' ident ',' expr ')'] - { - send Parser [ExprFactor.ident] - if $ExprFactor.ident == 'data' - send Parser ['.charCodeAt(' expr( ExprFactor.expr ) ')'] - else - send Parser ['[' expr( ExprFactor.expr ) ']'] - } - case [T: `TRUE] - { - T.data = 'true' - send Parser [T] - } - case [F: `FALSE] - { - F.data = 'false' - send Parser [F] - } - case [N: `nil] - { - N.data = '-1' - send Parser [N] - } - case [Number: number] - { - number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast Open: `( type Close: `) expr_factor] - { - expr_factor( ExprFactor._expr_factor ) - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case [I: ident `[ E: expr `] `. F: ident] - { - send Parser - "[I]\[[ expr( E )]\].[F] - } - case [E1: embedded_host `-> E2: lvalue] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - lvalue( E2 ) - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [T: `~ expr_factor_op] - { - send Parser [T] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - expr_bitwise( ExprBitwise._expr_bitwise ) - send Parser [A] - expr_factor_op( ExprBitwise.expr_factor_op ) - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - send Parser [Op] - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } - } - - void expr_test_op( Op: test_op ) - { - switch Op - case [ `== ] - send Parser '===' - case [ `!= ] - send Parser '!==' - default - send Parser [Op] - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - expr_test_op( ExprTest.test_op ) - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void number( Number: number ) - { - switch Number - case [`u `( uint `) ] - send Parser [Number.uint] - default - send Parser [Number] - } - - void type( Type: type ) - { - switch Type - case 'u8' - send Parser 'Uint8' - case 'u16' - send Parser 'Uint16' - case 'u32' - send Parser 'Uint32' - case 's8' - send Parser 'Int8' - case 's16' - send Parser 'Int16' - case 's32' - send Parser 'Int32' - default - send Parser 'Float64' - } - - void num_list( NumList: num_list ) - { - number( NumList.number ) - for CommaNum: comma_num in NumList { - send Parser [', '] - number( CommaNum.number ) - } - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [A: static_array] { - send Parser - "var [A.ident] = new [type(A.type)]Array(\[ [num_list(A.num_list)]\]); - } - case [V: static_value] { - send Parser - "var [V.ident] = [V.number]; - } - case [ - 'if' O: `( IfExpr: expr C: `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if ( [expr(IfExpr)] ) - " [stmt(IfStmt)] - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] - - send Parser - "else if ( [expr(ElseIfExpr)] ) - " [stmt(ElseIfStmt)] - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else - " [stmt(ElseStmt)] - } - } - case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { - send Parser - "while ( [expr(WhileExpr)] ) - " [stmt(WhileStmt)] - } - case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { - send Parser - "switch ( [expr(SwitchExpr)] ) { - " [stmt_list(StmtList)] - "} - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr(ExprExpr) Semi] - } - case [L: `{ TL: stmt* R: `}] { - send Parser - "{ - " [stmt_list(TL)] - "} - } - case [ - TypeList: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - send Parser - "var [Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - - send Parser - [Semi] - } - case [Export: export_stmt] - { - send Parser - "var [Export.ident] = [number(Export.number)]; - } - case ['fallthrough' ';'] - { - # Nothing needed here. - } - case [Index: index_stmt] - { - send Parser - "var [Index.ident]" - - if match Index.opt_init [E: `= expr] { - send Parser - [E expr(Index.opt_init.expr)] - } - - send Parser - "; - } - case [case_block] - { - send Parser - "case [expr( Stmt.case_block.expr )]: - "[stmt_list( Stmt.case_block._repeat_stmt )] - "break; - } - case [default_block] - { - send Parser - "default: - "[stmt_list( Stmt.default_block._repeat_stmt )] - "break; - } - case [goto_label] { } - case [G: goto_stmt] { } - case [AS: assign_stmt] - { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - default { - # catches unspecified cases - send Parser [Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - Parser = new parser() - - send Parser - "'use strict'; - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - CO: js_out::js_out = Parser->finish() - - if CO { - send Output - [CO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } - } -end - -void trans( Output: stream, Start: start ) -{ - js_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-js/rlparse.lm b/ragel/host-js/rlparse.lm deleted file mode 100644 index 100a9223..00000000 --- a/ragel/host-js/rlparse.lm +++ /dev/null @@ -1,202 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-julia/.gitignore b/ragel/host-julia/.gitignore deleted file mode 100644 index 7bd1258f..00000000 --- a/ragel/host-julia/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-julia -/ragel-julia.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-julia/CMakeLists.txt b/ragel/host-julia/CMakeLists.txt deleted file mode 100644 index 89b466e5..00000000 --- a/ragel/host-julia/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseJulia - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcJulia - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-julia main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-julia PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-julia - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-julia/Makefile.am b/ragel/host-julia/Makefile.am deleted file mode 100644 index f7f193b8..00000000 --- a/ragel/host-julia/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-julia - -ragel_julia_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_julia_SOURCES = main.cc rlhc.c - -nodist_ragel_julia_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_julia_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseJulia -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcJulia -o $@ $< diff --git a/ragel/host-julia/main.cc b/ragel/host-julia/main.cc deleted file mode 100644 index f06d7493..00000000 --- a/ragel/host-julia/main.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseJulia; -extern struct colm_sections rlhcJulia; - -/* - * Julia - */ -const char *defaultOutFnJulia( const char *inputFileName ) -{ - return fileNameFromStem( inputFileName, ".jl" ); -} - -HostType hostTypesJulia[] = -{ - { "u8", 0, "byte", true, true, false, 0, UCHAR_MAX, 0, 0, 4 }, -}; - -const HostLang hostLangJulia = -{ - hostTypesJulia, - 1, - 0, - false, - false, /* loopLabels */ - Translated, - GotoFeature, - &makeCodeGen, - &defaultOutFnJulia, - &genLineDirectiveTrans -}; - - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangJulia, &rlparseJulia, &rlhcJulia ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-julia/rlhc.lm b/ragel/host-julia/rlhc.lm deleted file mode 100644 index 72108994..00000000 --- a/ragel/host-julia/rlhc.lm +++ /dev/null @@ -1,561 +0,0 @@ -include 'ril.lm' - -namespace julia_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - literal `function `end `while `if `else `elseif - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def kw - [`function _IN_] - | [`while _IN_] - | [`if _IN_] - | [_EX_ `elseif _IN_] - | [_EX_ `else _IN_] - | [_EX_ `end] - - def item - [comment] - | [kw] - | [id] - | [number] - | [symbol] - | [string] - | [`{ _IN_ item* _EX_ `} ] - - def julia_out - [_IN_ _EX_ item*] -end - -namespace julia_gen - - global Parser: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] { - send Parser - "begin - " [stmt_list( StmtList )] - "end - } - case [host::`={ Expr: expr host::`}=] { - send Parser - "([expr( Expr )])" - } - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default { - send Parser - [Tok] - } - } - } - - void embedded_host( EmbeddedHost: embedded_host ) - { - switch EmbeddedHost - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - [tok_list( TL )] - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [`( E: expr `)] - { - send Parser - "([expr(E)])" - } - case [I: ident `[ E: expr `]] - { - send Parser - "[I]\[1+([expr( E )])\]" - } - case [`offset `( ident `, expr `)] - { - send Parser - [expr( ExprFactor.expr )] - } - case [`deref `( I: ident `, E: expr `)] - { - send Parser - "[I]\[1+([ expr( E ) ])\]" - } - case [`TRUE] - { - send Parser "true" - } - case [`FALSE] - { - send Parser "false" - } - case [N: `nil] - { - send Parser "0" - } - case [Number: number] - { - number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast `( T: type `) F: expr_factor] - { - send Parser - "convert([type( T )], [expr_factor( F )] )" - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[1+(' expr(E) ')]'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [I: ident `[ E: expr `]] - { - send Parser - "[I]\[1+([expr( E )])\]" - } - case [E1: embedded_host `-> E2: lvalue] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - lvalue( E2 ) - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[1+(' expr(E) ')]'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [T: `~ expr_factor_op] - { - send Parser [T] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - expr_bitwise( ExprBitwise._expr_bitwise ) - send Parser [A] - expr_factor_op( ExprBitwise.expr_factor_op ) - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - send Parser [Op] - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - send Parser [Op] - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case "s8" - send Parser ['Int8'] - case "u8" - send Parser ['UInt8'] - case "s16" - send Parser ['Int16'] - case "s32" - send Parser ['Int32'] - case "s64" - send Parser ['Int64'] - case "s128" - send Parser ['Int128'] - case "uint" - send Parser ['UInt'] - case "int" - send Parser ['Int'] - default - send Parser [Type] - } - - void number( Number: number ) - { - switch Number - case [`u `( uint `) ] - send Parser "[Number.uint]u" - default - send Parser [Number] - } - - void num_list( NumList: num_list ) - { - for Number: number in NumList - send Parser "[number( Number )], " - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [A: static_array] { - send Parser - "const [A.ident] = [type(A.type)]\[[num_list(A.num_list)]\] - } - case [V: static_value] { - send Parser - "const [V.ident] = [V.number] - } - # case [declaration] - case [ - TypeList: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - send Parser - [Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - else { - send Parser - "= 0 - } - - send Parser - [Semi] - } - case [ - `if `( IfExpr: expr `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if [expr(IfExpr)] - " [stmt(IfStmt)] - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - [`else `if `( ElseIfExpr: expr `) ElseIfStmt: stmt] - - send Parser - "elseif [expr(ElseIfExpr)] - " [stmt(ElseIfStmt)] - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else - " [stmt(ElseStmt)] - } - - send Parser - "end - } - case [`while `( WhileExpr: expr `) WhileStmt: stmt] { - send Parser - "while [expr(WhileExpr)] - " [stmt(WhileStmt)] - "end - } - case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { - - require StmtList - [`case E1: expr `{ Inner: stmt* `} Rest: stmt*] - - send Parser - "if [expr(SwitchExpr)] == [expr(E1)] - " [stmt_list(Inner)] - - for S: stmt in repeat(Rest) { - switch S - case [`case E1: expr `{ Inner: stmt* `}] - { - send Parser - "elseif [expr(SwitchExpr)] == [expr(E1)] - " [stmt_list(Inner)] - } - case - [`default `{ Inner: stmt* `}] - { - send Parser - "else - " [stmt_list(Inner)] - } - } - - send Parser - "end - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr(ExprExpr)] - } - case [L: `{ TL: stmt* R: `}] { - send Parser - [stmt_list(TL)] - } - case [ - TypeList: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - send Parser - [TypeList type(Type) Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - - send Parser "; - } - case [Export: export_stmt] - { - send Parser - "#define [Export.ident] [number(Export.number)] - } - case ['fallthrough' ';'] - { - # Nothing needed here. - } - case [Index: index_stmt] - { - send Parser - "[Index.ident]" - - if match Index.opt_init [E: `= expr] { - send Parser - [E expr(Index.opt_init.expr)] - } - else { - send Parser " = 0 " - - } - - send Parser "; - } - case [case_block] - { - send Parser - "@case [expr( Stmt.case_block.expr )] begin - "[stmt_list( Stmt.case_block._repeat_stmt )] - "end - } - case [default_block] - { - send Parser - "default: - "[stmt_list( Stmt.default_block._repeat_stmt )] - "break; - } - case [case_label] - { - send Parser - "@case [expr( Stmt.case_label.expr )] - } - case [L: goto_label] - { - send Parser - "@label [L.ident] - } - case [G: goto_stmt] - { - send Parser - "@goto [G.ident] - } - case [AS: assign_stmt] - { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)] - } - default { - # catches unspecified cases - send Parser - "[Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - Parser = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - CO: julia_out::julia_out = Parser->finish() - - if CO { - send Output - [CO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } - } -end - -void trans( Output: stream, Start: start ) -{ - julia_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-julia/rlparse.lm b/ragel/host-julia/rlparse.lm deleted file mode 100644 index 100a9223..00000000 --- a/ragel/host-julia/rlparse.lm +++ /dev/null @@ -1,202 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-ocaml/.gitignore b/ragel/host-ocaml/.gitignore deleted file mode 100644 index fe7038f5..00000000 --- a/ragel/host-ocaml/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-ocaml -/ragel-ocaml.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-ocaml/CMakeLists.txt b/ragel/host-ocaml/CMakeLists.txt deleted file mode 100644 index eff80ce9..00000000 --- a/ragel/host-ocaml/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseOCaml - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcOCaml - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-ocaml main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-ocaml PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-ocaml - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-ocaml/Makefile.am b/ragel/host-ocaml/Makefile.am deleted file mode 100644 index 1e268bce..00000000 --- a/ragel/host-ocaml/Makefile.am +++ /dev/null @@ -1,34 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-ocaml - -ragel_ocaml_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_ocaml_SOURCES = main.cc rlhc.c - -nodist_ragel_ocaml_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_ocaml_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseOCaml -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcOCaml -o $@ $< - - diff --git a/ragel/host-ocaml/main.cc b/ragel/host-ocaml/main.cc deleted file mode 100644 index 36f3d030..00000000 --- a/ragel/host-ocaml/main.cc +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseOCaml; -extern struct colm_sections rlhcOCaml; - -/* - * OCaml - */ -const char *defaultOutFnOCaml( const char *inputFileName ) -{ - return fileNameFromStem( inputFileName, ".ml" ); -} - -HostType hostTypesOCaml[] = -{ - { "int", 0, "int", true, true, false, S31BIT_MIN, S31BIT_MAX, 0, 0, 4 }, -}; - -const HostLang hostLangOCaml = -{ - hostTypesOCaml, - 1, - 0, - false, - false, /* loopLabels */ - Translated, - VarFeature, - &makeCodeGen, - &defaultOutFnOCaml, - &genLineDirectiveTrans -}; - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangOCaml, &rlparseOCaml, &rlhcOCaml ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-ocaml/rlhc.lm b/ragel/host-ocaml/rlhc.lm deleted file mode 100644 index f68b61be..00000000 --- a/ragel/host-ocaml/rlhc.lm +++ /dev/null @@ -1,609 +0,0 @@ -include 'ril.lm' - -namespace ocaml_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '(*' any* :>> '*)' - / - - literal `begin `end `{ `} - - token id - /[a-zA-Z_][a-zA-Z_0-9]* "'"? / - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' | '`' / - - token string / - '"' ( [^"\\\n] | '\\' any ) * '"' | - "'" ( [^'\\\n] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`begin _IN_ item* _EX_ `end ] - | [`{ _IN_ item* _EX_ `} ] - - def ocaml_out - [_IN_ _EX_ item*] -end - -namespace ml_gen - - global StaticVarMap: map = new map() - global Parser: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] - send Parser - "begin - "[stmt_list( StmtList )] - "end; - case [host::`={ Expr: expr host::`}=] - send Parser "([expr( Expr )])" - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default { - send Parser [Tok] - } - } - } - - void embedded_host( EH: embedded_host ) - { - switch EH - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - "begin - "[tok_list( TL )] - "end; - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [`( TL: expr `)] - { - send Parser - "( [ expr(TL) ] )" - } - case [I: ident `[ TL: expr `]] - { - if ( StaticVarMap->find( $I ) || $I == 'stack' ) { - send Parser - "[ ExprFactor.ident ].([ expr( TL ) ])" - } - else { - send Parser - "[ ExprFactor.ident ].\[[ expr( TL ) ]\]" - } - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '.(' expr(E) ')'] - } - case ['offset' '(' ident ',' expr ')'] - { - send Parser - [expr( ExprFactor.expr )] - } - case ['deref' '(' I: ident ',' Expr: expr ')'] - { - if ( $I == 'data' ) - send Parser 'Char.code ' - - if ( StaticVarMap->find( $I ) ) { - send Parser - "[I].( [ expr( Expr ) ] )" - } - else { - send Parser - "[I].\[[ expr( Expr ) ]\]" - } - } - case [T: `TRUE] - { - T.data = 'true' - send Parser [T] - } - case [F: `FALSE] - { - F.data = 'false' - send Parser [F] - } - case [N: `nil] - { - N.data = '0' - send Parser [N] - } - case [Number: number] - { - number( Number ) - } - case [I: ident] { - if ( StaticVarMap->find( $I ) ) { - send Parser - [^I] - } - else { - send Parser - "[^I].contents" - } - } - case [E1: embedded_host `-> E2: expr_factor] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast `( type `) expr_factor] - { - send Parser - [expr_factor( ExprFactor._expr_factor )] - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' E ']'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case [E1: embedded_host `-> E2: lvalue] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - lvalue( E2 ) - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '.(' E ')'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [T: `~ expr_factor_op] - { - send Parser " lnot " - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [L: expr_bitwise `& R: expr_factor_op] - { - send Parser - "[expr_bitwise( L )] land [expr_factor_op( R )]" - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - switch Op - case [`<<] - send Parser " lsl " - default - send Parser " asr " - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - switch Op - case [`==] - send Parser "= " - default - send Parser [Op] - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case "s8" - send Parser ['char '] - case "s16" - send Parser ['short '] - case "s32" - send Parser ['int '] - case "s64" - send Parser ['long '] - case "s128" - send Parser ['long long '] - case "uint" - send Parser ['int '] - default - send Parser [Type] - } - - void number( Number: number ) - { - switch Number - case [`u `( uint `) ] - send Parser "[Number.uint]u" - default - send Parser [Number] - } - - void num_list( NumList: num_list ) - { - for Number: number in NumList - send Parser "[number( Number )]; " - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [A: static_array] { - StaticVarMap->insert( $A.ident, ' ' ) - send Parser - "let [A.ident] : int array = \[| - " [num_list(A.num_list)] - "|\] - } - case [V: static_value] { - StaticVarMap->insert( $V.ident, ' ' ) - send Parser - "let [V.ident] : [V.type] = [V.number] - } - case [ - 'if' O: `( IfExpr: expr C: `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if [expr(IfExpr)] then - "begin - " [stmt(IfStmt)] - "end - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] - - send Parser - "else if [expr(ElseIfExpr)] then - "begin - " [stmt(ElseIfStmt)] - "end - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else - "begin - " [stmt(ElseStmt)] - "end - } - - send Parser - ";" - } - case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { - send Parser - "while [expr(WhileExpr)] do - " [stmt(WhileStmt)] - "done; - } - case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { - require StmtList - [`case E1: expr `{ Inner: stmt* `} Rest: stmt*] - - send Parser - "if [expr(SwitchExpr)] = [expr(E1)] then - "begin - " [stmt_list(Inner)] - "end - - for S: stmt in repeat(Rest) { - switch S - case [`case E1: expr `{ Inner: stmt* `}] - { - send Parser - "else if [expr(SwitchExpr)] = [expr(E1)] then - "begin - " [stmt_list(Inner)] - "end - } - case - [`default `{ Inner: stmt* `}] - { - send Parser - "else - "begin - " [stmt_list(Inner)] - "end - } - } - - send Parser - "; - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr(ExprExpr) Semi] - } - case [L: `{ TL: stmt* R: `}] { - send Parser - "begin - "[stmt_list(TL)] - "end; - } - case [D: declaration] { - send Parser - "let [D.ident] : [type(D.type)] ref " - - switch D.opt_init - case [E: `= expr] { - send Parser - "= ref ( [expr(D.opt_init.expr)] )" - } - default { - send Parser - "= ref 0" - } - - send Parser - " in - } - case [Export: export_stmt] - { - send Parser - "#define [Export.ident] [number(Export.number)] - } - case ['fallthrough' ';'] - { - # Nothing needed here. - } - case [Index: index_stmt] - { - send Parser - "let [Index.ident] : int ref " - - switch Index.opt_init - case [E: `= expr] { - send Parser - "= ref ( [expr(Index.opt_init.expr)] )" - } - default { - send Parser - "= ref 0" - } - - send Parser - " in - } - case [case_block] - { - send Parser - "| [expr( Stmt.case_block.expr )] -> - "begin - "[stmt_list( Stmt.case_block._repeat_stmt )] - "end; - } - case [default_block] - { - send Parser - "| _ -> - "[stmt_list( Stmt.default_block._repeat_stmt )] - } - case [case_label] - { - send Parser - "case [expr( Stmt.case_label.expr )]: - } - case [AS: assign_stmt] - { - switch AS.assign_op - case [`=] - { - switch AS.LValue - case "stack\[[expr]\]" { - send Parser - "Array.set stack top.contents [expr(AS.expr)]; - } - case "nfa_bp\[[expr]\].state" { - send Parser - "Array.set nfa_bp_state nfa_len.contents [expr(AS.expr)]; - } - case "nfa_bp\[[expr]\].p" { - send Parser - "Array.set nfa_bp_p nfa_len.contents [expr(AS.expr)]; - } - default { - send Parser - "[lvalue(AS.LValue)] := [expr(AS.expr)]; - } - } - case [`+=] - { - parse RhsAsFactor: expr_factor [$AS.LValue] - send Parser - "[lvalue(AS.LValue)] := [expr_factor(RhsAsFactor)] + [expr(AS.expr)]; - } - case [`-=] - { - parse RhsAsFactor: expr_factor [$AS.LValue] - send Parser - "[lvalue(AS.LValue)] := [expr_factor(RhsAsFactor)] - [expr(AS.expr)]; - } - default { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - } - default { - # catches unspecified cases - send Parser [Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - Parser = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - MO: ocaml_out::ocaml_out = Parser->finish() - - if MO { - send Output - [MO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } - } - -end - -void trans( Output: stream, Start: start ) -{ - ml_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-ocaml/rlparse.lm b/ragel/host-ocaml/rlparse.lm deleted file mode 100644 index 911e3ea6..00000000 --- a/ragel/host-ocaml/rlparse.lm +++ /dev/null @@ -1,204 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-ruby/.gitignore b/ragel/host-ruby/.gitignore deleted file mode 100644 index f61713c7..00000000 --- a/ragel/host-ruby/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile.in -/Makefile -/.deps -/.libs -/ragel-ruby -/ragel-ruby.exe -/rlparse.pack -/rlparse.c -/rlreduce.cc -/rlhc.c - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-ruby/CMakeLists.txt b/ragel/host-ruby/CMakeLists.txt deleted file mode 100644 index 4ec4e387..00000000 --- a/ragel/host-ruby/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseRuby - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcRuby - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-ruby main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-ruby PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-ruby - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-ruby/Makefile.am b/ragel/host-ruby/Makefile.am deleted file mode 100644 index 60423939..00000000 --- a/ragel/host-ruby/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-ruby - -ragel_ruby_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_ruby_SOURCES = main.cc rlhc.c - -nodist_ragel_ruby_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_ruby_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseRuby -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcRuby -o $@ $< diff --git a/ragel/host-ruby/main.cc b/ragel/host-ruby/main.cc deleted file mode 100644 index 3fed52e3..00000000 --- a/ragel/host-ruby/main.cc +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseRuby; -extern struct colm_sections rlhcRuby; - -/* What are the appropriate types for ruby? */ -static HostType hostTypesRuby[] = -{ - { "char", 0, "char", true, true, false, CHAR_MIN, CHAR_MAX, 0, 0, 1 }, - { "int", 0, "int", true, true, false, INT_MIN, INT_MAX, 0, 0, 4 }, -}; - -const char *defaultOutFnRuby( const char *inputFileName ) -{ - return fileNameFromStem( inputFileName, ".rb" ); -} - -static const HostLang hostLangRuby = -{ - hostTypesRuby, - 2, - 0, - false, - false, /* loopLabels. */ - Translated, - BreakFeature, - &makeCodeGen, - &defaultOutFnRuby, - &genLineDirectiveTrans -}; - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangRuby, &rlparseRuby, &rlhcRuby ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-ruby/rlhc.lm b/ragel/host-ruby/rlhc.lm deleted file mode 100644 index 87119465..00000000 --- a/ragel/host-ruby/rlhc.lm +++ /dev/null @@ -1,527 +0,0 @@ -include 'ril.lm' - -namespace ruby_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '#' any* :> '\n' - / - - literal `def `class `begin `end `while `if - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" | - "/" ( [^/\\] | '\\' any ) * "/" - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' | '{' | '}' | '\\' / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [`begin _IN_] - | [`class _IN_] - | [`while _IN_] - | [`if _IN_] - | [`def _IN_] - | [_EX_ `end] - - def ruby_out - [_IN_ _EX_ item*] -end - -global Parser: parser - -void tok_list( TL: host::tok* ) -{ - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] - { - send Parser - "begin - "[stmt_list( StmtList )] - "end - } - case [host::`={ Expr: expr host::`}=] - expr( Expr ) - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default { - send Parser [Tok] - } - } -} - -void embedded_host( EH: embedded_host ) -{ - switch EH - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - "begin - " [tok_list( TL )] - "end - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } -} - -void expr_factor( ExprFactor: expr_factor ) -{ - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [O:`( TL: expr C: `)] - { - send Parser - [O expr(TL) C] - } - case [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case ['offset' '(' ident ',' expr ')'] - { - send Parser - [expr( ExprFactor.expr )] - } - case ['deref' '(' ident ',' expr ')'] - { - send Parser - [ ExprFactor.ident '[' expr( ExprFactor.expr ) ']'] - if $ExprFactor.ident == 'data' - send Parser '.ord' - } - case [T: `TRUE] - { - T.data = 'true' - send Parser [T] - } - case [F: `FALSE] - { - F.data = 'false' - send Parser [F] - } - case [N: `nil] - { - N.data = '0' - send Parser [N] - } - case [Number: number] - { - ruby_number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast Open: `( Type: type Close: `) expr_factor] - { - #send Parser [Open] - #type( Type ) - #send Parser [Close] - expr_factor( ExprFactor._expr_factor ) - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' E ']'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } -} - -void lvalue( ExprFactor: lvalue ) -{ - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [ident O: `[ TL: expr C: `]] - { - send Parser - [ExprFactor.ident O expr( TL ) C] - } - case [E1: embedded_host `-> E2: lvalue] - { - embedded_host( E1 ) - lvalue( E2 ) - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' E ']'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } -} - -void expr_factor_op( ExprFactorOp: expr_factor_op ) -{ - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [T: `~ expr_factor_op] - { - send Parser [T] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } -} - -void expr_bitwise( ExprBitwise: expr_bitwise ) -{ - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - expr_bitwise( ExprBitwise._expr_bitwise ) - send Parser [A] - expr_factor_op( ExprBitwise.expr_factor_op ) - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } -} - -void expr_mult( ExprMult: expr_mult ) -{ - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } -} - -void expr_add( ExprAdd: expr_add ) -{ - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } -} - -void expr_shift( ExprShift: expr_shift ) -{ - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - send Parser [Op] - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } -} - -void expr_test( ExprTest: expr_test ) -{ - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - send Parser [Op] - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } -} - -void expr( Expr: expr ) -{ - expr_test( Expr.expr_test ) -} - -void type( Type: type ) -{ - switch Type - case "s8" - send Parser ['byte '] - case "s16" - send Parser ['short '] - case "s32" - send Parser ['int '] - case "s64" - send Parser ['long '] - case "s128" - send Parser ['long long '] - case "uint" - send Parser ['int '] - default - send Parser [Type] -} - -void ruby_number( Number: number ) -{ - switch Number - case [`u `( uint `) ] - send Parser "[Number.uint]" - default - send Parser [Number] -} - -void ruby_num_list( NumList: num_list ) -{ - for Number: number in NumList - send Parser "[ruby_number( Number )], " -} - -void stmt( Stmt: stmt ) -{ - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [A: static_array] { - send Parser - "class << self - " attr_accessor :[ A.ident ] - " private :[ A.ident ], :[ A.ident ]= - "end - "self.[ A.ident ] = \[ - " [ruby_num_list( A.num_list )] - "\] - " - } - case [V: static_value] { - send Parser - "class << self - " attr_accessor :[ V.ident ] - "end - "self.[ V.ident ] = [ V.number ]; - " - } - case [ - 'if' O: `( IfExpr: expr C: `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if ( [expr(IfExpr)] ) - " [stmt(IfStmt)] - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] - - send Parser - "elsif ( [expr(ElseIfExpr)] ) - " [stmt(ElseIfStmt)] - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else - " [stmt(ElseStmt)] - } - send Parser - "end - } - case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { - send Parser - "while ( [expr(WhileExpr)] ) - " [stmt(WhileStmt)] - "end - } - case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { - send Parser - "case [expr(SwitchExpr)] - "when -2 then - "begin - " [stmt_list(StmtList)] - "end - "end - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr(ExprExpr) Semi] - } - case [L: `{ TL: stmt* R: `}] { - send Parser - "begin - "[stmt_list(TL)] - "end - } - # [declaration] - case [ - TypeList: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - send Parser - [Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - else { - send Parser - "= 0 - } - - send Parser - [Semi] - } - case [Export: export_stmt] - { - send Parser - "class << self - " attr_accessor :[ Export.ident ] - "end - "self.[ Export.ident ] = [ ruby_number(Export.number) ]; - " - } - case ['fallthrough' ';'] - { - # Nothing needed here. - } - case [Index: index_stmt] - { - send Parser - "[Index.ident]" - - if match Index.opt_init [E: `= expr] { - send Parser - [E expr(Index.opt_init.expr)] - } - else { - send Parser - "= 0 - } - - send Parser "; - } - case [case_block] - { - send Parser - "end - "when [expr( Stmt.case_block.expr )] then - "begin - "[stmt_list( Stmt.case_block._repeat_stmt )] - } - case [default_block] - { - send Parser - "end - "else - "begin - "[stmt_list( Stmt.default_block._repeat_stmt )] - } - case [goto_label] {} - case [goto_stmt] {} - case [AS: assign_stmt] - { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - case [continue_stmt] - { - send Parser - "next; - } - default { - # catches unspecified cases - send Parser [Stmt] - } -} - -void stmt_list( StmtList: stmt* ) -{ - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) -} - -void ruby_trans( Output: stream, Start: start ) -{ - Parser = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - RO: ruby_out::ruby_out = Parser->finish() - - if RO { - send Output - [RO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } -} - -void trans( Output: stream, Start: start ) -{ - ruby_trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-ruby/rlparse.lm b/ragel/host-ruby/rlparse.lm deleted file mode 100644 index 99811877..00000000 --- a/ragel/host-ruby/rlparse.lm +++ /dev/null @@ -1,203 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / ruby_comment / - - token string - / s_literal | d_literal | host_re_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / ruby_comment / - - token string - / s_literal | d_literal | host_re_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any - -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/host-ruby/ruby.dsc b/ragel/host-ruby/ruby.dsc deleted file mode 100644 index 75342663..00000000 --- a/ragel/host-ruby/ruby.dsc +++ /dev/null @@ -1,2 +0,0 @@ -char NIL char true true false CHAR_MIN CHAR_MAX 0 0 1 -int NIL int true true false INT_MIN INT_MAX 0 0 4 diff --git a/ragel/host-rust/.gitignore b/ragel/host-rust/.gitignore deleted file mode 100644 index acd5559a..00000000 --- a/ragel/host-rust/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -/Makefile -/Makefile.in -/.deps -/.libs -/ragel-rust -/ragel-rust.exe -/rlhc.c -/rlparse.pack -/rlparse.c -/rlreduce.cc - -/CMakeFiles -/cmake_install.cmake diff --git a/ragel/host-rust/CMakeLists.txt b/ragel/host-rust/CMakeLists.txt deleted file mode 100644 index 272ef9f6..00000000 --- a/ragel/host-rust/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - DEPENDS rlparse.lm - COMMAND colm::colm - ARGS -I.. -c -b rlparseRust - -o "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - -m "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc" - rlparse.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_custom_command(OUTPUT - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - DEPENDS rlhc.lm - COMMAND colm::colm - ARGS -I.. -c -b rlhcRust - -o "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - rlhc.lm - WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}") - -add_executable(ragel-rust main.cc - "${CMAKE_CURRENT_BINARY_DIR}/rlhc.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlparse.c" - "${CMAKE_CURRENT_BINARY_DIR}/rlreduce.cc") - -target_link_libraries(ragel-rust PRIVATE libragel libfsm) - -if(${PROJECT_NAME}_MAKE_INSTALL) - install(TARGETS ragel-rust - EXPORT ${_PACKAGE_NAME}-targets - RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" - LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" - ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") -endif() diff --git a/ragel/host-rust/Makefile.am b/ragel/host-rust/Makefile.am deleted file mode 100644 index 4282cddc..00000000 --- a/ragel/host-rust/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ -COLM_BIN = ../../colm/colm -COLM_WRAP = ../../colm/colm-wrap -COLM_LA = ../../colm/libcolm.la -COLM_LIBDEP = $(COLM_LA) -COLM_BINDEP = $(COLM_BIN) $(COLM_WRAP) - -bin_PROGRAMS = ragel-rust - -ragel_rust_CPPFLAGS = -I$(top_srcdir)/aapl -I$(top_srcdir)/ragel -I$(top_srcdir)/colm/include - -dist_ragel_rust_SOURCES = main.cc rlhc.c - -nodist_ragel_rust_SOURCES = \ - rlparse.c rlreduce.cc - -ragel_rust_LDADD = ../libragel.la ../libfsm.la $(COLM_LA) - -BUILT_SOURCES = rlparse.c rlreduce.cc rlhc.c - -EXTRA_DIST = rlparse.lm rlhc.lm - -rlparse.pack: rlparse.lm $(COLM_BINDEP) - $(COLM_WRAP) -c -I .. -b rlparseRust -o $@ -p rlparse.c -m rlreduce.cc $< - -rlparse.c: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlreduce.cc: rlparse.pack - $(COLM_WRAP) -o $@ $< - -rlhc.c: rlhc.lm ../ril.lm $(COLM_BINDEP) - $(COLM_BIN) -c -I .. -b rlhcRust -o $@ $< diff --git a/ragel/host-rust/main.cc b/ragel/host-rust/main.cc deleted file mode 100644 index 93c5147d..00000000 --- a/ragel/host-rust/main.cc +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2001-2018 Adrian Thurston - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "inputdata.h" - -extern struct colm_sections rlparseRust; -extern struct colm_sections rlhcRust; - -/* - * Rust - */ -const char *defaultOutFnRust( const char *inputFileName ) -{ - return fileNameFromStem( inputFileName, ".rs" ); -} - -HostType hostTypesRust[] = -{ - { "u8", 0, "byte", true, true, false, 0, UCHAR_MAX, 0, 0, 4 }, -}; - -const HostLang hostLangRust = -{ - hostTypesRust, - 1, - 0, - false, - false, /* loopLabels */ - Translated, - BreakFeature, - &makeCodeGen, - &defaultOutFnRust, - &genLineDirectiveTrans -}; - - -int main( int argc, const char **argv ) -{ - InputData id( &hostLangRust, &rlparseRust, &rlhcRust ); - return id.rlhcMain( argc, argv ); -} diff --git a/ragel/host-rust/rlhc.lm b/ragel/host-rust/rlhc.lm deleted file mode 100644 index 57cd66e1..00000000 --- a/ragel/host-rust/rlhc.lm +++ /dev/null @@ -1,522 +0,0 @@ -include 'ril.lm' - -namespace rust_out - token _IN_ /''/ - token _EX_ /''/ - - lex - token comment / - '//' any* :> '\n' | - '/*' any* :>> '*/' - / - - token id - /[a-zA-Z_][a-zA-Z_0-9]*/ - - token number / - [0-9]+ - / - - token symbol / - '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | - '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | - '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | - '~' / - - literal `{ `} - - token lifetime / "'" id / - - token string / - '"' ( [^"\\] | '\\' any ) * '"' | - "'" ( [^'\\] | '\\' any ) * "'" - / - - ignore - /[ \t\v\r\n]+/ - end - - def item - [comment] - | [id] - | [number] - | [symbol] - | [string] - | [lifetime] - | [`{ _IN_ item* _EX_ `} ] - - def rust_out - [_IN_ _EX_ item*] -end - -namespace rust_gen - - global Parser: parser - - void tok_list( TL: host::tok* ) - { - for Tok: host::tok in repeat(TL) { - switch Tok - case [host::`${ StmtList: stmt* host::`}$] - send Parser "{[stmt_list( StmtList )]}" - case [host::`={ Expr: expr host::`}=] - send Parser "([expr( Expr )])" - case [E: escape] { - Str: str = $E - send Parser - "[Str.suffix( 1 )]" - } - default - send Parser [Tok] - } - } - - void embedded_host( EmbeddedHost: embedded_host ) - { - switch EmbeddedHost - case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] - { - send Parser - "([tok_list( TL )])" - } - case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] - { - send Parser - "{[tok_list( TL )]} - } - case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] - { - send Parser - [tok_list( TL )] - } - } - - void expr_factor( ExprFactor: expr_factor ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [O:`( TL: expr C: `)] - { - send Parser - [O expr(TL) C] - } - case [I: ident `[ E: expr `]] - { - send Parser - "[I]\[([expr( E )]) as usize\]" - } - case ['offset' '(' ident ',' expr ')'] - { - send Parser - "( [expr( ExprFactor.expr )] ) as i32" - } - case ['deref' '(' I: ident ',' E: expr ')'] - { - send Parser - "[I]\[([expr( E )]) as usize\] - } - case [T: `TRUE] - { - T.data = 'true' - send Parser [T] - } - case [F: `FALSE] - { - F.data = 'false' - send Parser [F] - } - case [N: `nil] - { - N.data = '0' - send Parser [N] - } - case [Number: number] - { - number( Number ) - } - case [E1: embedded_host `-> E2: expr_factor] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - expr_factor( E2 ) - } - case [`cast `( T: type `) E: expr_factor] - { - send Parser - "( [expr_factor( E )] ) as [type(T)]" - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' expr(E) ' as usize]'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void lvalue( ExprFactor: lvalue ) - { - switch ExprFactor - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [I: ident O: `[ E: expr C: `]] - { - send Parser - "[I]\[([expr( E )]) as usize\] - } - case [E1: embedded_host `-> E2: lvalue] - { - # The accessor operator is contained wihtin the lhs. - embedded_host( E1 ) - lvalue( E2 ) - } - case [I: ident `[ E: expr `] `. F: ident] { - send Parser - [^I '_' ^F '[' expr(E) ' as usize]'] - } - default { - # Catches cases not specified - send Parser [ExprFactor] - } - } - - void expr_factor_op( ExprFactorOp: expr_factor_op ) - { - switch ExprFactorOp - case [B: `! expr_factor_op] - { - send Parser [B] - expr_factor_op( ExprFactorOp._expr_factor_op ) - } - case [`~ EFO: expr_factor_op] - { - send Parser - "![expr_factor_op( EFO )] - } - case [expr_factor] - { - expr_factor( ExprFactorOp.expr_factor ) - } - } - - void expr_bitwise( ExprBitwise: expr_bitwise ) - { - switch ExprBitwise - case [expr_bitwise A: `& expr_factor_op] - { - expr_bitwise( ExprBitwise._expr_bitwise ) - send Parser [A] - expr_factor_op( ExprBitwise.expr_factor_op ) - } - case [expr_factor_op] - { - expr_factor_op( ExprBitwise.expr_factor_op ) - } - } - - void expr_mult( ExprMult: expr_mult ) - { - switch ExprMult - case [expr_mult T: `* expr_bitwise] - { - expr_mult( ExprMult._expr_mult ) - send Parser [T] - expr_bitwise( ExprMult.expr_bitwise ) - } - case [expr_bitwise] - { - expr_bitwise( ExprMult.expr_bitwise ) - } - } - - void expr_add( ExprAdd: expr_add ) - { - switch ExprAdd - case [expr_add Op: add_op expr_mult] - { - expr_add( ExprAdd._expr_add ) - send Parser [Op] - expr_mult( ExprAdd.expr_mult ) - } - case [expr_mult] - { - expr_mult( ExprAdd.expr_mult ) - } - } - - void expr_shift( ExprShift: expr_shift ) - { - switch ExprShift - case [expr_shift Op: shift_op expr_add] - { - expr_shift( ExprShift._expr_shift ) - send Parser [Op] - expr_add( ExprShift.expr_add ) - } - case [expr_add] - { - expr_add( ExprShift.expr_add ) - } - } - - void expr_test( ExprTest: expr_test ) - { - switch ExprTest - case [expr_test Op: test_op expr_shift] - { - expr_test( ExprTest._expr_test ) - send Parser [Op] - expr_shift( ExprTest.expr_shift ) - } - case [expr_shift] - { - expr_shift( ExprTest.expr_shift ) - } - } - - void expr( Expr: expr ) - { - expr_test( Expr.expr_test ) - } - - void type( Type: type ) - { - switch Type - case "s8" - send Parser ['i8 '] - case "s16" - send Parser ['i16 '] - case "s32" - send Parser ['i32 '] - case "s64" - send Parser ['i64 '] - case "s128" - send Parser ['i128'] - case "int" - send Parser ['i32'] - case "uint" - send Parser ['u32'] - default - send Parser [Type] - } - - void number( Number: number ) - { - switch Number - case [`u `( uint `) ] - send Parser "[Number.uint]u" - default - send Parser [Number] - } - - void num_list( NumList: num_list ) - { - for Number: number in NumList - send Parser "[number( Number )], " - send Parser "0" - } - - void stmt( Stmt: stmt ) - { - switch Stmt - case [EH: embedded_host] - { - send Parser - [embedded_host( EH )] - } - case [A: static_array] { - Length: int = 1 - for Number: number in A.num_list - Length = Length + 1 - - send Parser - "static [A.ident]: \[[type(A.type)]; [Length]\] = \[ [num_list(A.num_list)] \]; - } - case [V: static_value] { - send Parser - "static [V.ident]: i32 = [V.number]; - } - case [D: declaration] { - send Parser - "let mut [D.ident] " - - switch D.opt_init - case [E: `= expr] { - send Parser - "= [expr(D.opt_init.expr)]; - } - default { - send Parser - "= 0; - } - } - case [Index: index_stmt] - { - send Parser - "let mut [Index.ident] :i32" - - switch Index.opt_init - case [E: `= expr] { - send Parser - "= [expr(Index.opt_init.expr)]; - } - default { - send Parser - "= 0; - } - } - case [ - 'if' `( IfExpr: expr `) IfStmt: stmt - ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? - ] { - send Parser - "if ( [expr(IfExpr)] ) { - " [stmt(IfStmt)] - "} - - for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { - match ElseIfClause - ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] - - send Parser - "else if ( [expr(ElseIfExpr)] ) { - " [stmt(ElseIfStmt)] - "} - } - - if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { - send Parser - "else { - " [stmt(ElseStmt)] - "} - } - } - case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { - send Parser - "while ( [expr(WhileExpr)] ) - " [stmt(WhileStmt)] - } - case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { - send Parser - "match ( [expr(SwitchExpr)] ) { - " [stmt_list(StmtList)] - - NeedDef: bool = true - for Stmt: stmt in repeat(StmtList) { - if match Stmt [default_block] - NeedDef = false - } - - if NeedDef { - send Parser - " _ => {} - } - - send Parser - "} - } - case [ExprExpr: expr Semi: `;] { - send Parser - [expr(ExprExpr) Semi] - } - case [L: `{ TL: stmt* R: `}] { - send Parser - [L stmt_list(TL) R] - } - case [ - TypeList: opt_const Type: type - Ident: ident OptInit: opt_init Semi: `; - ] - { - send Parser - [TypeList type(Type) Ident] - - if match OptInit [E: `= expr] { - send Parser - [E expr(OptInit.expr)] - } - - send Parser - [Semi] - } - case [Export: export_stmt] - { - send Parser - "#define [Export.ident] [number(Export.number)] - } - case ['fallthrough' ';'] - { - # Nothing needed here. - } - case [case_block] - { - send Parser - "[expr( Stmt.case_block.expr )] => { - "[stmt_list( Stmt.case_block._repeat_stmt )] - "} - } - case [default_block] - { - send Parser - "_ => { - "[stmt_list( Stmt.default_block._repeat_stmt )] - "} - } - case [case_label] - { - send Parser - "case [expr( Stmt.case_label.expr )]: - } - case [AS: assign_stmt] - { - send Parser - "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; - } - default { - # catches unspecified cases - send Parser [Stmt] - } - } - - void stmt_list( StmtList: stmt* ) - { - for Stmt: stmt in repeat( StmtList ) - stmt( Stmt ) - } - - void trans( Output: stream, Start: start ) - { - Parser = new parser() - - if ( Start.opt_bom.bom ) - send Output [Start.opt_bom.bom] - - stmt_list( Start._repeat_stmt ) - - CO: rust_out::rust_out = Parser->finish() - - if CO { - send Output - [CO] - } - else { - send stderr - "failed to parse output: [Parser->error] - } - } -end - -void trans( Output: stream, Start: start ) -{ - rust_gen::trans( Output, Start ) -} - -include 'rlhc-main.lm' diff --git a/ragel/host-rust/rlparse.lm b/ragel/host-rust/rlparse.lm deleted file mode 100644 index 100a9223..00000000 --- a/ragel/host-rust/rlparse.lm +++ /dev/null @@ -1,202 +0,0 @@ -include 'ragel.lm' -include 'rlreduce.lm' - -namespace inline - lex - literal `fpc `fc `fcurs `ftargs - `fentry `fhold `fexec `fgoto `fnext - `fcall `fret `fbreak `fncall `fnret `fnbreak - - token ident /ident/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - token dec_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - literal - `{ `} `:: `* `, `( `) `; - - token var_ref - / "$" [a-zA-Z_][a-zA-Z_0-9]* / - { - if GblActionParams - { - input->push( make_token( - typeid, input->pull( match_length ) ) ) - } - else - { - # Just pull one char. Don't consume the word because it may - # be a keyword. - input->push( make_token( - typeid, input->pull( 1 ) ) ) - } - } - - token c_any - / any / - end - -end - -namespace host - lex - literal `%%{ - - token close_inc /'}--%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token close_imp /'}++%%'/ - { - input->push( make_token( typeid, input->pull( match_length ) ) ) - restoreGlobals() - } - - token slr / '%%' [^{] [^\n]* '\n' / - { - # Translates single line to multi-line - input->pull( 2 ) - R: str = input->pull( match_length - 3 ) - input->push( "}%%" ) - input->push( R ) - input->push( "%%{" ) - } - - rl NL / '\n' / - - rl s_literal - / "'" ([^'\\\n] | '\\' (any | NL))* "'" / - - rl d_literal - / '"' ([^"\\] | NL | '\\' (any | NL))* '"' / - - literal `define `= - - token ident /ident "'"?/ - token number /digit+/ - token hex_number /'0x' [0-9a-fA-F]+/ - - token comment - / c_comment | cpp_comment / - - token string - / s_literal | d_literal / - - token whitespace - / ( [ \t] | NL )+ / - - token c_any / any / - end - - def tok - [`define whitespace ident whitespace? number] :ImportDefNum - | [`define whitespace ident whitespace? string] :ImportDefStr - | [ident whitespace? `= whitespace? number] :ImportAssignNum - | [ident whitespace? `= whitespace? string] :ImportAssignStr - | [`define] :Def - | [`=] :Eq - | [ident] :Ident - | [number] :Number - | [hex_number] :HexNumber - | [comment] :Comment - | [string] :String - | [whitespace] :Whitespace - | [c_any] :Any -end - -reduction TopLevel - - # Pass Through. - # def tok - # [`define ident number] :Def1 - # | [`define ident string] :Def2 - # | [ident `= number] :Ass1 - # | [ident `= string] :Ass2 - # [`define whitespace ident whitespace? number] :ImportDefNum - # | [`define whitespace ident whitespace? string] :ImportDefStr - # | [ident whitespace? `= whitespace? number] :ImportAssignNum - # | [ident whitespace? `= whitespace? string] :ImportAssignStr - # | [`define] :Def - # | [`=] :Eq - # | [ident] :Ident - # | [number] :Number - # | [hex_number] :HexNumber - # | [comment] :Comment - # | [string] :String - # | [whitespace] :Whitespace - # | [c_any] :Any - - host::tok :ImportDefNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /* $number->neg */, $number->data, - $number->length, Literal::Number ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportDefStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignNum - { - if ( isImport ) - { - Literal *lit = new Literal( @number, - false /*$number->neg */, $number->data, - $number->length, Literal::Number ); - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - host::tok :ImportAssignStr - { - if ( isImport ) - { - Literal *lit = new Literal( @string, false, - $string->data, $string->length, Literal::LitString ); - - string name( $ident->data, $ident->length ); - import( @ident, name, lit ); - } - } - -end - -export RagelError: str - -# File name. The open is expected to succeed. It is tested before the colm -# program is called. -A: list_el = argv->pop_head_el() -GblFileName = A->value - -# Remaining items are include paths. -while ( argv->length > 0 ) { - A = argv->pop_head_el() - GblIncludePaths->push_tail_el( A ) -} - -Stream: stream = open( GblFileName, "r" ) -reduce TopLevel start[ Stream ] -RagelError = error diff --git a/ragel/rlhc-c.lm b/ragel/rlhc-c.lm new file mode 100644 index 00000000..0a2b6d97 --- /dev/null +++ b/ragel/rlhc-c.lm @@ -0,0 +1,462 @@ +include 'ril.lm' + +namespace c_out + + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`{ _IN_ item* _EX_ `} ] + + def c_out + [_IN_ _EX_ item*] +end + +namespace c_gen + global _: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case Stmt { + "{ + " [stmt_list( StmtList )] + "} + } + case Expr { + "([expr( Expr )])" + } + case Escape { + Str: str = $escape + "[Str.suffix( 1 )]" + } + default { + [Tok] + } + } + } + + void embedded_host( EmbeddedHost: embedded_host ) + { + switch EmbeddedHost + case Expr + { + "([tok_list( TL )])" + } + case Stmt + { + "{ + " [tok_list( TL )] + "} + } + case Bare + { + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case [EH: embedded_host] + { + [embedded_host( EH )] + } + case Paren + { + "([expr( expr )])" + } + case ArraySub + { + "[ident]\[[expr( expr )]\]" + } + case ArraySubField + { + "[ident]\[[expr( expr )]\].[Field]" + } + case Offset + { + "[ident] + [expr( expr )]" + } + case Deref + { + "(*( [expr(expr)] )) + } + case [`TRUE] + { + "1" + } + case [`FALSE] + { + "1" + } + case [N: `nil] + { + "0" + } + case [Number: number] + { + number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast `( T: type `) F: expr_factor] + { + "( [type( T )] ) [expr_factor( F )]" + } + default { + # Catches cases not specified + [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + [embedded_host( EH )] + } + case [ident O: `[ TL: expr C: `]] + { + [ident O expr( TL ) C] + } + case [I: ident `[ E: expr `] `. F: ident] + { + "[I]\[[ expr( E )]\].[F] + } + case [E1: embedded_host `-> E2: lvalue] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + lvalue( E2 ) + } + default { + # Catches cases not specified + [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + ['!' expr_factor_op( _expr_factor_op )] + } + case [T: `~ expr_factor_op] + { + ['~' expr_factor_op( _expr_factor_op )] + } + case [expr_factor] + { + [expr_factor( expr_factor )] + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + [expr_bitwise( _expr_bitwise ) A expr_factor_op( expr_factor_op )] + } + case [expr_factor_op] + { + [expr_factor_op( expr_factor_op )] + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + [expr_mult( _expr_mult ) T expr_bitwise( expr_bitwise )] + } + case [expr_bitwise] + { + [expr_bitwise( expr_bitwise )] + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + [expr_add( _expr_add ) Op expr_mult( expr_mult )] + } + case [expr_mult] + { + [expr_mult( expr_mult )] + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + [expr_shift( _expr_shift ) Op expr_add( expr_add )] + } + case [expr_add] + { + [expr_add( expr_add )] + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + [expr_test( _expr_test ) Op expr_shift( expr_shift )] + } + case [expr_shift] + { + [expr_shift( expr_shift )] + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case S8 + ['signed char '] + case S16 + ['short '] + case S32 + ['int '] + case S64 + ['long '] + case S128 + ['long long '] + case "uint" + ['unsigned int '] + default + [Type] + } + + void number( Number: number ) + { + switch Number + case Unsigned + "[uint]u" + default + [Number] + } + + void num_list( NumList: num_list ) + { + for Number: number in NumList + "[number( Number )], " + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + [embedded_host( EH )] + } + case [A: static_array] { + "static const [type(A.type)] " + "[A.ident] \[\] = { [num_list(A.num_list)] }; + } + case [V: static_value] { + "static const [V.type] [V.ident] = [V.number]; + } + case [ + `if `( IfExpr: expr `) + IfStmt: stmt + ElseIfClauseList: else_if_clause* + ElseClauseOpt: else_clause? + ] { + "if ( [expr(IfExpr)] ) + " [stmt(IfStmt)] + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + [`else `if `( ElseIfExpr: expr `) ElseIfStmt: stmt] + + "else if ( [expr(ElseIfExpr)] ) + " [stmt(ElseIfStmt)] + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + "else + " [stmt(ElseStmt)] + } + } + case [`while `( WhileExpr: expr `) WhileStmt: stmt] { + "while ( [expr(WhileExpr)] ) + " [stmt(WhileStmt)] + } + case [M: match_stmt] { + "switch ( [expr(M.E)] ) { + + for PB: pat_block in repeat( M.P ) { + "case [expr( PB.expr )]: + "[stmt_list( PB._repeat_stmt )] + "break; + } + + if match M.D [D: default_block] { + "default: + "[stmt_list( D._repeat_stmt )] + "break; + } + + "} + } + case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { + "switch ( [expr(SwitchExpr)] ) { + " [stmt_list(StmtList)] + "} + } + case [ES: expr_stmt] { + "[expr(ES.expr)]; + } + case [B: block] { + "{ + " [stmt_list(B.StmtList)] + "} + } + case [ + OptConst: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + "[OptConst] [type(Type)] [Ident]" + + if match OptInit [`= Init: expr] { + " = [expr(Init)] + } + + "; + } + case [Export: export_stmt] + { + "#define [Export.ident] [number(Export.number)] + } + case [fallthrough] + { + # Nothing needed here. + # C falls through by default. + } + case [Index: index_stmt] + { + "const [type(Index.type)] *[Index.ident] + + if match Index.opt_init [E: `= expr] { + [E expr(Index.opt_init.expr)] + } + + "; + } + case [CB: case_block] + { + "case [expr( CB.expr )]: + "[stmt_list( CB._repeat_stmt )] + "break; + } + case [DB: default_block] + { + "default: + "[stmt_list( DB._repeat_stmt )] + "break; + } + case [CL: case_label] + { + "case [expr( CL.expr )]: + } + case [AS: assign_stmt] + { + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + default { + # catches unspecified cases + [Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + _ = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + CO: c_out::c_out = _->finish() + + if CO { + send Output + [CO] + } + else { + send stderr + "failed to parse output: [_->error] + } + } +end + +void trans( Output: stream, Start: start ) +{ + c_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-crack.lm b/ragel/rlhc-crack.lm new file mode 100644 index 00000000..bebe7cd5 --- /dev/null +++ b/ragel/rlhc-crack.lm @@ -0,0 +1,536 @@ +include 'ril.lm' + +namespace crack_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" | + "`" ( [^`\\] | '\\' any ) * "`" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`{ _IN_ item* _EX_ `} ] + + def crack_out + [_IN_ _EX_ item*] +end + +namespace crack_gen + + global Parser: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] { + send Parser + "if ( 1 ) { + " [stmt_list( StmtList )] + "} + } + case [host::`={ Expr: expr host::`}=] { + send Parser + "([expr( Expr )])" + } + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default { + send Parser + [Tok] + } + } + } + + void embedded_host( EmbeddedHost: embedded_host ) + { + switch EmbeddedHost + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + "if ( 1 ) { + " [tok_list( TL )] + "} + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [`( E: expr `)] + { + send Parser + "([expr(E)])" + } + case [I: ident `[ E: expr `]] + { + send Parser + "[I]\[[expr( E )]\]" + } + case [`offset `( ident `, expr `)] + { + send Parser + [expr( ExprFactor.expr )] + } + case [`deref `( ident `, expr `)] + { + send Parser + [ ExprFactor.ident '[' expr( ExprFactor.expr ) ']'] + } + case [`TRUE] + { + send Parser "1" + } + case [`FALSE] + { + send Parser "1" + } + case [N: `nil] + { + send Parser "0" + } + case [Number: number] + { + number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast `( T: type `) F: expr_factor] + { + send Parser + "[type( T )] ( [expr_factor( F )] )" + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' E ']'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case [E1: embedded_host `-> E2: lvalue] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + lvalue( E2 ) + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' E ']'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [T: `~ expr_factor_op] + { + send Parser [T] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + expr_bitwise( ExprBitwise._expr_bitwise ) + send Parser [A] + expr_factor_op( ExprBitwise.expr_factor_op ) + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + send Parser [Op] + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + send Parser [Op] + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case "s8" + send Parser ['int16 '] + case "s16" + send Parser ['int16 '] + case "s32" + send Parser ['int32 '] + case "s64" + send Parser ['int64 '] + case "s128" + send Parser ['long long '] + case "uint" + send Parser ['uint32 '] + default + send Parser [Type] + } + + void number( Number: number ) + { + switch Number + case [`u `( uint `) ] + send Parser "[Number.uint]u" + case [`c `( uint `) ] + send Parser "[Number.uint]" + default + send Parser [Number] + } + + void num_list( NumList: num_list ) + { + for Number: number in NumList + send Parser "[number( Number )], " + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [Array: static_array] { + send Parser + "const array\[[type(Array.type)]\] " + "[Array.ident] = \[ [num_list(Array.num_list)] \]; + } + case [Value: static_value] { + send Parser + "const [Value.type] [Value.ident] = [Value.number]; + } + case [ + `if `( IfExpr: expr `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if ( [expr(IfExpr)] ) + " [flow_stmt(IfStmt)] + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] + + send Parser + "else if ( [expr(ElseIfExpr)] ) + " [flow_stmt(ElseIfStmt)] + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else + " [flow_stmt(ElseStmt)] + } + } + case [`while `( WhileExpr: expr `) WhileStmt: stmt] { + send Parser + "while ( [expr(WhileExpr)] ) + " [flow_stmt(WhileStmt)] + } + case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { + + require StmtList + [`case E1: expr `{ Inner: stmt* `} Rest: stmt*] + + send Parser + "if ( [expr(SwitchExpr)] == [expr(E1)] ) { + " [stmt_list(Inner)] + "} + + for S: stmt in repeat(Rest) { + switch S + case [`case E1: expr `{ Inner: stmt* `}] + { + send Parser + "else if ( [expr(SwitchExpr)] == [expr(E1)] ) { + " [stmt_list(Inner)] + "} + } + case + [`default `{ Inner: stmt* `}] + { + send Parser + "else { + " [stmt_list(Inner)] + "} + } + } + + send Parser + "; + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr(ExprExpr) Semi] + } + case [`{ TL: stmt* `}] { + send Parser + "if ( 1 ) { + " [stmt_list(TL)] + "} + } + case [ + TypeList: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + send Parser + [TypeList type(Type) Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + + send Parser + [Semi] + } + case [Export: export_stmt] + { + send Parser + "#define [Export.ident] [number(Export.number)] + } + case ['fallthrough' ';'] + { + # Nothing needed here. + } + case [Index: index_stmt] + { + send Parser + "int [Index.ident] + + if match Index.opt_init [E: `= expr] { + send Parser + [E expr(Index.opt_init.expr)] + } + else { + send Parser + " = 0" + } + + send Parser "; + } + case [case_block] + { + send Parser + "case [expr( Stmt.case_block.expr )]: + "[stmt_list( Stmt.case_block._repeat_stmt )] + "break; + } + case [default_block] + { + send Parser + "default: + "[stmt_list( Stmt.default_block._repeat_stmt )] + "break; + } + case [case_label] + { + send Parser + "case [expr( Stmt.case_label.expr )]: + } + case [AS: assign_stmt] + { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + default { + # catches unspecified cases + send Parser [Stmt] + } + } + + void flow_stmt( Stmt: stmt ) + { + switch Stmt + case [`{ TL: stmt* `}] { + send Parser + "{ + " [stmt_list(TL)] + "} + } + default { + stmt( Stmt ) + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + Parser = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + CO: crack_out::crack_out = Parser->finish() + + if CO { + send Output + [CO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } + } +end + +void trans( Output: stream, Start: start ) +{ + crack_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-csharp.lm b/ragel/rlhc-csharp.lm new file mode 100644 index 00000000..078157c5 --- /dev/null +++ b/ragel/rlhc-csharp.lm @@ -0,0 +1,480 @@ +include 'ril.lm' + +namespace csharp_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`{ _IN_ item* _EX_ `} ] + + def csharp_out + [_IN_ _EX_ item*] +end + +namespace csharp_gen + + global Parser: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] + send Parser "{[stmt_list( StmtList )]}" + case [host::`={ Expr: expr host::`}=] + send Parser "([expr( Expr )])" + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default { + send Parser [Tok] + } + } + } + + void embedded_host( EH: embedded_host ) + { + switch EH + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + "{[tok_list( TL )]} + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case + [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [O:`( TL: expr C: `)] + { + send Parser + [O expr(TL) C] + } + case [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case ['offset' '(' ident ',' expr ')'] + { + send Parser + [expr( ExprFactor.expr )] + } + case ['deref' '(' ident ',' expr ')'] + { + send Parser + [ ExprFactor.ident '[' expr( ExprFactor.expr ) ']'] + } + case [T: `TRUE] + { + T.data = 'true' + send Parser [T] + } + case [F: `FALSE] + { + F.data = 'false' + send Parser [F] + } + case [N: `nil] + { + N.data = '0' + send Parser [N] + } + case [Number: number] + { + number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast Open: `( Type: type Close: `) expr_factor] + { + send Parser [Open] + type( Type ) + send Parser [Close] + expr_factor( ExprFactor._expr_factor ) + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case [E1: embedded_host `-> E2: lvalue] + { + embedded_host( E1 ) + lvalue( E2 ) + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [T: `~ expr_factor_op] + { + send Parser [T] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + expr_bitwise( ExprBitwise._expr_bitwise ) + send Parser [A] + expr_factor_op( ExprBitwise.expr_factor_op ) + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + send Parser [Op] + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + send Parser [Op] + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case "s8" + send Parser ['sbyte '] + case "s16" + send Parser ['short '] + case "s32" + send Parser ['int '] + case "s64" + send Parser ['long '] + case "s128" + send Parser ['long long '] + case "uint" + send Parser ['uint '] + default + send Parser [Type] + } + + void number( Number: number ) + { + switch Number + case [`c `( uint `) ] { + Str: str = $Number.uint + send Parser "'\\u[sprintf( "%04x", Str.atoi() )]'" + } + case [`u `( uint `) ] { + send Parser [$Number.uint] + } + default { + send Parser [$Number.sint] + } + } + + void num_list( NumList: num_list ) + { + for Number: number in NumList + send Parser "[number( Number )], " + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [A: static_array] { + send Parser + "static readonly [type(A.type)] \[\]" + "[A.ident] = { [num_list( A.num_list )] }; + } + case [V: static_value] { + send Parser + "static readonly [V.type] [V.ident] = [V.number]; + } + case [ + 'if' O: `( IfExpr: expr C: `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if ( [expr(IfExpr)] ) + " [stmt(IfStmt)] + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] + + send Parser + "else if ( [expr(ElseIfExpr)] ) + " [stmt(ElseIfStmt)] + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else + " [stmt(ElseStmt)] + } + } + case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { + send Parser + "while ( [expr(WhileExpr)] ) + " [stmt(WhileStmt)] + } + case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { + send Parser + "switch ( [expr(SwitchExpr)] ) { + " [stmt_list(StmtList)] + "} + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr(ExprExpr) Semi] + } + case [L: `{ TL: stmt* R: `}] { + send Parser + [L stmt_list(TL) R] + } + case [ + TypeList: opt_const Type: type Ident: ident + OptInit: opt_init Semi: `; + ] + { + send Parser + [TypeList type(Type) Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + + send Parser + [Semi] + } + case [Export: export_stmt] + { + send Parser + "#define [Export.ident] [Export.number] + } + case ['fallthrough' ';'] + { + # Nothing needed here. + } + case [Index: index_stmt] + { + send Parser + "int [Index.ident]" + + if match Index.opt_init [E: `= expr] { + send Parser + [E expr(Index.opt_init.expr)] + } + + send Parser ";" + } + case [case_block] + { + send Parser + "case [expr( Stmt.case_block.expr )]: + "[stmt_list( Stmt.case_block._repeat_stmt )] + "break; + } + case [default_block] + { + send Parser + "default: + "[stmt_list( Stmt.default_block._repeat_stmt )] + "break; + } + case [case_label] + { + send Parser + "case [expr( Stmt.case_label.expr )]: + } + case [AS: assign_stmt] + { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + default { + # catches unspecified cases + send Parser [Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + Parser = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + CSO: csharp_out::csharp_out = Parser->finish() + + if CSO { + send Output + [CSO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } + } +end + +void trans( Output: stream, Start: start ) +{ + csharp_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-d.lm b/ragel/rlhc-d.lm new file mode 100644 index 00000000..2a047e68 --- /dev/null +++ b/ragel/rlhc-d.lm @@ -0,0 +1,511 @@ +include 'ril.lm' + +namespace d_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`{ _IN_ item* _EX_ `} ] + + def d_out + [_IN_ _EX_ item*] +end + +namespace d_gen + + global Parser: parser + + global HasDefault: list = new list() + + void pushHasDef( H: int ) + { + HasDefault->push( H ) + } + + int popHasDef() + { + return HasDefault->pop() + } + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] + send Parser "{[stmt_list( StmtList )]}" + case [host::`={ Expr: expr host::`}=] + send Parser "([expr( Expr )])" + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default { + send Parser [Tok] + } + } + } + + void embedded_host( EmbeddedHost: embedded_host ) + { + switch EmbeddedHost + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + "{[tok_list( TL )]} + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host(EH)] + } + case + [O:`( TL: expr C: `)] + { + send Parser + [O expr( TL ) C] + } + case + [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr(TL) C] + } + case + [`offset `( ident `, expr `)] + { + send Parser + "& [ExprFactor.ident] \[ [expr(ExprFactor.expr)] \] + } + case + [`deref `( ident `, expr `)] + { + send Parser + "(*( [expr(ExprFactor.expr)] )) + } + case + [T: `TRUE] + { + T.data = '1' + send Parser [T] + } + case + [F: `FALSE] + { + F.data = '0' + send Parser [F] + } + case + [N: `nil] + { + N.data = 'null' + send Parser [N] + } + case + [Number: number] + { + number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast Open: `( Type: type Close: `) expr_factor] + { + send Parser ['cast' Open] + type( Type ) + send Parser [Close] + expr_factor( ExprFactor._expr_factor ) + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host(EH)] + } + case + [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr(TL) C] + } + case [E1: embedded_host `-> E2: lvalue] + { + embedded_host( E1 ) + lvalue( E2 ) + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [T: `~ expr_factor_op] + { + send Parser [T] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + expr_bitwise( ExprBitwise._expr_bitwise ) + send Parser [A] + expr_factor_op( ExprBitwise.expr_factor_op ) + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + send Parser [Op] + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + send Parser [Op] + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case "s8" + send Parser ['byte '] + case "s16" + send Parser ['short '] + case "s32" + send Parser ['int '] + case "s64" + send Parser ['long '] + case "s128" + send Parser ['long long '] + default + send Parser [Type] + } + + void number( Number: number ) + { + switch Number + case [`u `( uint `) ] + send Parser "[Number.uint]u" + default + send Parser [Number] + } + + void num_list( NumList: num_list ) + { + for Number: number in NumList + send Parser "[number( Number )], " + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host(EH)] + } + case [A: static_array] { + send Parser + "static const [type(A.type)]\[\] " + "[A.ident] = \[ [num_list( A.num_list )] \]; + } + case [V: static_value] { + send Parser + "static const [V.type] [V.ident] = [V.number]; + } + case [ + `if `( IfExpr: expr `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if ( [expr(IfExpr)] ) + " [stmt(IfStmt)] + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + [`else `if `( ElseIfExpr: expr `) ElseIfStmt: stmt] + + send Parser + "else if ( [expr(ElseIfExpr)] ) + " [stmt(ElseIfStmt)] + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else + " [stmt(ElseStmt)] + } + } + case [`while `( WhileExpr: expr `) WhileStmt: stmt] { + send Parser + "while ( [expr(WhileExpr)] ) + " [stmt(WhileStmt)] + } + case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { + pushHasDef( 0 ) + + send Parser + "switch ( [expr(SwitchExpr)] ) { + " [stmt_list(StmtList)] + + if ( popHasDef() == 0 ) { + send Parser + " default: break; + } + + send Parser + "} + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr( ExprExpr ) Semi] + } + case [L: `{ TL: stmt* R: `}] { + send Parser + [L stmt_list( TL ) R] + } + case [ + OptConst: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + if match OptConst ['const'] { + send Parser + "const( [type( Type )] ) + } + else { + type( Type ) + } + + send Parser [Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + + send Parser [Semi] + } + case [case_block] + { + send Parser + "case [expr( Stmt.case_block.expr )]: + "[stmt_list( Stmt.case_block._repeat_stmt )] + "break; + } + case [default_block] + { + send Parser + "default: + "[stmt_list( Stmt.default_block._repeat_stmt )] + "break; + + popHasDef() + pushHasDef( 1 ) + } + case [case_label] + { + send Parser + "case [expr( Stmt.case_label.expr )]: + } + case [export_stmt] + { + send Parser + "static const [type(Stmt.export_stmt.type)] " + "[Stmt.export_stmt.ident] = [number(Stmt.export_stmt.number)]; + } + case ['fallthrough' ';'] + { + send Parser "goto case;" + } + case [Index: index_stmt] + { + send Parser + "const([type(Index.type)]) *[Index.ident]" + + if match Index.opt_init [E: `= expr] { + send Parser + [E expr(Index.opt_init.expr)] + } + + send Parser "; + } + case [AS: assign_stmt] + { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + default { + # catches unspecified cases + send Parser [Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + Parser = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + DO: d_out::d_out = Parser->finish() + + if DO { + send Output + [DO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } + } +end + +void trans( Output: stream, Start: start ) +{ + d_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-go.lm b/ragel/rlhc-go.lm new file mode 100644 index 00000000..21aa1cee --- /dev/null +++ b/ragel/rlhc-go.lm @@ -0,0 +1,453 @@ +include 'ril.lm' + +namespace out_go + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`{ _IN_ item* _EX_ `} ] + + def out_go + [_IN_ _EX_ item*] +end + + + +namespace go_gen + + global _: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case Stmt { + "{ + stmt_list( StmtList ) + "} + } + case Expr { + "([expr( Expr )])" + } + case Escape { + Str: str = $Tok + "[Str.suffix( 1 )]" + } + default { + [Tok] + } + } + } + + void embedded_host( EmbeddedHost: embedded_host ) + { + switch EmbeddedHost + case Expr + { + ['(' tok_list( TL ) ')'] + } + case Stmt + { + ['{' tok_list( TL ) '}\n'] + } + case Bare + { + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case EmbeddedHost + { + [embedded_host(embedded_host)] + } + case Paren + { + ['( ' expr(expr) ' )'] + } + case ArraySub + { + [ident '[ ' expr( expr ) ' ]'] + } + case Offset + { + "int([expr(expr )]) + } + case Deref + { + [ident '[ ' expr( expr ) ' ]' ] + } + case True + { + "true" + } + case False + { + "false" + } + case Nil + { + "0" + } + case Access + { + embedded_host(embedded_host) + expr_factor(_expr_factor) + } + case Cast + { + [type(type) '( ' expr_factor(_expr_factor) ' )' ] + } + default { + # Catches cases not specified + [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + [embedded_host(EH)] + } + case [ident `[ TL: expr `]] + { + [ident '[' expr( TL ) ']'] + } + case [E1: embedded_host `-> E2: lvalue] + { + embedded_host( E1 ) + lvalue( E2 ) + } + default { + # Catches cases not specified + [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + ['! ' expr_factor_op( _expr_factor_op )] + } + case [T: `~ expr_factor_op] + { + ['^ ' expr_factor_op( _expr_factor_op )] + } + case [expr_factor] + { + [expr_factor( ExprFactorOp.expr_factor )] + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + [expr_bitwise( _expr_bitwise ) ' & ' expr_factor_op( expr_factor_op )] + } + case [expr_factor_op] + { + [expr_factor_op( ExprBitwise.expr_factor_op )] + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + [expr_mult( _expr_mult ) ' * ' expr_bitwise( expr_bitwise )] + } + case [expr_bitwise] + { + [expr_bitwise( expr_bitwise )] + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + [expr_add( _expr_add ) ' ' Op ' ' expr_mult( expr_mult )] + } + case [expr_mult] + { + [expr_mult( ExprAdd.expr_mult )] + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + [expr_shift( _expr_shift ) ' ' Op ' ' expr_add( expr_add )] + } + case [expr_add] + { + [expr_add( expr_add )] + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + [expr_test( _expr_test ) ' ' Op ' ' expr_shift( expr_shift )] + } + case [expr_shift] + { + [expr_shift( ExprTest.expr_shift )] + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case S8 + ['int8'] + case S16 + ['int16'] + case S32 + ['int32'] + case S64 + ['int64'] + case S128 + ['long long'] + default + [Type] + } + + void number( Number: number ) + { + switch Number + case Unsigned + [uint] + default + [Number] + } + + void num_list( NumList: num_list ) + { + number( NumList.number ) + for CommaNum: comma_num in NumList { + [', ' number( CommaNum.number )] + } + } + + # Go must have {} around if and for statements. We strip any blocks from + # these statments and force our own. + void strip_block_stmt( Stmt: stmt ) + { + if match Stmt [`{ StmtList: stmt* `}] + stmt_list(StmtList) + else + stmt( Stmt ) + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + [embedded_host(EH)] + } + case [A: static_array] { + "var [A.ident] = \[\] " + "[type(A.type)] { [num_list(A.num_list)] } + } + case [V: static_value] { + "var [V.ident] [type(V.type)] = [V.number] + "var _ = [V.ident] + } + case [ + 'if' O: `( IfExpr: expr C: `) IfStmt: stmt + ] { + # if-statements with only the if clause can go out as an if. + "if [expr(IfExpr)] { + strip_block_stmt(IfStmt) + "} + } + case [ + 'if' O: `( IfExpr: expr C: `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + # If the if-statement has more than just an if clause it goes out as a switch. + "if [expr( IfExpr )] { + strip_block_stmt( IfStmt ) + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] + + "} else if [expr(ElseIfExpr)] { + strip_block_stmt(ElseIfStmt) + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + "} else { + strip_block_stmt(ElseStmt) + } + + "} + } + case ["while ( TRUE )" WhileStmt: stmt] { + "for { + strip_block_stmt(WhileStmt) + "} + } + case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { + "for [expr(WhileExpr)] { + strip_block_stmt(WhileStmt) + "} + } + case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { + "switch [expr(SwitchExpr)] { + stmt_list(StmtList) + "} + } + case [ExprExpr: expr `;] { + [expr(ExprExpr) ';'] + } + case [B: block] { + "{ + stmt_list(B.StmtList) + "} + } + case [D: declaration] + { + "var [D.ident] [type(D.type)]" + + if match D.opt_init ['=' Expr: expr] { + " = [expr(Expr)]" + } + ['\n'] + } + case [ES: export_stmt] + { + "#define [ES.ident] [number(ES.number)] + } + case [fallthrough] + { + "fallthrough + } + case [Index: index_stmt] + { + "var [Index.ident] int" + + if match Index.opt_init ['=' Expr: expr] { + " = [expr(Expr)]" + } + + ['\n'] + } + case [CB: case_block] + { + "case [expr( CB.expr )]: + stmt_list( CB._repeat_stmt ) + } + case [DB: default_block] + { + "default: + stmt_list( DB._repeat_stmt ) + } + case [CL: case_label] + { + "case [expr( CL.expr )]: + } + case [AS: assign_stmt] + { + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + default { + # catches unspecified cases + "[Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + _ = new parser() + Input: _input = _->gets() + Input->auto_trim(true) + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + GO: out_go::out_go = _->finish() + + if GO { + send Output + [GO] + } + else { + send stderr + "failed to parse output: [_->error] + } + + } +end + +void trans( Output: stream, Start: start ) +{ + go_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-java.lm b/ragel/rlhc-java.lm new file mode 100644 index 00000000..a458369f --- /dev/null +++ b/ragel/rlhc-java.lm @@ -0,0 +1,504 @@ +include 'ril.lm' + +namespace java_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`{ _IN_ item* _EX_ `} ] + + def java_out + [_IN_ _EX_ item*] +end + +namespace java_gen + + global Parser: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] { + send Parser + "{ + " [stmt_list( StmtList )] + "} + } + case [host::`={ Expr: expr host::`}=] + send Parser "([expr( Expr )])" + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default { + send Parser [Tok] + } + } + } + + void embedded_host( EH: embedded_host ) + { + switch EH + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + "{ + " [tok_list( TL )] + "} + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case + [O:`( TL: expr C: `)] + { + send Parser + [O expr(TL) C] + } + case + [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case + ['offset' '(' ident ',' expr ')'] + { + send Parser + [expr( ExprFactor.expr )] + } + case + ['deref' '(' ident ',' expr ')'] + { + send Parser + [ ExprFactor.ident '[' expr( ExprFactor.expr ) ']'] + } + case + [T: `TRUE] + { + T.data = 'true' + send Parser [T] + } + case + [F: `FALSE] + { + F.data = 'false' + send Parser [F] + } + case + [N: `nil] + { + N.data = '0' + send Parser [N] + } + case + [Number: number] + { + number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast Open: `( Type: type Close: `) expr_factor] + { + send Parser [Open] + type( Type ) + send Parser [Close] + expr_factor( ExprFactor._expr_factor ) + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' E ']'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case + [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case [E1: embedded_host `-> E2: lvalue] + { + embedded_host( E1 ) + lvalue( E2 ) + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' E ']'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [T: `~ expr_factor_op] + { + send Parser [T] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + expr_bitwise( ExprBitwise._expr_bitwise ) + send Parser [A] + expr_factor_op( ExprBitwise.expr_factor_op ) + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + send Parser [Op] + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + send Parser [Op] + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case "s8" + send Parser ['byte '] + case "s16" + send Parser ['short '] + case "s32" + send Parser ['int '] + case "s64" + send Parser ['long '] + case "s128" + send Parser ['long long '] + case "uint" + send Parser ['int '] + default + send Parser [Type] + } + + void number( Number: number ) + { + switch Number + case [`u `( uint `) ] + send Parser "[Number.uint]" + default + send Parser [Number] + } + + void java_num_list( NumList: num_list ) + { + for Number: number in NumList + send Parser "[number( Number )], " + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [A: static_array] { + send Parser + "private static [type(A.type)] " + "[A.ident] \[\] = { [java_num_list(A.num_list)] }; + } + case [V: static_value] { + send Parser + "private static [V.type] [V.ident] = [V.number]; + } + case [ + 'if' O: `( IfExpr: expr C: `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if ( [expr(IfExpr)] ) + " [stmt(IfStmt)] + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] + + send Parser + "else if ( [expr(ElseIfExpr)] ) + " [stmt(ElseIfStmt)] + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else + " [stmt(ElseStmt)] + } + } + case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { + send Parser + "while ( [expr(WhileExpr)] ) + " [stmt(WhileStmt)] + } + case [BL: break_label? 'while' '(' WhileExpr: expr ')' '{' StmtList: stmt* '}' ] { + if match BL [bl: break_label] + send Parser "[bl.ident]: " + + send Parser + "while ( [expr(WhileExpr)] ) { + " [stmt_list(StmtList)] + "} + } + case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { + send Parser + "switch ( [expr(SwitchExpr)] ) { + " [stmt_list(StmtList)] + "} + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr(ExprExpr) Semi] + } + case [L: `{ TL: stmt* R: `}] { + send Parser + "{ + " [stmt_list(TL)] + "} + } + case [ + TypeList: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + send Parser + [TypeList type(Type) Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + + send Parser + [Semi] + } + case [Export: export_stmt] + { + send Parser + "static final char [Export.ident] = [number(Export.number)]; + } + case ['fallthrough' ';'] + { + # Nothing needed here. + } + case [Index: index_stmt] + { + send Parser + "int [Index.ident]" + + if match Index.opt_init [E: `= expr] { + send Parser + [E expr(Index.opt_init.expr)] + } + send Parser "; + + } + case [case_block] + { + send Parser + "case [expr( Stmt.case_block.expr )]: + "[stmt_list( Stmt.case_block._repeat_stmt )] + "break; + } + case [default_block] + { + send Parser + "default: + "[stmt_list( Stmt.default_block._repeat_stmt )] + "break; + } + case [goto_label] { } + case [G: goto_stmt] { } + case [AS: assign_stmt] + { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + default { + # catches unspecified cases + send Parser [Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + Parser = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + JO: java_out::java_out = Parser->finish() + + if JO { + send Output + [JO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } + } +end + +void trans( Output: stream, Start: start ) +{ + java_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-js.lm b/ragel/rlhc-js.lm new file mode 100644 index 00000000..29a61346 --- /dev/null +++ b/ragel/rlhc-js.lm @@ -0,0 +1,504 @@ +include 'ril.lm' + +namespace js_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`{ _IN_ item* _EX_ `} ] + + def js_out + [_IN_ _EX_ item*] +end + +namespace js_gen + + global Parser: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] { + send Parser + "{ + " [stmt_list( StmtList )] + "} + } + case [host::`={ Expr: expr host::`}=] { + send Parser + "([expr( Expr )])" + } + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default { + send Parser + [Tok] + } + } + } + + void embedded_host( EmbeddedHost: embedded_host ) + { + switch EmbeddedHost + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + "{ + " [tok_list( TL )] + "} + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [O:`( TL: expr C: `)] + { + send Parser + [O expr(TL) C] + } + case [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case ['offset' '(' ident ',' expr ')'] + { + send Parser + [expr( ExprFactor.expr )] + } + case ['deref' '(' ident ',' expr ')'] + { + send Parser [ExprFactor.ident] + if $ExprFactor.ident == 'data' + send Parser ['.charCodeAt(' expr( ExprFactor.expr ) ')'] + else + send Parser ['[' expr( ExprFactor.expr ) ']'] + } + case [T: `TRUE] + { + T.data = 'true' + send Parser [T] + } + case [F: `FALSE] + { + F.data = 'false' + send Parser [F] + } + case [N: `nil] + { + N.data = '-1' + send Parser [N] + } + case [Number: number] + { + number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast Open: `( type Close: `) expr_factor] + { + expr_factor( ExprFactor._expr_factor ) + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case [I: ident `[ E: expr `] `. F: ident] + { + send Parser + "[I]\[[ expr( E )]\].[F] + } + case [E1: embedded_host `-> E2: lvalue] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + lvalue( E2 ) + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [T: `~ expr_factor_op] + { + send Parser [T] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + expr_bitwise( ExprBitwise._expr_bitwise ) + send Parser [A] + expr_factor_op( ExprBitwise.expr_factor_op ) + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + send Parser [Op] + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } + } + + void expr_test_op( Op: test_op ) + { + switch Op + case [ `== ] + send Parser '===' + case [ `!= ] + send Parser '!==' + default + send Parser [Op] + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + expr_test_op( ExprTest.test_op ) + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void number( Number: number ) + { + switch Number + case [`u `( uint `) ] + send Parser [Number.uint] + default + send Parser [Number] + } + + void type( Type: type ) + { + switch Type + case 'u8' + send Parser 'Uint8' + case 'u16' + send Parser 'Uint16' + case 'u32' + send Parser 'Uint32' + case 's8' + send Parser 'Int8' + case 's16' + send Parser 'Int16' + case 's32' + send Parser 'Int32' + default + send Parser 'Float64' + } + + void num_list( NumList: num_list ) + { + number( NumList.number ) + for CommaNum: comma_num in NumList { + send Parser [', '] + number( CommaNum.number ) + } + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [A: static_array] { + send Parser + "var [A.ident] = new [type(A.type)]Array(\[ [num_list(A.num_list)]\]); + } + case [V: static_value] { + send Parser + "var [V.ident] = [V.number]; + } + case [ + 'if' O: `( IfExpr: expr C: `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if ( [expr(IfExpr)] ) + " [stmt(IfStmt)] + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] + + send Parser + "else if ( [expr(ElseIfExpr)] ) + " [stmt(ElseIfStmt)] + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else + " [stmt(ElseStmt)] + } + } + case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { + send Parser + "while ( [expr(WhileExpr)] ) + " [stmt(WhileStmt)] + } + case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { + send Parser + "switch ( [expr(SwitchExpr)] ) { + " [stmt_list(StmtList)] + "} + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr(ExprExpr) Semi] + } + case [L: `{ TL: stmt* R: `}] { + send Parser + "{ + " [stmt_list(TL)] + "} + } + case [ + TypeList: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + send Parser + "var [Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + + send Parser + [Semi] + } + case [Export: export_stmt] + { + send Parser + "var [Export.ident] = [number(Export.number)]; + } + case ['fallthrough' ';'] + { + # Nothing needed here. + } + case [Index: index_stmt] + { + send Parser + "var [Index.ident]" + + if match Index.opt_init [E: `= expr] { + send Parser + [E expr(Index.opt_init.expr)] + } + + send Parser + "; + } + case [case_block] + { + send Parser + "case [expr( Stmt.case_block.expr )]: + "[stmt_list( Stmt.case_block._repeat_stmt )] + "break; + } + case [default_block] + { + send Parser + "default: + "[stmt_list( Stmt.default_block._repeat_stmt )] + "break; + } + case [goto_label] { } + case [G: goto_stmt] { } + case [AS: assign_stmt] + { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + default { + # catches unspecified cases + send Parser [Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + Parser = new parser() + + send Parser + "'use strict'; + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + CO: js_out::js_out = Parser->finish() + + if CO { + send Output + [CO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } + } +end + +void trans( Output: stream, Start: start ) +{ + js_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-julia.lm b/ragel/rlhc-julia.lm new file mode 100644 index 00000000..72108994 --- /dev/null +++ b/ragel/rlhc-julia.lm @@ -0,0 +1,561 @@ +include 'ril.lm' + +namespace julia_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + literal `function `end `while `if `else `elseif + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def kw + [`function _IN_] + | [`while _IN_] + | [`if _IN_] + | [_EX_ `elseif _IN_] + | [_EX_ `else _IN_] + | [_EX_ `end] + + def item + [comment] + | [kw] + | [id] + | [number] + | [symbol] + | [string] + | [`{ _IN_ item* _EX_ `} ] + + def julia_out + [_IN_ _EX_ item*] +end + +namespace julia_gen + + global Parser: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] { + send Parser + "begin + " [stmt_list( StmtList )] + "end + } + case [host::`={ Expr: expr host::`}=] { + send Parser + "([expr( Expr )])" + } + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default { + send Parser + [Tok] + } + } + } + + void embedded_host( EmbeddedHost: embedded_host ) + { + switch EmbeddedHost + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + [tok_list( TL )] + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [`( E: expr `)] + { + send Parser + "([expr(E)])" + } + case [I: ident `[ E: expr `]] + { + send Parser + "[I]\[1+([expr( E )])\]" + } + case [`offset `( ident `, expr `)] + { + send Parser + [expr( ExprFactor.expr )] + } + case [`deref `( I: ident `, E: expr `)] + { + send Parser + "[I]\[1+([ expr( E ) ])\]" + } + case [`TRUE] + { + send Parser "true" + } + case [`FALSE] + { + send Parser "false" + } + case [N: `nil] + { + send Parser "0" + } + case [Number: number] + { + number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast `( T: type `) F: expr_factor] + { + send Parser + "convert([type( T )], [expr_factor( F )] )" + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[1+(' expr(E) ')]'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [I: ident `[ E: expr `]] + { + send Parser + "[I]\[1+([expr( E )])\]" + } + case [E1: embedded_host `-> E2: lvalue] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + lvalue( E2 ) + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[1+(' expr(E) ')]'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [T: `~ expr_factor_op] + { + send Parser [T] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + expr_bitwise( ExprBitwise._expr_bitwise ) + send Parser [A] + expr_factor_op( ExprBitwise.expr_factor_op ) + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + send Parser [Op] + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + send Parser [Op] + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case "s8" + send Parser ['Int8'] + case "u8" + send Parser ['UInt8'] + case "s16" + send Parser ['Int16'] + case "s32" + send Parser ['Int32'] + case "s64" + send Parser ['Int64'] + case "s128" + send Parser ['Int128'] + case "uint" + send Parser ['UInt'] + case "int" + send Parser ['Int'] + default + send Parser [Type] + } + + void number( Number: number ) + { + switch Number + case [`u `( uint `) ] + send Parser "[Number.uint]u" + default + send Parser [Number] + } + + void num_list( NumList: num_list ) + { + for Number: number in NumList + send Parser "[number( Number )], " + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [A: static_array] { + send Parser + "const [A.ident] = [type(A.type)]\[[num_list(A.num_list)]\] + } + case [V: static_value] { + send Parser + "const [V.ident] = [V.number] + } + # case [declaration] + case [ + TypeList: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + send Parser + [Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + else { + send Parser + "= 0 + } + + send Parser + [Semi] + } + case [ + `if `( IfExpr: expr `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if [expr(IfExpr)] + " [stmt(IfStmt)] + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + [`else `if `( ElseIfExpr: expr `) ElseIfStmt: stmt] + + send Parser + "elseif [expr(ElseIfExpr)] + " [stmt(ElseIfStmt)] + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else + " [stmt(ElseStmt)] + } + + send Parser + "end + } + case [`while `( WhileExpr: expr `) WhileStmt: stmt] { + send Parser + "while [expr(WhileExpr)] + " [stmt(WhileStmt)] + "end + } + case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { + + require StmtList + [`case E1: expr `{ Inner: stmt* `} Rest: stmt*] + + send Parser + "if [expr(SwitchExpr)] == [expr(E1)] + " [stmt_list(Inner)] + + for S: stmt in repeat(Rest) { + switch S + case [`case E1: expr `{ Inner: stmt* `}] + { + send Parser + "elseif [expr(SwitchExpr)] == [expr(E1)] + " [stmt_list(Inner)] + } + case + [`default `{ Inner: stmt* `}] + { + send Parser + "else + " [stmt_list(Inner)] + } + } + + send Parser + "end + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr(ExprExpr)] + } + case [L: `{ TL: stmt* R: `}] { + send Parser + [stmt_list(TL)] + } + case [ + TypeList: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + send Parser + [TypeList type(Type) Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + + send Parser "; + } + case [Export: export_stmt] + { + send Parser + "#define [Export.ident] [number(Export.number)] + } + case ['fallthrough' ';'] + { + # Nothing needed here. + } + case [Index: index_stmt] + { + send Parser + "[Index.ident]" + + if match Index.opt_init [E: `= expr] { + send Parser + [E expr(Index.opt_init.expr)] + } + else { + send Parser " = 0 " + + } + + send Parser "; + } + case [case_block] + { + send Parser + "@case [expr( Stmt.case_block.expr )] begin + "[stmt_list( Stmt.case_block._repeat_stmt )] + "end + } + case [default_block] + { + send Parser + "default: + "[stmt_list( Stmt.default_block._repeat_stmt )] + "break; + } + case [case_label] + { + send Parser + "@case [expr( Stmt.case_label.expr )] + } + case [L: goto_label] + { + send Parser + "@label [L.ident] + } + case [G: goto_stmt] + { + send Parser + "@goto [G.ident] + } + case [AS: assign_stmt] + { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)] + } + default { + # catches unspecified cases + send Parser + "[Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + Parser = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + CO: julia_out::julia_out = Parser->finish() + + if CO { + send Output + [CO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } + } +end + +void trans( Output: stream, Start: start ) +{ + julia_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-ocaml.lm b/ragel/rlhc-ocaml.lm new file mode 100644 index 00000000..f68b61be --- /dev/null +++ b/ragel/rlhc-ocaml.lm @@ -0,0 +1,609 @@ +include 'ril.lm' + +namespace ocaml_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '(*' any* :>> '*)' + / + + literal `begin `end `{ `} + + token id + /[a-zA-Z_][a-zA-Z_0-9]* "'"? / + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' | '`' / + + token string / + '"' ( [^"\\\n] | '\\' any ) * '"' | + "'" ( [^'\\\n] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`begin _IN_ item* _EX_ `end ] + | [`{ _IN_ item* _EX_ `} ] + + def ocaml_out + [_IN_ _EX_ item*] +end + +namespace ml_gen + + global StaticVarMap: map = new map() + global Parser: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] + send Parser + "begin + "[stmt_list( StmtList )] + "end; + case [host::`={ Expr: expr host::`}=] + send Parser "([expr( Expr )])" + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default { + send Parser [Tok] + } + } + } + + void embedded_host( EH: embedded_host ) + { + switch EH + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + "begin + "[tok_list( TL )] + "end; + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [`( TL: expr `)] + { + send Parser + "( [ expr(TL) ] )" + } + case [I: ident `[ TL: expr `]] + { + if ( StaticVarMap->find( $I ) || $I == 'stack' ) { + send Parser + "[ ExprFactor.ident ].([ expr( TL ) ])" + } + else { + send Parser + "[ ExprFactor.ident ].\[[ expr( TL ) ]\]" + } + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '.(' expr(E) ')'] + } + case ['offset' '(' ident ',' expr ')'] + { + send Parser + [expr( ExprFactor.expr )] + } + case ['deref' '(' I: ident ',' Expr: expr ')'] + { + if ( $I == 'data' ) + send Parser 'Char.code ' + + if ( StaticVarMap->find( $I ) ) { + send Parser + "[I].( [ expr( Expr ) ] )" + } + else { + send Parser + "[I].\[[ expr( Expr ) ]\]" + } + } + case [T: `TRUE] + { + T.data = 'true' + send Parser [T] + } + case [F: `FALSE] + { + F.data = 'false' + send Parser [F] + } + case [N: `nil] + { + N.data = '0' + send Parser [N] + } + case [Number: number] + { + number( Number ) + } + case [I: ident] { + if ( StaticVarMap->find( $I ) ) { + send Parser + [^I] + } + else { + send Parser + "[^I].contents" + } + } + case [E1: embedded_host `-> E2: expr_factor] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast `( type `) expr_factor] + { + send Parser + [expr_factor( ExprFactor._expr_factor )] + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' E ']'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case [E1: embedded_host `-> E2: lvalue] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + lvalue( E2 ) + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '.(' E ')'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [T: `~ expr_factor_op] + { + send Parser " lnot " + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [L: expr_bitwise `& R: expr_factor_op] + { + send Parser + "[expr_bitwise( L )] land [expr_factor_op( R )]" + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + switch Op + case [`<<] + send Parser " lsl " + default + send Parser " asr " + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + switch Op + case [`==] + send Parser "= " + default + send Parser [Op] + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case "s8" + send Parser ['char '] + case "s16" + send Parser ['short '] + case "s32" + send Parser ['int '] + case "s64" + send Parser ['long '] + case "s128" + send Parser ['long long '] + case "uint" + send Parser ['int '] + default + send Parser [Type] + } + + void number( Number: number ) + { + switch Number + case [`u `( uint `) ] + send Parser "[Number.uint]u" + default + send Parser [Number] + } + + void num_list( NumList: num_list ) + { + for Number: number in NumList + send Parser "[number( Number )]; " + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [A: static_array] { + StaticVarMap->insert( $A.ident, ' ' ) + send Parser + "let [A.ident] : int array = \[| + " [num_list(A.num_list)] + "|\] + } + case [V: static_value] { + StaticVarMap->insert( $V.ident, ' ' ) + send Parser + "let [V.ident] : [V.type] = [V.number] + } + case [ + 'if' O: `( IfExpr: expr C: `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if [expr(IfExpr)] then + "begin + " [stmt(IfStmt)] + "end + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] + + send Parser + "else if [expr(ElseIfExpr)] then + "begin + " [stmt(ElseIfStmt)] + "end + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else + "begin + " [stmt(ElseStmt)] + "end + } + + send Parser + ";" + } + case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { + send Parser + "while [expr(WhileExpr)] do + " [stmt(WhileStmt)] + "done; + } + case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { + require StmtList + [`case E1: expr `{ Inner: stmt* `} Rest: stmt*] + + send Parser + "if [expr(SwitchExpr)] = [expr(E1)] then + "begin + " [stmt_list(Inner)] + "end + + for S: stmt in repeat(Rest) { + switch S + case [`case E1: expr `{ Inner: stmt* `}] + { + send Parser + "else if [expr(SwitchExpr)] = [expr(E1)] then + "begin + " [stmt_list(Inner)] + "end + } + case + [`default `{ Inner: stmt* `}] + { + send Parser + "else + "begin + " [stmt_list(Inner)] + "end + } + } + + send Parser + "; + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr(ExprExpr) Semi] + } + case [L: `{ TL: stmt* R: `}] { + send Parser + "begin + "[stmt_list(TL)] + "end; + } + case [D: declaration] { + send Parser + "let [D.ident] : [type(D.type)] ref " + + switch D.opt_init + case [E: `= expr] { + send Parser + "= ref ( [expr(D.opt_init.expr)] )" + } + default { + send Parser + "= ref 0" + } + + send Parser + " in + } + case [Export: export_stmt] + { + send Parser + "#define [Export.ident] [number(Export.number)] + } + case ['fallthrough' ';'] + { + # Nothing needed here. + } + case [Index: index_stmt] + { + send Parser + "let [Index.ident] : int ref " + + switch Index.opt_init + case [E: `= expr] { + send Parser + "= ref ( [expr(Index.opt_init.expr)] )" + } + default { + send Parser + "= ref 0" + } + + send Parser + " in + } + case [case_block] + { + send Parser + "| [expr( Stmt.case_block.expr )] -> + "begin + "[stmt_list( Stmt.case_block._repeat_stmt )] + "end; + } + case [default_block] + { + send Parser + "| _ -> + "[stmt_list( Stmt.default_block._repeat_stmt )] + } + case [case_label] + { + send Parser + "case [expr( Stmt.case_label.expr )]: + } + case [AS: assign_stmt] + { + switch AS.assign_op + case [`=] + { + switch AS.LValue + case "stack\[[expr]\]" { + send Parser + "Array.set stack top.contents [expr(AS.expr)]; + } + case "nfa_bp\[[expr]\].state" { + send Parser + "Array.set nfa_bp_state nfa_len.contents [expr(AS.expr)]; + } + case "nfa_bp\[[expr]\].p" { + send Parser + "Array.set nfa_bp_p nfa_len.contents [expr(AS.expr)]; + } + default { + send Parser + "[lvalue(AS.LValue)] := [expr(AS.expr)]; + } + } + case [`+=] + { + parse RhsAsFactor: expr_factor [$AS.LValue] + send Parser + "[lvalue(AS.LValue)] := [expr_factor(RhsAsFactor)] + [expr(AS.expr)]; + } + case [`-=] + { + parse RhsAsFactor: expr_factor [$AS.LValue] + send Parser + "[lvalue(AS.LValue)] := [expr_factor(RhsAsFactor)] - [expr(AS.expr)]; + } + default { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + } + default { + # catches unspecified cases + send Parser [Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + Parser = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + MO: ocaml_out::ocaml_out = Parser->finish() + + if MO { + send Output + [MO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } + } + +end + +void trans( Output: stream, Start: start ) +{ + ml_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-ruby.lm b/ragel/rlhc-ruby.lm new file mode 100644 index 00000000..87119465 --- /dev/null +++ b/ragel/rlhc-ruby.lm @@ -0,0 +1,527 @@ +include 'ril.lm' + +namespace ruby_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '#' any* :> '\n' + / + + literal `def `class `begin `end `while `if + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" | + "/" ( [^/\\] | '\\' any ) * "/" + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' | '{' | '}' | '\\' / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [`begin _IN_] + | [`class _IN_] + | [`while _IN_] + | [`if _IN_] + | [`def _IN_] + | [_EX_ `end] + + def ruby_out + [_IN_ _EX_ item*] +end + +global Parser: parser + +void tok_list( TL: host::tok* ) +{ + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] + { + send Parser + "begin + "[stmt_list( StmtList )] + "end + } + case [host::`={ Expr: expr host::`}=] + expr( Expr ) + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default { + send Parser [Tok] + } + } +} + +void embedded_host( EH: embedded_host ) +{ + switch EH + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + "begin + " [tok_list( TL )] + "end + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } +} + +void expr_factor( ExprFactor: expr_factor ) +{ + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [O:`( TL: expr C: `)] + { + send Parser + [O expr(TL) C] + } + case [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case ['offset' '(' ident ',' expr ')'] + { + send Parser + [expr( ExprFactor.expr )] + } + case ['deref' '(' ident ',' expr ')'] + { + send Parser + [ ExprFactor.ident '[' expr( ExprFactor.expr ) ']'] + if $ExprFactor.ident == 'data' + send Parser '.ord' + } + case [T: `TRUE] + { + T.data = 'true' + send Parser [T] + } + case [F: `FALSE] + { + F.data = 'false' + send Parser [F] + } + case [N: `nil] + { + N.data = '0' + send Parser [N] + } + case [Number: number] + { + ruby_number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast Open: `( Type: type Close: `) expr_factor] + { + #send Parser [Open] + #type( Type ) + #send Parser [Close] + expr_factor( ExprFactor._expr_factor ) + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' E ']'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } +} + +void lvalue( ExprFactor: lvalue ) +{ + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [ident O: `[ TL: expr C: `]] + { + send Parser + [ExprFactor.ident O expr( TL ) C] + } + case [E1: embedded_host `-> E2: lvalue] + { + embedded_host( E1 ) + lvalue( E2 ) + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' E ']'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } +} + +void expr_factor_op( ExprFactorOp: expr_factor_op ) +{ + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [T: `~ expr_factor_op] + { + send Parser [T] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } +} + +void expr_bitwise( ExprBitwise: expr_bitwise ) +{ + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + expr_bitwise( ExprBitwise._expr_bitwise ) + send Parser [A] + expr_factor_op( ExprBitwise.expr_factor_op ) + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } +} + +void expr_mult( ExprMult: expr_mult ) +{ + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } +} + +void expr_add( ExprAdd: expr_add ) +{ + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } +} + +void expr_shift( ExprShift: expr_shift ) +{ + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + send Parser [Op] + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } +} + +void expr_test( ExprTest: expr_test ) +{ + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + send Parser [Op] + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } +} + +void expr( Expr: expr ) +{ + expr_test( Expr.expr_test ) +} + +void type( Type: type ) +{ + switch Type + case "s8" + send Parser ['byte '] + case "s16" + send Parser ['short '] + case "s32" + send Parser ['int '] + case "s64" + send Parser ['long '] + case "s128" + send Parser ['long long '] + case "uint" + send Parser ['int '] + default + send Parser [Type] +} + +void ruby_number( Number: number ) +{ + switch Number + case [`u `( uint `) ] + send Parser "[Number.uint]" + default + send Parser [Number] +} + +void ruby_num_list( NumList: num_list ) +{ + for Number: number in NumList + send Parser "[ruby_number( Number )], " +} + +void stmt( Stmt: stmt ) +{ + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [A: static_array] { + send Parser + "class << self + " attr_accessor :[ A.ident ] + " private :[ A.ident ], :[ A.ident ]= + "end + "self.[ A.ident ] = \[ + " [ruby_num_list( A.num_list )] + "\] + " + } + case [V: static_value] { + send Parser + "class << self + " attr_accessor :[ V.ident ] + "end + "self.[ V.ident ] = [ V.number ]; + " + } + case [ + 'if' O: `( IfExpr: expr C: `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if ( [expr(IfExpr)] ) + " [stmt(IfStmt)] + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] + + send Parser + "elsif ( [expr(ElseIfExpr)] ) + " [stmt(ElseIfStmt)] + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else + " [stmt(ElseStmt)] + } + send Parser + "end + } + case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { + send Parser + "while ( [expr(WhileExpr)] ) + " [stmt(WhileStmt)] + "end + } + case ['switch' '(' SwitchExpr: expr ')' '{' StmtList: stmt* '}'] { + send Parser + "case [expr(SwitchExpr)] + "when -2 then + "begin + " [stmt_list(StmtList)] + "end + "end + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr(ExprExpr) Semi] + } + case [L: `{ TL: stmt* R: `}] { + send Parser + "begin + "[stmt_list(TL)] + "end + } + # [declaration] + case [ + TypeList: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + send Parser + [Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + else { + send Parser + "= 0 + } + + send Parser + [Semi] + } + case [Export: export_stmt] + { + send Parser + "class << self + " attr_accessor :[ Export.ident ] + "end + "self.[ Export.ident ] = [ ruby_number(Export.number) ]; + " + } + case ['fallthrough' ';'] + { + # Nothing needed here. + } + case [Index: index_stmt] + { + send Parser + "[Index.ident]" + + if match Index.opt_init [E: `= expr] { + send Parser + [E expr(Index.opt_init.expr)] + } + else { + send Parser + "= 0 + } + + send Parser "; + } + case [case_block] + { + send Parser + "end + "when [expr( Stmt.case_block.expr )] then + "begin + "[stmt_list( Stmt.case_block._repeat_stmt )] + } + case [default_block] + { + send Parser + "end + "else + "begin + "[stmt_list( Stmt.default_block._repeat_stmt )] + } + case [goto_label] {} + case [goto_stmt] {} + case [AS: assign_stmt] + { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + case [continue_stmt] + { + send Parser + "next; + } + default { + # catches unspecified cases + send Parser [Stmt] + } +} + +void stmt_list( StmtList: stmt* ) +{ + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) +} + +void ruby_trans( Output: stream, Start: start ) +{ + Parser = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + RO: ruby_out::ruby_out = Parser->finish() + + if RO { + send Output + [RO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } +} + +void trans( Output: stream, Start: start ) +{ + ruby_trans( Output, Start ) +} + +include 'rlhc-main.lm' diff --git a/ragel/rlhc-rust.lm b/ragel/rlhc-rust.lm new file mode 100644 index 00000000..57cd66e1 --- /dev/null +++ b/ragel/rlhc-rust.lm @@ -0,0 +1,522 @@ +include 'ril.lm' + +namespace rust_out + token _IN_ /''/ + token _EX_ /''/ + + lex + token comment / + '//' any* :> '\n' | + '/*' any* :>> '*/' + / + + token id + /[a-zA-Z_][a-zA-Z_0-9]*/ + + token number / + [0-9]+ + / + + token symbol / + '!' | '#' | '$' | '%' | '&' | '(' | ')' | '*' | + '+' | ',' | '-' | '.' | '/' | ':' | ';' | '<' | + '=' | '>' | '?' | '@' | '[' | ']' | '^' | '|' | + '~' / + + literal `{ `} + + token lifetime / "'" id / + + token string / + '"' ( [^"\\] | '\\' any ) * '"' | + "'" ( [^'\\] | '\\' any ) * "'" + / + + ignore + /[ \t\v\r\n]+/ + end + + def item + [comment] + | [id] + | [number] + | [symbol] + | [string] + | [lifetime] + | [`{ _IN_ item* _EX_ `} ] + + def rust_out + [_IN_ _EX_ item*] +end + +namespace rust_gen + + global Parser: parser + + void tok_list( TL: host::tok* ) + { + for Tok: host::tok in repeat(TL) { + switch Tok + case [host::`${ StmtList: stmt* host::`}$] + send Parser "{[stmt_list( StmtList )]}" + case [host::`={ Expr: expr host::`}=] + send Parser "([expr( Expr )])" + case [E: escape] { + Str: str = $E + send Parser + "[Str.suffix( 1 )]" + } + default + send Parser [Tok] + } + } + + void embedded_host( EmbeddedHost: embedded_host ) + { + switch EmbeddedHost + case [`host `( string `, uint `) `={ TL: host::tok* host::`}=] + { + send Parser + "([tok_list( TL )])" + } + case [`host `( string `, uint `) `${ TL: host::tok* host::`}$] + { + send Parser + "{[tok_list( TL )]} + } + case [`host `( string `, uint `) `@{ TL: host::tok* host::`}@] + { + send Parser + [tok_list( TL )] + } + } + + void expr_factor( ExprFactor: expr_factor ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [O:`( TL: expr C: `)] + { + send Parser + [O expr(TL) C] + } + case [I: ident `[ E: expr `]] + { + send Parser + "[I]\[([expr( E )]) as usize\]" + } + case ['offset' '(' ident ',' expr ')'] + { + send Parser + "( [expr( ExprFactor.expr )] ) as i32" + } + case ['deref' '(' I: ident ',' E: expr ')'] + { + send Parser + "[I]\[([expr( E )]) as usize\] + } + case [T: `TRUE] + { + T.data = 'true' + send Parser [T] + } + case [F: `FALSE] + { + F.data = 'false' + send Parser [F] + } + case [N: `nil] + { + N.data = '0' + send Parser [N] + } + case [Number: number] + { + number( Number ) + } + case [E1: embedded_host `-> E2: expr_factor] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + expr_factor( E2 ) + } + case [`cast `( T: type `) E: expr_factor] + { + send Parser + "( [expr_factor( E )] ) as [type(T)]" + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' expr(E) ' as usize]'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void lvalue( ExprFactor: lvalue ) + { + switch ExprFactor + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [I: ident O: `[ E: expr C: `]] + { + send Parser + "[I]\[([expr( E )]) as usize\] + } + case [E1: embedded_host `-> E2: lvalue] + { + # The accessor operator is contained wihtin the lhs. + embedded_host( E1 ) + lvalue( E2 ) + } + case [I: ident `[ E: expr `] `. F: ident] { + send Parser + [^I '_' ^F '[' expr(E) ' as usize]'] + } + default { + # Catches cases not specified + send Parser [ExprFactor] + } + } + + void expr_factor_op( ExprFactorOp: expr_factor_op ) + { + switch ExprFactorOp + case [B: `! expr_factor_op] + { + send Parser [B] + expr_factor_op( ExprFactorOp._expr_factor_op ) + } + case [`~ EFO: expr_factor_op] + { + send Parser + "![expr_factor_op( EFO )] + } + case [expr_factor] + { + expr_factor( ExprFactorOp.expr_factor ) + } + } + + void expr_bitwise( ExprBitwise: expr_bitwise ) + { + switch ExprBitwise + case [expr_bitwise A: `& expr_factor_op] + { + expr_bitwise( ExprBitwise._expr_bitwise ) + send Parser [A] + expr_factor_op( ExprBitwise.expr_factor_op ) + } + case [expr_factor_op] + { + expr_factor_op( ExprBitwise.expr_factor_op ) + } + } + + void expr_mult( ExprMult: expr_mult ) + { + switch ExprMult + case [expr_mult T: `* expr_bitwise] + { + expr_mult( ExprMult._expr_mult ) + send Parser [T] + expr_bitwise( ExprMult.expr_bitwise ) + } + case [expr_bitwise] + { + expr_bitwise( ExprMult.expr_bitwise ) + } + } + + void expr_add( ExprAdd: expr_add ) + { + switch ExprAdd + case [expr_add Op: add_op expr_mult] + { + expr_add( ExprAdd._expr_add ) + send Parser [Op] + expr_mult( ExprAdd.expr_mult ) + } + case [expr_mult] + { + expr_mult( ExprAdd.expr_mult ) + } + } + + void expr_shift( ExprShift: expr_shift ) + { + switch ExprShift + case [expr_shift Op: shift_op expr_add] + { + expr_shift( ExprShift._expr_shift ) + send Parser [Op] + expr_add( ExprShift.expr_add ) + } + case [expr_add] + { + expr_add( ExprShift.expr_add ) + } + } + + void expr_test( ExprTest: expr_test ) + { + switch ExprTest + case [expr_test Op: test_op expr_shift] + { + expr_test( ExprTest._expr_test ) + send Parser [Op] + expr_shift( ExprTest.expr_shift ) + } + case [expr_shift] + { + expr_shift( ExprTest.expr_shift ) + } + } + + void expr( Expr: expr ) + { + expr_test( Expr.expr_test ) + } + + void type( Type: type ) + { + switch Type + case "s8" + send Parser ['i8 '] + case "s16" + send Parser ['i16 '] + case "s32" + send Parser ['i32 '] + case "s64" + send Parser ['i64 '] + case "s128" + send Parser ['i128'] + case "int" + send Parser ['i32'] + case "uint" + send Parser ['u32'] + default + send Parser [Type] + } + + void number( Number: number ) + { + switch Number + case [`u `( uint `) ] + send Parser "[Number.uint]u" + default + send Parser [Number] + } + + void num_list( NumList: num_list ) + { + for Number: number in NumList + send Parser "[number( Number )], " + send Parser "0" + } + + void stmt( Stmt: stmt ) + { + switch Stmt + case [EH: embedded_host] + { + send Parser + [embedded_host( EH )] + } + case [A: static_array] { + Length: int = 1 + for Number: number in A.num_list + Length = Length + 1 + + send Parser + "static [A.ident]: \[[type(A.type)]; [Length]\] = \[ [num_list(A.num_list)] \]; + } + case [V: static_value] { + send Parser + "static [V.ident]: i32 = [V.number]; + } + case [D: declaration] { + send Parser + "let mut [D.ident] " + + switch D.opt_init + case [E: `= expr] { + send Parser + "= [expr(D.opt_init.expr)]; + } + default { + send Parser + "= 0; + } + } + case [Index: index_stmt] + { + send Parser + "let mut [Index.ident] :i32" + + switch Index.opt_init + case [E: `= expr] { + send Parser + "= [expr(Index.opt_init.expr)]; + } + default { + send Parser + "= 0; + } + } + case [ + 'if' `( IfExpr: expr `) IfStmt: stmt + ElseIfClauseList: else_if_clause* ElseClauseOpt: else_clause? + ] { + send Parser + "if ( [expr(IfExpr)] ) { + " [stmt(IfStmt)] + "} + + for ElseIfClause: else_if_clause in repeat( ElseIfClauseList ) { + match ElseIfClause + ['else if (' ElseIfExpr: expr ')' ElseIfStmt: stmt] + + send Parser + "else if ( [expr(ElseIfExpr)] ) { + " [stmt(ElseIfStmt)] + "} + } + + if ( match ElseClauseOpt ['else' ElseStmt: stmt] ) { + send Parser + "else { + " [stmt(ElseStmt)] + "} + } + } + case ['while' '(' WhileExpr: expr ')' WhileStmt: stmt] { + send Parser + "while ( [expr(WhileExpr)] ) + " [stmt(WhileStmt)] + } + case [`switch `( SwitchExpr: expr `) `{ StmtList: stmt* `}] { + send Parser + "match ( [expr(SwitchExpr)] ) { + " [stmt_list(StmtList)] + + NeedDef: bool = true + for Stmt: stmt in repeat(StmtList) { + if match Stmt [default_block] + NeedDef = false + } + + if NeedDef { + send Parser + " _ => {} + } + + send Parser + "} + } + case [ExprExpr: expr Semi: `;] { + send Parser + [expr(ExprExpr) Semi] + } + case [L: `{ TL: stmt* R: `}] { + send Parser + [L stmt_list(TL) R] + } + case [ + TypeList: opt_const Type: type + Ident: ident OptInit: opt_init Semi: `; + ] + { + send Parser + [TypeList type(Type) Ident] + + if match OptInit [E: `= expr] { + send Parser + [E expr(OptInit.expr)] + } + + send Parser + [Semi] + } + case [Export: export_stmt] + { + send Parser + "#define [Export.ident] [number(Export.number)] + } + case ['fallthrough' ';'] + { + # Nothing needed here. + } + case [case_block] + { + send Parser + "[expr( Stmt.case_block.expr )] => { + "[stmt_list( Stmt.case_block._repeat_stmt )] + "} + } + case [default_block] + { + send Parser + "_ => { + "[stmt_list( Stmt.default_block._repeat_stmt )] + "} + } + case [case_label] + { + send Parser + "case [expr( Stmt.case_label.expr )]: + } + case [AS: assign_stmt] + { + send Parser + "[lvalue(AS.LValue) AS.assign_op expr(AS.expr)]; + } + default { + # catches unspecified cases + send Parser [Stmt] + } + } + + void stmt_list( StmtList: stmt* ) + { + for Stmt: stmt in repeat( StmtList ) + stmt( Stmt ) + } + + void trans( Output: stream, Start: start ) + { + Parser = new parser() + + if ( Start.opt_bom.bom ) + send Output [Start.opt_bom.bom] + + stmt_list( Start._repeat_stmt ) + + CO: rust_out::rust_out = Parser->finish() + + if CO { + send Output + [CO] + } + else { + send stderr + "failed to parse output: [Parser->error] + } + } +end + +void trans( Output: stream, Start: start ) +{ + rust_gen::trans( Output, Start ) +} + +include 'rlhc-main.lm' -- cgit v1.2.1