diff --git a/README.md b/README.md index 3c053db..862e53b 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ Borrowing from that: 'the place where http lives'. - collection literals - ease of use for CRUD operations, like automatic mapping from sql rows to json - Urls are made up of directories. -- A controller sourcefile is a file named web.crud +- A controller sourcefile is a file named web.tp - likewise: - - service.crud for services - - db.crud database access code - - util.crud utilities + - service.tp for services + - db.tp database access code + - util.tp utilities - it is not mandatory to have services. If you want, you can put all your logic in a controller. - and it can only access functions in its own subtree. Generic code should be put higher up in the tree. - Therefore, services cannot call other services, because that is the recipe for spaghetti. Refactor your logic, abstract and put lower level code in utilities. diff --git a/examples/api/customer/db.crud b/examples/api/customer/db.tp similarity index 100% rename from examples/api/customer/db.crud rename to examples/api/customer/db.tp diff --git a/examples/api/customer/service.crud b/examples/api/customer/service.tp similarity index 100% rename from examples/api/customer/service.crud rename to examples/api/customer/service.tp diff --git a/examples/api/customer/web.crud b/examples/api/customer/web.tp similarity index 100% rename from examples/api/customer/web.crud rename to examples/api/customer/web.tp diff --git a/examples/model/customers b/examples/model/customers.tp similarity index 100% rename from examples/model/customers rename to examples/model/customers.tp diff --git a/source/hello/service.crud b/source/hello/service.tp similarity index 100% rename from source/hello/service.crud rename to source/hello/service.tp diff --git a/source/hello/web.crud b/source/hello/web.tp similarity index 100% rename from source/hello/web.crud rename to source/hello/web.tp diff --git a/src/compiler/compiler_tests.rs b/src/compiler/compiler_tests.rs index 7865b70..56f4c37 100644 --- a/src/compiler/compiler_tests.rs +++ b/src/compiler/compiler_tests.rs @@ -2,7 +2,7 @@ mod tests { use crate::errors::CompilerError::IllegalArgumentsException; use crate::errors::CompilerErrorAtLine; - use crate::errors::CrudLangError::{Compiler, Runtime}; + use crate::errors::TipiLangError::{Compiler, Runtime}; use crate::errors::RuntimeError::{IllegalArgumentException, IndexOutOfBounds}; use crate::value::{Value, string}; use chrono::DateTime; diff --git a/src/compiler/mod.rs b/src/compiler/mod.rs index f8c0387..bc6543b 100644 --- a/src/compiler/mod.rs +++ b/src/compiler/mod.rs @@ -1,10 +1,10 @@ use std::collections::HashMap; use std::fs; use walkdir::WalkDir; -use crate::{compiler, symbol_builder, AsmRegistry}; +use crate::{compiler, symbol_builder, AsmRegistry, TIPI_EXT}; use crate::compiler::asm_pass::AsmChunk; -use crate::errors::CrudLangError; -use crate::errors::CrudLangError::Platform; +use crate::errors::TipiLangError; +use crate::errors::TipiLangError::Platform; mod compiler_tests; pub mod scan_pass; @@ -12,19 +12,19 @@ pub mod ast_pass; pub mod tokens; pub mod asm_pass; -pub fn compile_sourcedir(source_dir: &str) -> Result, CrudLangError> { +pub fn compile_sourcedir(source_dir: &str) -> Result, TipiLangError> { let mut asm_registry = AsmRegistry::new(); for entry in WalkDir::new(source_dir).into_iter().filter_map(|e| e.ok()) { let path = entry.path().to_str().unwrap(); - if path.ends_with(".crud") { + if path.ends_with(TIPI_EXT) { print!("-- Compiling {} -- ", path); let source = fs::read_to_string(path).map_err(map_underlying())?; let tokens = scan_pass::scan(&source)?; let mut symbol_table = HashMap::new(); match ast_pass::compile(Some(path), tokens, &mut symbol_table) { Ok(statements) => { - let path = path.strip_prefix(source_dir).unwrap().replace(".crud", ""); + let path = path.strip_prefix(source_dir).unwrap().replace(TIPI_EXT, ""); symbol_builder::build(&path, &statements, &mut symbol_table); asm_pass::compile(Some(&path), &statements, &symbol_table, &mut asm_registry)?; @@ -40,12 +40,12 @@ pub fn compile_sourcedir(source_dir: &str) -> Result, Ok(asm_registry) } -pub fn map_underlying() -> fn(std::io::Error) -> CrudLangError { +pub fn map_underlying() -> fn(std::io::Error) -> TipiLangError { |e| Platform(e.to_string()) } -pub fn compile(src: &str) -> Result, CrudLangError> { +pub fn compile(src: &str) -> Result, TipiLangError> { let tokens = compiler::scan_pass::scan(src)?; let mut asm_registry = HashMap::new(); let mut symbol_table = HashMap::new(); @@ -56,7 +56,7 @@ pub fn compile(src: &str) -> Result, CrudLangError> { } #[cfg(test)] -pub(crate) fn run(src: &str) -> Result { +pub(crate) fn run(src: &str) -> Result { let tokens = compiler::scan_pass::scan(src)?; let mut symbol_table = HashMap::new(); let ast = compiler::ast_pass::compile(None, tokens, &mut symbol_table)?; @@ -64,5 +64,5 @@ pub(crate) fn run(src: &str) -> Result { let mut asm_registry = HashMap::new(); asm_pass::compile(None, &ast, &symbol_table, &mut asm_registry)?; let registry = arc_swap::ArcSwap::from(std::sync::Arc::new(asm_registry)); - crate::vm::interpret(registry.load(), "main").map_err(CrudLangError::from) + crate::vm::interpret(registry.load(), "main").map_err(TipiLangError::from) } diff --git a/src/errors.rs b/src/errors.rs index 60cc4eb..8f74ed0 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use thiserror::Error; #[derive(Error, Debug, PartialEq)] -pub enum CrudLangError { +pub enum TipiLangError { #[error("Compilation failed: {0}")] Compiler(#[from] CompilerErrorAtLine), @@ -61,7 +61,7 @@ pub enum CompilerError { UnexpectedType(TokenType), #[error("'{0}' is a keyword. You cannot use it as an identifier")] KeywordNotAllowedAsIdentifier(TokenType), - #[error("Crud does not support numbers above 2^64")] + #[error("Tipi does not support numbers above 2^64")] Overflow, #[error("Undeclared function: '{0}'")] FunctionNotFound(String), diff --git a/src/lib.rs b/src/lib.rs index d17d76b..99288ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,3 +18,5 @@ pub(crate) type SymbolTable = HashMap; pub(crate) type Expr = Result; pub(crate) type Stmt = Result; pub(crate) type AsmRegistry = HashMap; + +pub const TIPI_EXT: &str = ".tp"; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 5f68d19..440f06e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ use axum::http::StatusCode; use axum::routing::any; use axum::{Json, Router}; use clap::Parser; -use tipi_lang::errors::CrudLangError; +use tipi_lang::errors::TipiLangError; use tipi_lang::vm::interpret_async; use std::collections::HashMap; use std::sync::Arc; @@ -26,8 +26,8 @@ struct Args { } #[tokio::main] -async fn main() -> Result<(), CrudLangError> { - println!("-- Crudlang --"); +async fn main() -> Result<(), TipiLangError> { + println!("-- Tipilang --"); tracing_subscriber::fmt::init(); let args = Args::parse(); let source = args.source.unwrap_or("./source".to_string()); diff --git a/src/reference_main.rs b/src/reference_main.rs index e210bcd..fc01677 100644 --- a/src/reference_main.rs +++ b/src/reference_main.rs @@ -32,7 +32,7 @@ async fn main() -> Result<(), Box> { }; let app = Router::new() - .route("/api/customers/{id}", get(get_customer)) + .route("/api/customers.tp/{id}", get(get_customer)) .with_state(state); // run our app with hyper, listening globally on port 3000 @@ -53,7 +53,7 @@ async fn get_customer( let rows = state .db .query( - "SELECT id, first_name, last_name FROM customers WHERE id = $1", + "SELECT id, first_name, last_name FROM customers.tp WHERE id = $1", &[&id], ) .await diff --git a/src/repl.rs b/src/repl.rs index f897c73..bd0ce13 100644 --- a/src/repl.rs +++ b/src/repl.rs @@ -1,7 +1,7 @@ use crate::compiler::asm_pass::AsmChunk; use crate::compiler::scan_pass::scan; use crate::compiler::{asm_pass, ast_pass, map_underlying}; -use crate::errors::CrudLangError; +use crate::errors::TipiLangError; use crate::symbol_builder; use crate::vm::Vm; use arc_swap::ArcSwap; @@ -11,7 +11,7 @@ use std::io::Write; use std::ops::Deref; use std::sync::Arc; -pub fn start(registry: Arc>>) -> Result<(), CrudLangError> { +pub fn start(registry: Arc>>) -> Result<(), TipiLangError> { println!("REPL started -- Type ctrl-c to exit (both the repl and the server)"); println!(":h for help"); let mut symbol_table = HashMap::new(); diff --git a/syntax/crud/CHANGELOG.md b/syntax/crud/CHANGELOG.md index 3cb92d6..af75914 100644 --- a/syntax/crud/CHANGELOG.md +++ b/syntax/crud/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -All notable changes to the "crud" extension will be documented in this file. +All notable changes to the "tipi" extension will be documented in this file. Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. diff --git a/syntax/crud/package.json b/syntax/crud/package.json index d61d979..ac7dc17 100644 --- a/syntax/crud/package.json +++ b/syntax/crud/package.json @@ -1,7 +1,7 @@ { - "name": "crud", - "displayName": "crud", - "description": "crud-lang", + "name": "tipi", + "displayName": "tipi", + "description": "tipi-lang", "version": "0.0.1", "engines": { "vscode": "^1.105.0" @@ -11,20 +11,20 @@ ], "contributes": { "languages": [{ - "id": "crud", - "aliases": ["crud-lang", "crud"], - "extensions": [".crud"], + "id": "tipi", + "aliases": ["tipi-lang", "tipi"], + "extensions": [".tipi"], "configuration": "./language-configuration.json" }], "grammars": [{ - "language": "crud", - "scopeName": "source.crud", - "path": "./syntaxes/crud.tmLanguage.json" + "language": "tipi", + "scopeName": "source.tipi", + "path": "./syntaxes/tipi.tmLanguage.json" }], "semanticTokenScopes": [ { "scopes": { - "crud.custom.scope": ["annotation.crud"] + "tipi.custom.scope": ["annotation.tipi"] } } ] diff --git a/syntax/crud/syntaxes/crud.tmLanguage.json b/syntax/crud/syntaxes/tipi.tmLanguage.json similarity index 64% rename from syntax/crud/syntaxes/crud.tmLanguage.json rename to syntax/crud/syntaxes/tipi.tmLanguage.json index 1ba3554..aea8911 100644 --- a/syntax/crud/syntaxes/crud.tmLanguage.json +++ b/syntax/crud/syntaxes/tipi.tmLanguage.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json", - "name": "crud-lang", + "name": "tipi-lang", "patterns": [ { "include": "#keywords" @@ -19,35 +19,35 @@ "keywords": { "patterns": [ { - "name": "variable.other.crud", + "name": "variable.other.tipi", "match": "(#.+?\\(.*?\\))" }, { - "name": "keyword.control.crud", + "name": "keyword.control.tipi", "match": "\\b(fn)\\b" }, { - "name": "storage.type.crud", + "name": "storage.type.tipi", "match": "\\b(u32|u64|i32|i64\f32|f64|string|date|char|list|map|bool)\\b" }, { - "name": "support.function.crud", + "name": "support.function.tipi", "match": "\\b(get|put|post|delete|patch|options)\\b" }, { - "name": "constant.numeric.crud", + "name": "constant.numeric.tipi", "match": "\\b[0-9]+\\.?[0-9]*\\b" }, { - "name": "constant.language.crud", + "name": "constant.language.tipi", "match": "\\b(true|false)\\b" }, { - "name": "constant.character.escape.crud", + "name": "constant.character.escape.tipi", "match": "\\\\[nrt\\\\'\"]" }, { - "name": "comment.line.crud", + "name": "comment.line.tipi", "match": "(//.*)" } ] @@ -55,41 +55,41 @@ "operators": { "patterns": [ { - "name": "keyword.operator.arithmetic.crud", + "name": "keyword.operator.arithmetic.tipi", "match": "\\+|\\-|\\*|\\/" }, { - "name": "keyword.operator.comparison.crud", + "name": "keyword.operator.comparison.tipi", "match": "==|!=|<=|>=|<|>" }, { - "name": "keyword.operator.assignment.crud", + "name": "keyword.operator.assignment.tipi", "match": "=" } ] }, "strings": { - "name": "string.quoted.double.crud", + "name": "string.quoted.double.tipi", "begin": "\"", "end": "\"", "patterns": [ { - "name": "constant.character.escape.crud", + "name": "constant.character.escape.tipi", "match": "\\\\." } ] }, "chars": { - "name": "string.quoted.single.crud", + "name": "string.quoted.single.tipi", "begin": "'", "end": "'", "patterns": [ { - "name": "constant.character.escape.crud", + "name": "constant.character.escape.tipi", "match": "\\\\." } ] } }, - "scopeName": "source.crud" + "scopeName": "source.tipi" } \ No newline at end of file diff --git a/syntax/crud/vsc-extension-quickstart.md b/syntax/crud/vsc-extension-quickstart.md index c3ce634..2e6ce0f 100644 --- a/syntax/crud/vsc-extension-quickstart.md +++ b/syntax/crud/vsc-extension-quickstart.md @@ -4,7 +4,7 @@ * This folder contains all of the files necessary for your extension. * `package.json` - this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension. -* `syntaxes/crud.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization. +* `syntaxes/tipi.tmLanguage.json` - this is the Text mate grammar file that is used for tokenization. * `language-configuration.json` - this is the language configuration, defining the tokens that are used for comments and brackets. ## Get up and running straight away