diff options
Diffstat (limited to 'tree-sitter/dsk/dsk-cli/templates')
10 files changed, 277 insertions, 0 deletions
diff --git a/tree-sitter/dsk/dsk-cli/templates/default/README.md b/tree-sitter/dsk/dsk-cli/templates/default/README.md new file mode 100644 index 0000000..4560c6a --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/default/README.md @@ -0,0 +1,82 @@ +# __DSL_NAME__ + +A Domain-Specific Language created with DSK (DSL Development Kit). + +## Overview + +- **Language Type**: __PARADIGM__ +- **Purpose**: __PURPOSE__ +- **Data Philosophy**: __DATA_PHILOSOPHY__ + +## Getting Started + +### Prerequisites + +- [Tree-sitter CLI](https://tree-sitter.github.io/tree-sitter/creating-parsers#installation) +- Node.js or Bun (for JavaScript bindings) +- C compiler (gcc/clang) for native compilation + +### Development + +```bash +# Start development mode with file watching +dsk dev + +# Run tests +dsk test + +# Build parser and packages +dsk build + +# Generate editor syntax highlighting +dsk highlight + +# Package for distribution +dsk package +``` + +## Project Structure + +``` +__DSL_NAME__/ +├── grammar.js # Tree-sitter grammar definition +├── corpus/ # Test cases for the grammar +│ └── examples.txt +├── generated/ # Generated artifacts (created by dsk build) +│ ├── c/ # C static library +│ ├── js/ # JavaScript/Node.js package +│ └── editors/ # Editor configurations +└── examples/ # Example programs in your language + └── hello.__EXT__ +``` + +## Language Features + +__FEATURES_LIST__ + +## Grammar Rules + +The grammar includes rules for: + +- **Tokens**: Identifiers, numbers, strings, comments +- **Expressions**: Based on your language paradigm +- **Statements**: Control flow and declarations +- **Data Structures**: __DATA_STRUCTURES__ + +## Next Steps + +1. **Customize the Grammar**: Edit `grammar.js` to refine your language syntax +2. **Add Test Cases**: Create examples in `corpus/examples.txt` +3. **Write Example Programs**: Add sample code to `examples/` +4. **Generate Editor Support**: Run `dsk highlight` for syntax highlighting +5. **Build and Test**: Use `dsk dev` for iterative development + +## Resources + +- [Tree-sitter Documentation](https://tree-sitter.github.io/tree-sitter/) +- [DSK Documentation](https://github.com/your-org/dsk) +- [Language Implementation Patterns](https://pragprog.com/titles/tpdsl/) + +--- + +Generated by [DSK](https://github.com/your-org/dsk) - DSL Development Kit diff --git a/tree-sitter/dsk/dsk-cli/templates/default/corpus/examples.txt b/tree-sitter/dsk/dsk-cli/templates/default/corpus/examples.txt new file mode 100644 index 0000000..94f199e --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/default/corpus/examples.txt @@ -0,0 +1,85 @@ +================================================================================ +Basic Examples +================================================================================ + +Simple variable declaration +--- + +__VARIABLE_EXAMPLE__ + +--- + +(source_file + (statement + (variable_declaration + (identifier) + (expression (number))))) + +================================================================================ +Comments +================================================================================ + +Line comment +--- + +__COMMENT_EXAMPLE__ This is a comment +__VARIABLE_EXAMPLE__ + +--- + +(source_file + (statement + (variable_declaration + (identifier) + (expression (number))))) + +================================================================================ +Expressions +================================================================================ + +String literal via variable declaration +--- + +__VARIABLE_KEYWORD__ message __ASSIGNMENT_OPERATOR__ __STRING_EXAMPLE____TERMINATOR__ + +--- + +(source_file + (statement + (variable_declaration + (identifier) + (expression (string))))) + +================================================================================ +Numbers +================================================================================ + +Integer via variable declaration +--- + +__VARIABLE_KEYWORD__ count __ASSIGNMENT_OPERATOR__ __NUMBER_EXAMPLE____TERMINATOR__ + +--- + +(source_file + (statement + (variable_declaration + (identifier) + (expression (number))))) + +================================================================================ +Identifiers +================================================================================ + +Valid identifier via variable declaration +--- + +__VARIABLE_KEYWORD__ __IDENTIFIER_EXAMPLE__ __ASSIGNMENT_OPERATOR__ 42__TERMINATOR__ + +--- + +(source_file + (statement + (variable_declaration + (identifier) + (expression (number))))) diff --git a/tree-sitter/dsk/dsk-cli/templates/default/examples/hello.__EXT__ b/tree-sitter/dsk/dsk-cli/templates/default/examples/hello.__EXT__ new file mode 100644 index 0000000..07769f6 --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/default/examples/hello.__EXT__ @@ -0,0 +1,7 @@ +__COMMENT_EXAMPLE__ Hello World example for __DSL_NAME__ + +__PARADIGM_EXAMPLE__ + +__COMMENT_EXAMPLE__ More examples: +__VARIABLE_EXAMPLE__ +__VARIABLE_KEYWORD__ __IDENTIFIER_EXAMPLE__ __ASSIGNMENT_OPERATOR__ __STRING_EXAMPLE____TERMINATOR__ diff --git a/tree-sitter/dsk/dsk-cli/templates/default/package.json b/tree-sitter/dsk/dsk-cli/templates/default/package.json new file mode 100644 index 0000000..ab3d0c4 --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/default/package.json @@ -0,0 +1,9 @@ +{ + "name": "__DSL_NAME__-dsl", + "private": true, + "type": "commonjs", + "description": "DSL project for __DSL_NAME__ generated by DSK", + "license": "MIT" +} + + diff --git a/tree-sitter/dsk/dsk-cli/templates/js-addon/binding.gyp b/tree-sitter/dsk/dsk-cli/templates/js-addon/binding.gyp new file mode 100644 index 0000000..ddb424b --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/js-addon/binding.gyp @@ -0,0 +1,28 @@ +{ + "targets": [ + { + "target_name": "tree_sitter___DSL_NAME___binding", + "dependencies": [ + "<!(node -p \"require('node-addon-api').gyp\")" + ], + "include_dirs": [ + "<!@(node -p \"require('node-addon-api').include\")", + "src" + ], + "sources": [ + "bindings/node.cc", + "src/parser.c" + ], + "cflags_c": [ + "-std=c99" + ], + "cflags_cc": [ + "-std=c++14" + ], + "defines": [ + "NAPI_DISABLE_CPP_EXCEPTIONS", + "NAPI_VERSION=8" + ] + } + ] +} diff --git a/tree-sitter/dsk/dsk-cli/templates/js-addon/bindings/node.cc b/tree-sitter/dsk/dsk-cli/templates/js-addon/bindings/node.cc new file mode 100644 index 0000000..d0ba098 --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/js-addon/bindings/node.cc @@ -0,0 +1,16 @@ +#include "napi.h" + +typedef struct TSLanguage TSLanguage; + +extern "C" TSLanguage *tree_sitter___DSL_NAME__(); + +// "tree_sitter___DSL_NAME___binding" is the symbol that gets exported +// when this file is compiled as a Node.js addon. +Napi::Object Init(Napi::Env env, Napi::Object exports) { + exports["name"] = Napi::String::New(env, "__DSL_NAME__"); + auto language = tree_sitter___DSL_NAME__(); + exports["language"] = Napi::External<TSLanguage>::New(env, language); + return exports; +} + +NODE_API_MODULE(tree_sitter___DSL_NAME___binding, Init) diff --git a/tree-sitter/dsk/dsk-cli/templates/js-addon/index.d.ts b/tree-sitter/dsk/dsk-cli/templates/js-addon/index.d.ts new file mode 100644 index 0000000..d25eae0 --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/js-addon/index.d.ts @@ -0,0 +1,3 @@ +declare const _exports: any; +export = _exports; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/tree-sitter/dsk/dsk-cli/templates/js-addon/index.d.ts.map b/tree-sitter/dsk/dsk-cli/templates/js-addon/index.d.ts.map new file mode 100644 index 0000000..ca7a93a --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/js-addon/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""} \ No newline at end of file diff --git a/tree-sitter/dsk/dsk-cli/templates/js-addon/index.js b/tree-sitter/dsk/dsk-cli/templates/js-addon/index.js new file mode 100644 index 0000000..4780f31 --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/js-addon/index.js @@ -0,0 +1,15 @@ +try { + module.exports = require("./build/Release/tree_sitter___DSL_NAME___binding"); +} catch (error1) { + if (error1.code !== 'MODULE_NOT_FOUND') { + throw error1; + } + try { + module.exports = require("./build/Debug/tree_sitter___DSL_NAME___binding"); + } catch (error2) { + if (error2.code !== 'MODULE_NOT_FOUND') { + throw error2; + } + throw error1 + } +} diff --git a/tree-sitter/dsk/dsk-cli/templates/js-addon/package.json b/tree-sitter/dsk/dsk-cli/templates/js-addon/package.json new file mode 100644 index 0000000..c7a0488 --- /dev/null +++ b/tree-sitter/dsk/dsk-cli/templates/js-addon/package.json @@ -0,0 +1,31 @@ +{ + "name": "tree-sitter-__DSL_NAME__", + "version": "1.0.0", + "description": "Tree-sitter parser for __DSL_NAME__", + "main": "index.js", + "keywords": [ + "tree-sitter", + "parser", + "__DSL_NAME__" + ], + "author": "Generated by DSK", + "license": "MIT", + "dependencies": { + "node-addon-api": "^7.0.0", + "node-gyp": "^10.0.0" + }, + "devDependencies": { + "tree-sitter-cli": "^0.20.0" + }, + "scripts": { + "install": "node-gyp rebuild", + "test": "tree-sitter test" + }, + "gypfile": true, + "files": [ + "grammar.js", + "src", + "index.js", + "binding.gyp" + ] +} |