diff --git a/.mega-linter.yml b/.mega-linter.yml index 0ad7a6b..f0c6e89 100644 --- a/.mega-linter.yml +++ b/.mega-linter.yml @@ -1,5 +1,6 @@ --- -# yaml-language-server: $schema=https://raw.githubusercontent.com/megalinter/megalinter/main/megalinter/descriptors/schemas/megalinter-configuration.jsonschema.json +# yaml-language-server: +# $schema=https://raw.githubusercontent.com/megalinter/megalinter/main/megalinter/descriptors/schemas/megalinter-configuration.jsonschema.json # Configuration file for MegaLinter # See all available variables at # https://megalinter.io/configuration/ and in linters documentation diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 98cf31d..6156fab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -28,42 +28,42 @@ Thank you for your interest in contributing to tree-sitter-shellspec! This docum 1. Fork the repository on GitHub 2. Clone your fork locally: - ```bash - git clone https://github.com/YOUR_USERNAME/tree-sitter-shellspec.git - cd tree-sitter-shellspec - ``` +```bash +git clone https://github.com/YOUR_USERNAME/tree-sitter-shellspec.git +cd tree-sitter-shellspec +``` 3. Add the upstream repository: - ```bash - git remote add upstream https://github.com/ivuorinen/tree-sitter-shellspec.git - ``` +```bash +git remote add upstream https://github.com/ivuorinen/tree-sitter-shellspec.git +``` ## Development Setup 1. **Install dependencies:** - ```bash - npm install - ``` +```bash +npm install +``` 2. **Generate the grammar:** - ```bash - npm run generate - ``` +```bash +npm run generate +``` 3. **Run tests:** - ```bash - npm test - ``` +```bash +npm test +``` 4. **Build the parser:** - ```bash - npm run build - ``` +```bash +npm run build +``` ### Development Workflow @@ -209,33 +209,34 @@ tree-sitter test --debug 1. **Create a feature branch:** - ```bash - git checkout -b feature/your-feature-name - ``` +```bash +git checkout -b feature/your-feature-name +``` 2. **Make your changes** following the guidelines above 3. **Commit with clear messages:** - ```bash - git commit -m "feat: add support for Data block modifiers +```bash +git commit -m "feat: add support for Data block modifiers - - Add :raw and :expand modifier support - - Update test cases for new syntax - - Add documentation examples" - ``` +- Add :raw and :expand modifier support +- Update test cases for new syntax +- Add documentation examples" +``` 4. **Push to your fork:** - ```bash - git push origin feature/your-feature-name - ``` +```bash +git push origin feature/your-feature-name +``` 5. **Create a Pull Request** with: - - Clear description of changes - - References to related issues - - Test results and coverage - - Breaking change notes (if any) + +- Clear description of changes +- References to related issues +- Test results and coverage +- Breaking change notes (if any) ### Commit Message Guidelines @@ -282,43 +283,50 @@ Use the [Grammar Issue template](.github/ISSUE_TEMPLATE/grammar_issue.md) for: ### High Priority 1. **Enhanced Data block support** - - `:raw` and `:expand` modifiers - - Pipe filter syntax (`Data | command`) - - Multi-line `#|` syntax + +- `:raw` and `:expand` modifiers +- Pipe filter syntax (`Data | command`) +- Multi-line `#|` syntax 2. **Assertion parsing** - - When/The statement structures - - Matcher syntax parsing - - Subject/predicate analysis + +- When/The statement structures +- Matcher syntax parsing +- Subject/predicate analysis 3. **Performance optimization** - - Reduce parser conflicts - - Optimize grammar rules - - Improve parsing speed + +- Reduce parser conflicts +- Optimize grammar rules +- Improve parsing speed ### Medium Priority 1. **Editor integration** - - Neovim configuration examples - - VS Code extension support - - Emacs tree-sitter integration + +- Neovim configuration examples +- VS Code extension support +- Emacs tree-sitter integration 2. **Tooling improvements** - - Syntax highlighting themes - - Language server features - - Code formatting rules + +- Syntax highlighting themes +- Language server features +- Code formatting rules 3. **Documentation** - - Usage tutorials - - Grammar development guide - - Editor setup instructions + +- Usage tutorials +- Grammar development guide +- Editor setup instructions ### Low Priority 1. **Advanced features** - - ShellSpec custom matchers - - Configuration file parsing - - Metadata extraction + +- ShellSpec custom matchers +- Configuration file parsing +- Metadata extraction ## Development Resources diff --git a/README.md b/README.md index 14187cf..db0bb19 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,16 @@ # tree-sitter-shellspec -[![Test Status](https://img.shields.io/badge/tests-59%2F59%20passing-brightgreen)](https://github.com/ivuorinen/tree-sitter-shellspec) +[![Test Status](https://img.shields.io/badge/tests-61%2F61%20passing-brightgreen)](https://github.com/ivuorinen/tree-sitter-shellspec) [![Grammar Coverage](https://img.shields.io/badge/coverage-100%25-brightgreen)](https://github.com/ivuorinen/tree-sitter-shellspec) [![Tree-sitter](https://img.shields.io/badge/tree--sitter-grammar-blue)](https://tree-sitter.github.io/) -A comprehensive [Tree-sitter](https://tree-sitter.github.io/) grammar for [ShellSpec](https://shellspec.info/) - a BDD (Behavior Driven Development) testing framework for POSIX shell scripts. +A comprehensive [Tree-sitter](https://tree-sitter.github.io/) grammar for +[ShellSpec](https://shellspec.info/) - a BDD (Behavior Driven Development) testing framework for POSIX shell scripts. ## Overview -This grammar extends the [tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) grammar to provide complete parsing support for ShellSpec's BDD constructs. +This grammar extends the [tree-sitter-bash](https://github.com/tree-sitter/tree-sitter-bash) grammar to provide complete parsing support +for ShellSpec's BDD constructs. It enables syntax highlighting, code navigation, and tooling integration for ShellSpec test files. diff --git a/grammar.js b/grammar.js index aeb0a6e..684b215 100644 --- a/grammar.js +++ b/grammar.js @@ -1,8 +1,8 @@ /** - * @file ShellSpec grammar for tree-sitter (extends bash) - * @author Ismo Vuorinen - * @license MIT - */ + * @file ShellSpec grammar for tree-sitter (extends bash) + * @author Ismo Vuorinen + * @license MIT + */ /// // @ts-check diff --git a/package.json b/package.json index 094b7ee..ca66439 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,18 @@ "main": "grammar.js", "author": "Ismo Vuorinen", "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/ivuorinen/tree-sitter-shellspec.git" + }, + "files": [ + "grammar.js", + "src", + "queries", + "binding.gyp", + "bindings", + "scripts" + ], "scripts": { "generate": "tree-sitter generate && ./scripts/post-generate.sh", "generate:only": "tree-sitter generate", diff --git a/queries/highlights.scm b/queries/highlights.scm new file mode 100644 index 0000000..95d4c8b --- /dev/null +++ b/queries/highlights.scm @@ -0,0 +1,85 @@ +; ShellSpec Syntax Highlighting +; Extends tree-sitter-bash highlighting + +; Block keywords (BDD test structure) +[ + "Describe" + "Context" + "ExampleGroup" + "It" + "Example" + "Specify" +] @keyword.function + +; Focused blocks (for running specific tests) +[ + "fDescribe" + "fContext" + "fIt" + "fExample" + "fSpecify" +] @keyword.function.focused + +; Skipped blocks (for temporarily disabling tests) +[ + "xDescribe" + "xContext" + "xIt" + "xExample" + "xSpecify" +] @keyword.function.skipped + +; Hook keywords +[ + "Before" + "After" + "BeforeAll" + "AfterAll" + "BeforeEach" + "AfterEach" + "BeforeRun" + "AfterRun" + "BeforeCall" + "AfterCall" +] @keyword.control.hook + +; Utility blocks +[ + "Data" + "Parameters" +] @keyword.function.data + +; Skip/Pending/Todo blocks +[ + "Skip" + "Pending" + "Todo" +] @keyword.function.pending + +; Directives +[ + "Include" +] @keyword.directive + +; Comments (inherit from bash) +(comment) @comment + +; Strings (inherit from bash) +(string) @string +(raw_string) @string + +; Functions (inherit from bash) +(function_definition + name: (word) @function) + +; Variables (inherit from bash) +(variable_name) @variable + +; Operators (inherit from bash) +[ + "&&" + "||" + "|" + ";" + "&" +] @operator diff --git a/src/grammar.json b/src/grammar.json index b134387..b8fdd13 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -7923,4 +7923,4 @@ "_primary_expression" ], "reserved": {} -} +} \ No newline at end of file diff --git a/src/node-types.json b/src/node-types.json index cad17a1..534a93d 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -3307,4 +3307,4 @@ "type": "~", "named": false } -] +] \ No newline at end of file diff --git a/src/scanner.c b/src/scanner.c index d4bf63a..2fd1f83 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -174,12 +174,12 @@ static void deserialize(Scanner *scanner, const char *buffer, unsigned length) { } /** - * Consume a "word" in POSIX parlance, and returns it unquoted. - * - * This is an approximate implementation that doesn't deal with any - * POSIX-mandated substitution, and assumes the default value for - * IFS. - */ + * Consume a "word" in POSIX parlance, and returns it unquoted. + * + * This is an approximate implementation that doesn't deal with any + * POSIX-mandated substitution, and assumes the default value for + * IFS. + */ static bool advance_word(TSLexer *lexer, String *unquoted_word) { bool empty = true; diff --git a/src/tree_sitter/array.h b/src/tree_sitter/array.h index 28b1a8d..a17a574 100644 --- a/src/tree_sitter/array.h +++ b/src/tree_sitter/array.h @@ -62,7 +62,7 @@ extern "C" { /// Push a new `element` onto the end of the array. #define array_push(self, element) \ (_array__grow((Array *)(self), 1, array_elem_size(self)), \ - (self)->contents[(self)->size++] = (element)) + (self)->contents[(self)->size++] = (element)) /// Increase the array's size by `count` elements. /// New elements are zero-initialized. @@ -218,8 +218,8 @@ static inline void _array__grow(Array *self, uint32_t count, size_t element_size /// This is not what you're looking for, see `array_splice`. static inline void _array__splice(Array *self, size_t element_size, - uint32_t index, uint32_t old_count, - uint32_t new_count, const void *elements) { + uint32_t index, uint32_t old_count, + uint32_t new_count, const void *elements) { uint32_t new_size = self->size + new_count - old_count; uint32_t old_end = index + old_count; uint32_t new_end = index + new_count; diff --git a/src/tree_sitter/parser.h b/src/tree_sitter/parser.h index bd98686..858107d 100644 --- a/src/tree_sitter/parser.h +++ b/src/tree_sitter/parser.h @@ -152,7 +152,6 @@ struct TSLanguage { }; static inline bool set_contains(const TSCharacterRange *ranges, uint32_t len, int32_t lookahead) { - if (len == 0) return false; uint32_t index = 0; uint32_t size = len - index; while (size > 1) {