diff --git a/example/main/README.md b/example/main/README.md index 1bbe7df..5d3aec0 100644 --- a/example/main/README.md +++ b/example/main/README.md @@ -1,2 +1,3 @@ # Reason + This is not a cargo example, as its needs a full build.rs step. diff --git a/example/main/c/main.c b/example/main/c/main.c index bf6ee53..e820cf7 100644 --- a/example/main/c/main.c +++ b/example/main/c/main.c @@ -1,23 +1,23 @@ /* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ + * Copyright (C) 2023 - 2024: + * The Trinitrix Project + * + * This file is part of the Trixy crate for Trinitrix. + * + * Trixy is free software: you can redistribute it and/or modify + * it under the terms of the Lesser GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * and the Lesser GNU General Public License along with this program. + * If not, see . + */ #include "../dist/interface.h" #include @@ -25,45 +25,49 @@ #include #include -#define println(args...) \ - printf("(plugin): "); \ - printf(args); \ - printf("\n"); \ - fflush(stdout); -#define eprintln(args...) \ - printf("(plugin): "); \ - printf(args); \ - printf("\n"); \ - fflush(stdout); +#define println(args...) \ + printf ("(plugin): "); \ + printf (args); \ + printf ("\n"); \ + fflush (stdout); +#define eprintln(args...) \ + printf ("(plugin): "); \ + printf (args); \ + printf ("\n"); \ + fflush (stdout); -int p_main() { +int +p_main () +{ // You can simply call functions .. - outstanding("James"); + outstanding ("James"); // .. but they check their inputs: // This call for example will fail, as a null pointer isn't supported. // - // A error will be signaled by a 0 return code, then the error can be obtained - // with the `last_error_length` and `last_error_message` functions - if (!outstanding(0x0)) { - int error_length = last_error_length(); - char *error = malloc(error_length); - last_error_message(error, error_length); - eprintln("Encountered error: %s", error); - free(error); - } + // A error will be signaled by a 0 return code, then the error can be + // obtained with the `last_error_length` and `last_error_message` functions + if (!outstanding (0x0)) + { + int error_length = last_error_length (); + char *error = malloc (error_length); + last_error_message (error, error_length); + eprintln ("Encountered error: %s", error); + free (error); + } - println("Saying hi!"); + println ("Saying hi!"); string_t hi; - if (!one.hi(&hi, "Adam")) { - int error_length = last_error_length(); - char *error = malloc(error_length); - last_error_message(error, error_length); - eprintln("Encountered error: %s", error); - free(error); - } - println("Rust returned: %s", hi); - string_free(hi); + if (!one.hi (&hi, "Adam")) + { + int error_length = last_error_length (); + char *error = malloc (error_length); + last_error_message (error, error_length); + eprintln ("Encountered error: %s", error); + free (error); + } + println ("Rust returned: %s", hi); + string_free (hi); return 0; } diff --git a/example/main/src/bin/main/api.tri b/example/main/src/bin/main/api.tri index 5e000fc..981bc02 100644 --- a/example/main/src/bin/main/api.tri +++ b/example/main/src/bin/main/api.tri @@ -22,7 +22,6 @@ /// Call out an outstanding person fn outstanding(name: String); - mod one { /// Say hi to a name fn hi(name: String) -> String; diff --git a/trixy-macros/src/generate.old/command_enum/mod.rs b/trixy-macros/src/generate.old/command_enum/mod.rs index f6731fd..49aaf2f 100644 --- a/trixy-macros/src/generate.old/command_enum/mod.rs +++ b/trixy-macros/src/generate.old/command_enum/mod.rs @@ -19,14 +19,12 @@ * If not, see . */ - - use convert_case::{Case, Casing}; use proc_macro2::TokenStream as TokenStream2; use quote::{format_ident, quote, ToTokens}; use syn::{punctuated::Punctuated, Ident, Token, Type}; -use crate::{DataCommandEnum, command_enum_parsing::Field}; +use crate::{command_enum_parsing::Field, DataCommandEnum}; use super::get_input_type_of_bare_fn_field; diff --git a/trixy-macros/src/generate.old/lua_wrapper/lua_functions_to_globals/mod.rs b/trixy-macros/src/generate.old/lua_wrapper/lua_functions_to_globals/mod.rs index 951ace9..71c9dd3 100644 --- a/trixy-macros/src/generate.old/lua_wrapper/lua_functions_to_globals/mod.rs +++ b/trixy-macros/src/generate.old/lua_wrapper/lua_functions_to_globals/mod.rs @@ -19,14 +19,12 @@ * If not, see . */ - - use proc_macro2::TokenStream as TokenStream2; use quote::{format_ident, quote}; use syn::{punctuated::Punctuated, Token}; use crate::{ - command_enum_parsing::{Field, NamespacePath, FunctionDeclaration}, + command_enum_parsing::{Field, FunctionDeclaration, NamespacePath}, DataCommandEnum, }; diff --git a/trixy-macros/src/generate.old/lua_wrapper/mod.rs b/trixy-macros/src/generate.old/lua_wrapper/mod.rs index 272b9e5..e08fa2f 100644 --- a/trixy-macros/src/generate.old/lua_wrapper/mod.rs +++ b/trixy-macros/src/generate.old/lua_wrapper/mod.rs @@ -19,8 +19,6 @@ * If not, see . */ - - use proc_macro2::TokenStream as TokenStream2; use quote::quote; diff --git a/trixy-macros/src/generate.old/lua_wrapper/rust_wrapper_functions/mod.rs b/trixy-macros/src/generate.old/lua_wrapper/rust_wrapper_functions/mod.rs index b22ccb8..fc39118 100644 --- a/trixy-macros/src/generate.old/lua_wrapper/rust_wrapper_functions/mod.rs +++ b/trixy-macros/src/generate.old/lua_wrapper/rust_wrapper_functions/mod.rs @@ -19,8 +19,6 @@ * If not, see . */ - - use convert_case::{Case, Casing}; use proc_macro2::TokenStream as TokenStream2; use quote::quote; diff --git a/trixy-macros/src/generate.old/mod.rs b/trixy-macros/src/generate.old/mod.rs index 8c0f88f..bbd5af8 100644 --- a/trixy-macros/src/generate.old/mod.rs +++ b/trixy-macros/src/generate.old/mod.rs @@ -19,8 +19,6 @@ * If not, see . */ - - mod command_enum; mod lua_wrapper; diff --git a/trixy-parser/README.md b/trixy-parser/README.md index e48f30f..9d8c341 100644 --- a/trixy-parser/README.md +++ b/trixy-parser/README.md @@ -1,10 +1,13 @@ # trixy-lang_parser + This crate contains a parser (and lexer) for the Trixy language. The corresponding grammar is in the grammar file [here](./docs/grammar.ebnf) encoded in [Extended Backus-Naur Form](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form). ## Testing + A binary (`trixy-parser`) exists, which provides easy access to the different library parsing steps ## Docs + Run `./generate_docs` to turn the grammar file into railroad diagrams. diff --git a/trixy-parser/example/comments.tri b/trixy-parser/example/comments.tri index 401328f..b99a2af 100644 --- a/trixy-parser/example/comments.tri +++ b/trixy-parser/example/comments.tri @@ -19,17 +19,14 @@ * If not, see . */ - - fn print(message: String); /// First doc comment // Some more text -nasp trinitrix { +mod trinitrix { /// Second doc comment fn hi(name: String) -> String; } - // That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: // vim: syntax=rust diff --git a/trixy-parser/example/empty.tri b/trixy-parser/example/empty.tri index 0429522..1776d65 100644 --- a/trixy-parser/example/empty.tri +++ b/trixy-parser/example/empty.tri @@ -19,12 +19,8 @@ * If not, see . */ - - - - // an empty comment: // // an empty doc comment: /// -nasp test {} +mod test {} diff --git a/trixy-parser/example/failing.tri b/trixy-parser/example/failing.tri deleted file mode 100644 index 6bdb8d4..0000000 --- a/trixy-parser/example/failing.tri +++ /dev/null @@ -1,32 +0,0 @@ -/* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ - - - -fn print(message: CommandTransferValue); - -nasp trinitrix { {} - fn hi honner(name: String) -> String; ; -} - - -// That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: -// vim: syntax=rust diff --git a/trixy-parser/example/failing_comments.tri b/trixy-parser/example/failing_comments.tri deleted file mode 100644 index d75ba0f..0000000 --- a/trixy-parser/example/failing_comments.tri +++ /dev/null @@ -1,36 +0,0 @@ -/* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ - - - -fn print(message: CommandTransferValue); - -/// Some doc comment -// Some more text -nasp trinitrix { - fn hi(name: String) -> String; -} - -/// Trailing doc comment (I will fail) - - -// That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: -// vim: syntax=rust diff --git a/trixy-parser/example/failing_enum_name.tri b/trixy-parser/example/failing_enum_name.tri index d655b25..15b3909 100644 --- a/trixy-parser/example/failing_enum_name.tri +++ b/trixy-parser/example/failing_enum_name.tri @@ -19,20 +19,17 @@ * If not, see . */ - - -nasp trinitrix { +mod trinitrix { /// This enum can't be called Trinitrix, as that's already the name of the namespace /// (if it's in Pascal case) enum Trinitrix { High, Medium, Low, - }; + } fn execute_callback(priority: Trinitrix); } - // That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: // vim: syntax=rust diff --git a/trixy-parser/example/failing_types.tri b/trixy-parser/example/failing_types.tri index 7f4645e..a4c5ca2 100644 --- a/trixy-parser/example/failing_types.tri +++ b/trixy-parser/example/failing_types.tri @@ -19,15 +19,12 @@ * If not, see . */ - - struct Callback { func: Function, timeout: Integer, -}; +} fn execute_callback(callback: Name); - // That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: // vim: syntax=rust diff --git a/trixy-parser/example/failing_types_generic.tri b/trixy-parser/example/failing_types_generic.tri index 73b58bf..7e7d1c4 100644 --- a/trixy-parser/example/failing_types_generic.tri +++ b/trixy-parser/example/failing_types_generic.tri @@ -19,14 +19,12 @@ * If not, see . */ +struct A {} +struct B {} -struct A {}; -struct B {}; - -enum Error {}; +enum Error {} fn execute_callback(callback: String) -> Error; - // That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: // vim: syntax=rust diff --git a/trixy-parser/example/full.tri b/trixy-parser/example/full.tri index 8329e62..ee30e2f 100644 --- a/trixy-parser/example/full.tri +++ b/trixy-parser/example/full.tri @@ -19,34 +19,32 @@ * If not, see . */ - - /// Prints to the output, with a newline. // HACK(@soispha): The stdlib Lua `print()` function has stdout as output hardcoded, // redirecting stdout seems too much like a hack thus we are just redefining the print function // to output to a controlled output. <2023-09-09> //fn print(input: CommandTransferValue); -nasp trinitrix { +mod trinitrix { /// Language specific functions, which mirror the `trinitrix.api` namespace. /// That is, if you have to choose between a `std` and a `api` function choose the `std` /// one as it will most likely be more high-level and easier to use (as it isn't abstracted /// over multiple languages). Feel free to drop down to the lower level api, if you feel /// like that more, it should be as stable and user-oriented as the `std` functions - nasp std {} + mod std {} /// Debug only functions, these are effectively useless - nasp debug { + mod debug { enum UserGreet { Friendly, Angrily, - Hastly - }; + Hastly, + } struct GreetedUser { names: Vec, new: GreetedUser, - state: UserGreet - }; + state: UserGreet, + } /// Greets the user fn greet(input: String) -> String; @@ -55,7 +53,7 @@ nasp trinitrix { } /// General API to change stuff in Trinitrix - nasp api { + mod api { /// Closes the application fn exit(); @@ -73,7 +71,7 @@ nasp trinitrix { /* fn register_function(function: RawFunction); */ /// Function that change the UI, or UI state - nasp ui { + mod ui { /// Shows the command line fn command_line_show(); @@ -118,7 +116,7 @@ nasp trinitrix { /// The callback MUST be registered first by calling /// `trinitrix.api.register_function()` the returned value can than be used to /// set the keymap. - nasp keymaps { + mod keymaps { /// Add a new keymapping fn add(mode: String, key: String, callback: Function); @@ -132,7 +130,7 @@ nasp trinitrix { } /// Functions only used internally within Trinitrix - nasp raw { + mod raw { /// Send an error to the default error output fn raise_error(input: String); @@ -150,7 +148,7 @@ nasp trinitrix { /// ensuring memory locations stay allocated in garbage collected language is hard) /// /// Treat it as an implementation detail - nasp __private {} + mod __private {} } } } diff --git a/trixy-parser/example/multiple.tri b/trixy-parser/example/multiple.tri index 010a5b2..ff59b64 100644 --- a/trixy-parser/example/multiple.tri +++ b/trixy-parser/example/multiple.tri @@ -19,18 +19,15 @@ * If not, see . */ - - fn print(message: CommandTransferValue); -nasp trinitrix { +mod trinitrix { fn hi(name: String) -> String; } -nasp trinitrix { +mod trinitrix { fn ho(name: String, name2: String) -> String; } - // That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: // vim: syntax=rust diff --git a/trixy-parser/example/other_comments.tri b/trixy-parser/example/other_comments.tri index 4662cdc..8454713 100644 --- a/trixy-parser/example/other_comments.tri +++ b/trixy-parser/example/other_comments.tri @@ -19,8 +19,6 @@ * If not, see . */ - - /// other doc comment fn hi(name: String) -> String; @@ -29,13 +27,12 @@ struct ho { ident: String, /// also a doc comment codebase: Vec, -}; +} /// Some doc comment -nasp trinitrix { +mod trinitrix { fn hi(name: String) -> String; } - // That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: // vim: syntax=rust diff --git a/trixy-parser/example/simple.tri b/trixy-parser/example/simple.tri index 2cd3598..eff99fe 100644 --- a/trixy-parser/example/simple.tri +++ b/trixy-parser/example/simple.tri @@ -19,14 +19,11 @@ * If not, see . */ - - fn print(message: CommandTransferValue); -nasp trinitrix { +mod trinitrix { fn hi(name: String) -> String; } - // That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: // vim: syntax=rust diff --git a/trixy-parser/example/types.tri b/trixy-parser/example/types.tri index a0bcc0f..1a135c5 100644 --- a/trixy-parser/example/types.tri +++ b/trixy-parser/example/types.tri @@ -19,23 +19,20 @@ * If not, see . */ - - -nasp trinitrix { +mod trinitrix { struct Callback { func: Function, timeout: Integer, - }; + } enum CallbackPriority { High, Medium, Low, - }; + } fn execute_callback(callback: Callback, priority: CallbackPriority); } - // That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing: // vim: syntax=rust diff --git a/trixy-types/src/c_headers/errno.h b/trixy-types/src/c_headers/errno.h index de21abf..d70a75e 100644 --- a/trixy-types/src/c_headers/errno.h +++ b/trixy-types/src/c_headers/errno.h @@ -1,23 +1,23 @@ /* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ + * Copyright (C) 2023 - 2024: + * The Trinitrix Project + * + * This file is part of the Trixy crate for Trinitrix. + * + * Trixy is free software: you can redistribute it and/or modify + * it under the terms of the Lesser GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * and the Lesser GNU General Public License along with this program. + * If not, see . + */ #ifndef TRIXY_ERRNO_H #define TRIXY_ERRNO_H @@ -26,10 +26,10 @@ /** Calculate the number of bytes in the last error's error message **not** * including any trailing `null` characters. */ -extern int last_error_length(); +extern int last_error_length (); -/** Write the most recent error message into a caller-provided buffer as a UTF-8 - * string, returning the number of bytes written. +/** Write the most recent error message into a caller-provided buffer as a + * UTF-8 string, returning the number of bytes written. * * # Note * @@ -40,6 +40,6 @@ extern int last_error_length(); * bytes). `-1` is returned if there are any errors, for example when passed a * null pointer or a buffer of insufficient size. */ -extern int last_error_message(char *buffer, uint64_t length); +extern int last_error_message (char *buffer, uint64_t length); #endif // TRIXY_ERRNO_H diff --git a/trixy-types/src/c_headers/string.h b/trixy-types/src/c_headers/string.h index df0d2fc..1b22c4e 100644 --- a/trixy-types/src/c_headers/string.h +++ b/trixy-types/src/c_headers/string.h @@ -1,30 +1,30 @@ /* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ + * Copyright (C) 2023 - 2024: + * The Trinitrix Project + * + * This file is part of the Trixy crate for Trinitrix. + * + * Trixy is free software: you can redistribute it and/or modify + * it under the terms of the Lesser GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * and the Lesser GNU General Public License along with this program. + * If not, see . + */ #ifndef TRIXY_STRING_H #define TRIXY_STRING_H /** - * @brief This string type is allocated by rust, which means that you can't just - * free it from c, but need to return it to rust to be freed. + * @brief This string type is allocated by rust, which means that you can't + * just free it from c, but need to return it to rust to be freed. * @see the `string_free` method */ typedef const char *string_t; @@ -32,6 +32,6 @@ typedef const char *string_t; /** * @brief The free function for rust stings */ -extern int string_free(string_t string); +extern int string_free (string_t string); #endif // TRIXY_STRING_H diff --git a/trixy-types/src/c_headers/vec.h b/trixy-types/src/c_headers/vec.h index 8f6b3c9..c7ba42a 100644 --- a/trixy-types/src/c_headers/vec.h +++ b/trixy-types/src/c_headers/vec.h @@ -1,23 +1,23 @@ /* -* Copyright (C) 2023 - 2024: -* The Trinitrix Project -* -* This file is part of the Trixy crate for Trinitrix. -* -* Trixy is free software: you can redistribute it and/or modify -* it under the terms of the Lesser GNU General Public License as -* published by the Free Software Foundation, either version 3 of -* the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* and the Lesser GNU General Public License along with this program. -* If not, see . -*/ + * Copyright (C) 2023 - 2024: + * The Trinitrix Project + * + * This file is part of the Trixy crate for Trinitrix. + * + * Trixy is free software: you can redistribute it and/or modify + * it under the terms of the Lesser GNU General Public License as + * published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * and the Lesser GNU General Public License along with this program. + * If not, see . + */ #ifndef TRIXY_VEC_H #define TRIXY_VEC_H @@ -30,11 +30,12 @@ * You are must not free it by calling c's `free`. Use `vec_free` * instead. */ -struct vec { +struct vec +{ void *data; size_t length; }; -extern int vec_free(struct vec vector); +extern int vec_free (struct vec vector); #endif // TRIXY_VEC_H