Compare commits
No commits in common. "5ce46a1568acf1afdbee64c1970a0036c24bb4c7" and "03f8eda241f86cbd3f9d49ab0d20ce6e3b8dd6bd" have entirely different histories.
5ce46a1568
...
03f8eda241
|
@ -1,3 +1,2 @@
|
|||
# Reason
|
||||
|
||||
This is not a cargo example, as its needs a full build.rs step.
|
||||
|
|
|
@ -26,29 +26,26 @@
|
|||
#include <string.h>
|
||||
|
||||
#define println(args...) \
|
||||
printf ("\33[32;1m(plugin):\33[0m \33[34;1m"); \
|
||||
printf("[32;1m(plugin):[0m [34;1m"); \
|
||||
printf(args); \
|
||||
printf ("\n\33[0m"); \
|
||||
printf("\n[0m"); \
|
||||
fflush(stdout);
|
||||
#define eprintln(args...) \
|
||||
printf ("\33[32;1m(plugin):\33[0m\33[31;1m "); \
|
||||
printf("[32;1m(plugin):[0m[31;1m "); \
|
||||
printf(args); \
|
||||
printf ("\n\33[0m"); \
|
||||
printf("\n[0m"); \
|
||||
fflush(stdout);
|
||||
|
||||
int
|
||||
plugin_main ()
|
||||
{
|
||||
int p_main() {
|
||||
// You can simply call functions ..
|
||||
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 (NULL))
|
||||
{
|
||||
// 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);
|
||||
|
@ -58,8 +55,7 @@ plugin_main ()
|
|||
|
||||
println("Saying hi!");
|
||||
string_t hi;
|
||||
if (!one.hi (&hi, "Adam"))
|
||||
{
|
||||
if (!one.hi(&hi, "Adam")) {
|
||||
int error_length = last_error_length();
|
||||
char *error = malloc(error_length);
|
||||
last_error_message(error, error_length);
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
/// Call out an outstanding person
|
||||
fn outstanding(name: String);
|
||||
|
||||
|
||||
mod one {
|
||||
/// Say hi to a name
|
||||
fn hi(name: String) -> String;
|
||||
|
|
|
@ -49,11 +49,11 @@ fn handle_cmd(cmd: Commands) {
|
|||
fn main() {
|
||||
let library_path = env::args().nth(1).expect("USAGE: cargo r -- <LIB>");
|
||||
type AddFunc = unsafe fn() -> c_int;
|
||||
println!("Loading plugin_main() from {}", library_path);
|
||||
println!("Loading p_main() from {}", library_path);
|
||||
|
||||
unsafe {
|
||||
let lib = Library::new(library_path).unwrap();
|
||||
let func: Symbol<AddFunc> = lib.get(b"plugin_main").unwrap();
|
||||
let func: Symbol<AddFunc> = lib.get(b"p_main").unwrap();
|
||||
println!("starting plugin");
|
||||
let out = func();
|
||||
println!("plugin finished with: {}", out);
|
||||
|
|
23
flake.lock
23
flake.lock
|
@ -174,8 +174,7 @@
|
|||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay",
|
||||
"systems": "systems",
|
||||
"treefmt-nix": "treefmt-nix"
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
|
@ -248,26 +247,6 @@
|
|||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"treefmt-nix": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1708335038,
|
||||
"narHash": "sha256-ETLZNFBVCabo7lJrpjD6cAbnE11eDOjaQnznmg/6hAE=",
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"rev": "e504621290a1fd896631ddbc5e9c16f4366c9f65",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "treefmt-nix",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
|
|
44
flake.nix
44
flake.nix
|
@ -16,6 +16,7 @@
|
|||
# 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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
{
|
||||
description = "A rust crate used to generate multi-language apis for your
|
||||
application";
|
||||
|
@ -28,13 +29,6 @@
|
|||
flake = false;
|
||||
};
|
||||
|
||||
treefmt-nix = {
|
||||
url = "github:numtide/treefmt-nix";
|
||||
inputs = {
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
systems = {
|
||||
url = "github:nix-systems/default";
|
||||
};
|
||||
|
@ -70,13 +64,11 @@
|
|||
};
|
||||
};
|
||||
outputs = {
|
||||
self,
|
||||
nixpkgs,
|
||||
crane,
|
||||
flake-utils,
|
||||
rust-overlay,
|
||||
ebnf2pdf,
|
||||
treefmt-nix,
|
||||
...
|
||||
}:
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
|
@ -120,52 +112,18 @@
|
|||
doCheck = true;
|
||||
inherit nativeBuildInputs buildInputs;
|
||||
};
|
||||
treefmtEval = treefmt-nix.lib.evalModule pkgs (
|
||||
{pkgs, ...}: {
|
||||
# Used to find the project root
|
||||
projectRootFile = "flake.nix";
|
||||
|
||||
programs = {
|
||||
alejandra.enable = true;
|
||||
rustfmt.enable = true;
|
||||
clang-format.enable = true;
|
||||
mdformat.enable = true;
|
||||
shfmt = {
|
||||
enable = true;
|
||||
indent_size = 4;
|
||||
};
|
||||
shellcheck.enable = true;
|
||||
};
|
||||
|
||||
settings.formatter = {
|
||||
clang-format = {
|
||||
options = ["--style" "GNU"];
|
||||
};
|
||||
rustfmt = {
|
||||
# also add the Trixy files
|
||||
includes = ["*.tri"];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
in {
|
||||
checks.default = craneBuild;
|
||||
packages = {
|
||||
default = craneBuild;
|
||||
};
|
||||
|
||||
formatter = treefmtEval.config.build.wrapper;
|
||||
checks = {
|
||||
formatting = treefmtEval.config.build.check self;
|
||||
};
|
||||
|
||||
devShells.default = pkgs.mkShell {
|
||||
packages = with pkgs; [
|
||||
alejandra
|
||||
|
||||
cocogitto
|
||||
licensure
|
||||
treefmt
|
||||
|
||||
rust
|
||||
cargo-edit
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
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::{command_enum_parsing::Field, DataCommandEnum};
|
||||
use crate::{DataCommandEnum, command_enum_parsing::Field};
|
||||
|
||||
use super::get_input_type_of_bare_fn_field;
|
||||
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::{format_ident, quote};
|
||||
use syn::{punctuated::Punctuated, Token};
|
||||
|
||||
use crate::{
|
||||
command_enum_parsing::{Field, FunctionDeclaration, NamespacePath},
|
||||
command_enum_parsing::{Field, NamespacePath, FunctionDeclaration},
|
||||
DataCommandEnum,
|
||||
};
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
use convert_case::{Case, Casing};
|
||||
use proc_macro2::TokenStream as TokenStream2;
|
||||
use quote::quote;
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
mod command_enum;
|
||||
mod lua_wrapper;
|
||||
|
||||
|
|
|
@ -80,7 +80,6 @@ impl TrixyConfig {
|
|||
write!(c_header_out, "{}\n{}", c_header, VIM_LINE_C).expect("Write should work");
|
||||
|
||||
Command::new("clang-format")
|
||||
.args(["--style", "GNU"])
|
||||
.args(["-i", &c_header_path.to_str().unwrap()])
|
||||
.status()
|
||||
.unwrap_or_else(|err| {
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
# 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.
|
||||
|
|
|
@ -19,14 +19,17 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
fn print(message: String);
|
||||
|
||||
/// First doc comment
|
||||
// Some more text
|
||||
mod trinitrix {
|
||||
nasp 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
|
||||
|
|
|
@ -19,8 +19,12 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// an empty comment:
|
||||
//
|
||||
// an empty doc comment:
|
||||
///
|
||||
mod test {}
|
||||
nasp test {}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (C) 2023 - 2024:
|
||||
* The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
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
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (C) 2023 - 2024:
|
||||
* The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
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
|
|
@ -19,17 +19,20 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
mod trinitrix {
|
||||
|
||||
|
||||
nasp 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
|
||||
|
|
|
@ -19,12 +19,15 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
|
|
@ -19,12 +19,14 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
struct A {}
|
||||
struct B {}
|
||||
|
||||
enum Error {}
|
||||
struct A {};
|
||||
struct B {};
|
||||
|
||||
enum Error {};
|
||||
|
||||
fn execute_callback(callback: String<A, B>) -> Error<String, Error>;
|
||||
|
||||
|
||||
// That's a flat out lie, but it results in a rather nice syntax highlight compared to nothing:
|
||||
// vim: syntax=rust
|
||||
|
|
|
@ -19,32 +19,34 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/// 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);
|
||||
|
||||
mod trinitrix {
|
||||
nasp 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
|
||||
mod std {}
|
||||
nasp std {}
|
||||
|
||||
/// Debug only functions, these are effectively useless
|
||||
mod debug {
|
||||
nasp debug {
|
||||
enum UserGreet {
|
||||
Friendly,
|
||||
Angrily,
|
||||
Hastly,
|
||||
}
|
||||
Hastly
|
||||
};
|
||||
struct GreetedUser {
|
||||
names: Vec<String>,
|
||||
new: GreetedUser,
|
||||
state: UserGreet,
|
||||
}
|
||||
state: UserGreet
|
||||
};
|
||||
/// Greets the user
|
||||
fn greet(input: String) -> String;
|
||||
|
||||
|
@ -53,7 +55,7 @@ mod trinitrix {
|
|||
}
|
||||
|
||||
/// General API to change stuff in Trinitrix
|
||||
mod api {
|
||||
nasp api {
|
||||
/// Closes the application
|
||||
fn exit();
|
||||
|
||||
|
@ -71,7 +73,7 @@ mod trinitrix {
|
|||
/* fn register_function(function: RawFunction); */
|
||||
|
||||
/// Function that change the UI, or UI state
|
||||
mod ui {
|
||||
nasp ui {
|
||||
/// Shows the command line
|
||||
fn command_line_show();
|
||||
|
||||
|
@ -116,7 +118,7 @@ mod trinitrix {
|
|||
/// The callback MUST be registered first by calling
|
||||
/// `trinitrix.api.register_function()` the returned value can than be used to
|
||||
/// set the keymap.
|
||||
mod keymaps {
|
||||
nasp keymaps {
|
||||
/// Add a new keymapping
|
||||
fn add(mode: String, key: String, callback: Function);
|
||||
|
||||
|
@ -130,7 +132,7 @@ mod trinitrix {
|
|||
}
|
||||
|
||||
/// Functions only used internally within Trinitrix
|
||||
mod raw {
|
||||
nasp raw {
|
||||
/// Send an error to the default error output
|
||||
fn raise_error(input: String);
|
||||
|
||||
|
@ -148,7 +150,7 @@ mod trinitrix {
|
|||
/// ensuring memory locations stay allocated in garbage collected language is hard)
|
||||
///
|
||||
/// Treat it as an implementation detail
|
||||
mod __private {}
|
||||
nasp __private {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,15 +19,18 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
fn print(message: CommandTransferValue);
|
||||
|
||||
mod trinitrix {
|
||||
nasp trinitrix {
|
||||
fn hi(name: String) -> String;
|
||||
}
|
||||
|
||||
mod trinitrix {
|
||||
nasp 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
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/// other doc comment
|
||||
fn hi(name: String) -> String;
|
||||
|
||||
|
@ -27,12 +29,13 @@ struct ho {
|
|||
ident: String,
|
||||
/// also a doc comment
|
||||
codebase: Vec<String>,
|
||||
}
|
||||
};
|
||||
|
||||
/// Some doc comment
|
||||
mod trinitrix {
|
||||
nasp 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
|
||||
|
|
|
@ -19,11 +19,14 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
fn print(message: CommandTransferValue);
|
||||
|
||||
mod trinitrix {
|
||||
nasp 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
|
||||
|
|
|
@ -19,20 +19,23 @@
|
|||
* If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
mod trinitrix {
|
||||
|
||||
|
||||
nasp 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
|
||||
|
|
|
@ -28,8 +28,8 @@
|
|||
*/
|
||||
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
|
||||
*
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
#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;
|
||||
|
|
|
@ -30,8 +30,7 @@
|
|||
* You are must not free it by calling c's `free`. Use `vec_free`
|
||||
* instead.
|
||||
*/
|
||||
struct vec
|
||||
{
|
||||
struct vec {
|
||||
void *data;
|
||||
size_t length;
|
||||
};
|
||||
|
|
Reference in New Issue