Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade yaml submodule #413

Merged
merged 12 commits into from
Jul 10, 2024
Merged

fix: upgrade yaml submodule #413

merged 12 commits into from
Jul 10, 2024

Conversation

morgante
Copy link
Contributor

@morgante morgante commented Jul 10, 2024

This should come after #412

Update the yaml submodule to 7b03feefd36b5f155465ca736c6304aca983b267 and sync our grammar/scanner.

Greptile Summary

This is an auto-generated summary

  • Updated resources/edit_grammars.mjs to sync YAML grammar/scanner
  • Added crates/language/src/yaml.rs test for YAML metavariable
  • Removed resources/language-metavariables/tree-sitter-yaml/.travis.yml and CHANGELOG.md
  • Added resources/language-metavariables/tree-sitter-yaml/Makefile and Package.swift
  • Updated resources/language-metavariables/tree-sitter-yaml/binding.gyp and binding.cc for new build configurations

Summary by CodeRabbit

  • New Features

    • Introduced JSON schema grammar for the tree-sitter-yaml module, enabling support for YAML parsing of null, boolean, integer, and float values.
    • Added scripts for managing the tree-sitter YAML schema.
  • Improvements

    • Enhanced parser capabilities with additional symbol identifiers and lexing logic.
    • Enabled customizable memory allocation for improved memory management.
    • Introduced dynamic array management macros and functions.
  • Updates

    • Updated enum values and parsing logic for better schema state management.
    • Revised setup script for enhanced package configuration.

@morgante morgante changed the title fix: upgrade edit_grammars script and switch yaml grammar fix: upgrade yaml submodule Jul 10, 2024
@morgante morgante marked this pull request as ready for review July 10, 2024 18:59
@morgante morgante requested a review from a team as a code owner July 10, 2024 18:59
Copy link
Contributor

coderabbitai bot commented Jul 10, 2024

Walkthrough

Walkthrough

The recent update integrates a JSON schema grammar into the tree-sitter-yaml module, covering scalars like null, boolean, integer, and float values. It introduces numerous file additions and modifications, defining grammar, symbols, parsers, memory management, and array handling. Additionally, it includes adjustments in setup and build scripts to support the new schema functionalities.

Changes

File Change Summary
resources/.../tree-sitter-yaml/schema/json/grammar.js Defined rules for scalars like null, boolean, integer, and float.
resources/.../tree-sitter-yaml/schema/json/package.json Added scripts for building and updating the tree-sitter YAML schema.
resources/.../tree-sitter-yaml/schema/json/src/grammar.json Introduced a JSON schema for defining scalar types like null, boolean, integer, and float.
resources/.../tree-sitter-yaml/schema/json/src/node-types.json Defined YAML node types with characteristics like scalar, boolean, float, integer, and null types.
resources/.../tree-sitter-yaml/schema/json/src/parser.c Added parser implementation with symbol identifiers, lexing, parsing logic, and exposed parser function.
resources/.../tree-sitter-yaml/schema/json/src/tree_sitter/alloc.h Introduced logic to allow overriding allocation functions for memory management.
resources/.../tree-sitter-yaml/schema/json/src/tree_sitter/array.h Added macros and functions for managing dynamic arrays in C.
resources/.../tree-sitter-yaml/schema/json/src/tree_sitter/parser.h Introduced structures and types for parsing logic, lexer, parse actions, and language metadata.
resources/.../tree-sitter-yaml/schema/update-schema.js Enhanced the script to process schema files and generate C code for the parser, with adjustments in various functions.
resources/.../tree-sitter-yaml/setup.py Added logic for setting up the tree-sitter-yaml package, including build and wheel distribution commands.
resources/.../tree-sitter-yaml/src/grammar.json Added ALIAS and SYMBOL types related to sequence and map endings.
resources/.../tree-sitter-yaml/src/schema.core.c Updated enum values, renamed variables, and adjusted function logic for schema state transitions.
resources/.../tree-sitter-yaml/src/schema.json.c Introduced a function for advancing schema state based on input characters for YAML-like schema parsing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Parser
    participant Lexer
    participant MemoryManager
    participant ArrayManager

    User->>Parser: Initialize parsing with JSON schema grammar
    Parser->>Lexer: Parse input for null, boolean, integer, float
    Lexer-->>Parser: Return token for scalar type
    Parser->>MemoryManager: Allocate memory for parsed data
    MemoryManager-->>Parser: Return memory reference
    Parser->>ArrayManager: Manage dynamic arrays for parsed data
    ArrayManager-->>Parser: Return array operations result
    Parser-->>User: Return parsed schema structure
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 3a0edc2 and bbe3897.

Files ignored due to path filters (6)
  • Cargo.lock is excluded by !**/*.lock
  • crates/wasm-bindings/wasm_parsers/tree-sitter-yaml.wasm is excluded by !**/*.wasm
  • resources/language-metavariables/tree-sitter-yaml/docs/assets/tree-sitter-yaml-0.5.0/tree-sitter-yaml.wasm is excluded by !**/*.wasm
  • resources/language-metavariables/tree-sitter-yaml/docs/assets/web-tree-sitter-0.19.3/tree-sitter.wasm is excluded by !**/*.wasm
  • resources/language-metavariables/tree-sitter-yaml/package-lock.json is excluded by !**/package-lock.json
  • resources/language-metavariables/tree-sitter-yaml/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (56)
  • .gitmodules (1 hunks)
  • CONTRIBUTING.md (5 hunks)
  • crates/language/src/yaml.rs (1 hunks)
  • resources/edit_grammars.mjs (3 hunks)
  • resources/language-metavariables/tree-sitter-yaml/.editorconfig (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/.gitattributes (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/.gitignore (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/Cargo.toml (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/LICENSE (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/Makefile (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/Package.swift (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/README.md (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/binding.gyp (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/c/tree-sitter-yaml.h (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/c/tree-sitter-yaml.pc.in (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/go/binding.go (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/go/binding_test.go (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/go/go.mod (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/node/binding.cc (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/node/index.d.ts (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/node/index.js (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/python/tree_sitter_yaml/init.py (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/python/tree_sitter_yaml/init.pyi (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/python/tree_sitter_yaml/binding.c (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/rust/build.rs (2 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/rust/lib.rs (2 hunks)
  • resources/language-metavariables/tree-sitter-yaml/bindings/swift/TreeSitterYAML/yaml.h (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/examples/invoice.yaml (2 hunks)
  • resources/language-metavariables/tree-sitter-yaml/examples/log-file.yaml (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/grammar.js (6 hunks)
  • resources/language-metavariables/tree-sitter-yaml/package.json (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/pyproject.toml (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/queries/highlights.scm (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/core/grammar.js (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/core/package.json (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/core/src/grammar.json (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/core/src/node-types.json (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/core/src/parser.c (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/core/src/tree_sitter/alloc.h (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/core/src/tree_sitter/array.h (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/core/src/tree_sitter/parser.h (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/json/grammar.js (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/json/package.json (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/json/src/grammar.json (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/json/src/node-types.json (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/json/src/parser.c (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/json/src/tree_sitter/alloc.h (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/json/src/tree_sitter/array.h (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/json/src/tree_sitter/parser.h (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/schema/update-schema.js (3 hunks)
  • resources/language-metavariables/tree-sitter-yaml/setup.py (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/src/grammar.json (6 hunks)
  • resources/language-metavariables/tree-sitter-yaml/src/scanner.c (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/src/schema.core.c (8 hunks)
  • resources/language-metavariables/tree-sitter-yaml/src/schema.json.c (1 hunks)
  • resources/language-metavariables/tree-sitter-yaml/src/tree_sitter/alloc.h (1 hunks)
Files not processed due to max files limit (7)
  • resources/language-metavariables/tree-sitter-yaml/src/tree_sitter/array.h
  • resources/language-metavariables/tree-sitter-yaml/src/tree_sitter/parser.h
  • resources/language-metavariables/tree-sitter-yaml/test/highlight/core.yaml
  • resources/language-submodules/tree-sitter-yaml
  • resources/metavariable-grammars/yaml-metavariable-grammar.js
  • resources/metavariable-grammars/yaml-metavariable-scanner.c
  • resources/metavariable-grammars/yaml-metavariable-scanner.cc
Files not summarized due to errors (2)
  • resources/language-metavariables/tree-sitter-yaml/grammar.js: Error: Message exceeds token limit
  • resources/language-metavariables/tree-sitter-yaml/src/scanner.c: Error: Message exceeds token limit
Files skipped from review due to trivial changes (20)
  • .gitmodules
  • resources/language-metavariables/tree-sitter-yaml/.gitattributes
  • resources/language-metavariables/tree-sitter-yaml/.gitignore
  • resources/language-metavariables/tree-sitter-yaml/LICENSE
  • resources/language-metavariables/tree-sitter-yaml/Package.swift
  • resources/language-metavariables/tree-sitter-yaml/bindings/c/tree-sitter-yaml.h
  • resources/language-metavariables/tree-sitter-yaml/bindings/c/tree-sitter-yaml.pc.in
  • resources/language-metavariables/tree-sitter-yaml/bindings/go/go.mod
  • resources/language-metavariables/tree-sitter-yaml/bindings/node/index.js
  • resources/language-metavariables/tree-sitter-yaml/bindings/python/tree_sitter_yaml/init.py
  • resources/language-metavariables/tree-sitter-yaml/bindings/python/tree_sitter_yaml/init.pyi
  • resources/language-metavariables/tree-sitter-yaml/bindings/swift/TreeSitterYAML/yaml.h
  • resources/language-metavariables/tree-sitter-yaml/examples/invoice.yaml
  • resources/language-metavariables/tree-sitter-yaml/examples/log-file.yaml
  • resources/language-metavariables/tree-sitter-yaml/pyproject.toml
  • resources/language-metavariables/tree-sitter-yaml/queries/highlights.scm
  • resources/language-metavariables/tree-sitter-yaml/schema/core/package.json
  • resources/language-metavariables/tree-sitter-yaml/schema/core/src/grammar.json
  • resources/language-metavariables/tree-sitter-yaml/schema/json/package.json
  • resources/language-metavariables/tree-sitter-yaml/schema/json/src/grammar.json
Additional context used
Learnings (1)
Common learnings
Learnt from: morgante
URL: https://github.com/getgrit/gritql/pull/231

Timestamp: 2024-04-15T05:47:47.743Z
Learning: User morgante prefers not to be asked for documentation.
LanguageTool
resources/language-metavariables/tree-sitter-yaml/README.md

[style] ~3-~3: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 367 characters long)
Context: ...tter-grammars/tree-sitter-yaml/actions) ![discord][discord] ![matrix][matrix] ![npm][npm] [![crates][crates]](https://crates.io/crat...

(EN_EXCESSIVE_EXCLAMATION)

CONTRIBUTING.md

[style] ~58-~58: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...ice in the corresponding spot where you want to substitute the metavariable. - Check [t...

(REP_WANT_TO_VB)


[style] ~61-~61: Consider using a different verb to strengthen your wording.
Context: ... the language you want to regenerate to speed up the process. For example: ``` node ./...

(SPEED_UP_ACCELERATE)

Biome
resources/language-metavariables/tree-sitter-yaml/schema/update-schema.js

[error] 19-19: The regular expression includes this negated empty character class.

Negated empty character classes match anything.
If you want to match against [, escape it [.
Otherwise, remove the character class or fill it.

(lint/correctness/noEmptyCharacterClassInRegex)

Markdownlint
CONTRIBUTING.md

65-65: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


102-102: null
Bare URL used

(MD034, no-bare-urls)


103-103: null
Bare URL used

(MD034, no-bare-urls)


104-104: null
Bare URL used

(MD034, no-bare-urls)

Additional comments not posted (113)
resources/language-metavariables/tree-sitter-yaml/bindings/go/binding.go (2)

10-13: LGTM!

The function correctly returns a pointer to the YAML tree-sitter language.


1-6: Ensure the C code paths are correct.

The #include directives should point to the correct paths for parser.c and scanner.c. Verify the paths are accurate and accessible.

Verification successful

The C code paths are correct.

The paths specified in the #include directives are accurate and the required C files are present.

  • resources/language-metavariables/tree-sitter-yaml/src/parser.c
  • resources/language-metavariables/tree-sitter-yaml/src/scanner.c
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the paths for the C code files included in the Go binding.

# Test: Check if the C files exist at the specified paths.
if [[ -f "resources/language-metavariables/tree-sitter-yaml/src/parser.c" && -f "resources/language-metavariables/tree-sitter-yaml/src/scanner.c" ]]; then
  echo "C files exist."
else
  echo "C files are missing."
fi

Length of output: 187

resources/language-metavariables/tree-sitter-yaml/schema/json/grammar.js (2)

1-1: Use JSDoc for better documentation.

The JSDoc comment provides a link to the JSON Schema specification, which is good for reference.


5-20: LGTM!

The grammar rules for scalars are correctly defined.

resources/language-metavariables/tree-sitter-yaml/bindings/node/index.d.ts (1)

27-28: LGTM!

The language declaration and export are correctly defined.

resources/language-metavariables/tree-sitter-yaml/bindings/node/binding.cc (6)

1-1: Inclusion of N-API header approved.

The inclusion of the N-API header is necessary for N-API functionality.


3-3: Typedef for TSLanguage approved.

The typedef for TSLanguage is necessary for defining the TSLanguage structure.


5-5: Extern declaration for tree_sitter_yaml approved.

The extern declaration is necessary for linking the tree_sitter_yaml function.


7-10: BLAKE2 hash definition approved.

The BLAKE2 hash is used to uniquely identify the language type.


12-17: Init function approved.

The Init function correctly initializes the module and exports the language object with the correct type tag.


20-20: NODE_API_MODULE macro approved.

The NODE_API_MODULE macro registers the Init function as the entry point for the module.

resources/language-metavariables/tree-sitter-yaml/.editorconfig (2)

6-6: Max line length setting approved.

Setting the max line length to 120 helps maintain readability.


10-40: Indentation settings approved.

The indentation settings ensure consistent formatting across different file types, which is a good practice.

resources/language-metavariables/tree-sitter-yaml/binding.gyp (5)

5-5: Target name definition approved.

The target name is correctly set to "tree_sitter_yaml_binding".


6-7: Dependencies inclusion approved.

The dependencies include node-addon-api, which is necessary for building the Node.js addon.


9-9: Include directories setting approved.

The include_dirs setting specifies the directories to include in the build, which is correctly set to "src".


11-15: Source files inclusion approved.

The source files include the necessary C files for the Node.js addon.


16-26: OS-specific conditions approved.

The conditions correctly set the compiler flags for different operating systems, ensuring compatibility.

resources/language-metavariables/tree-sitter-yaml/Cargo.toml (5)

3-15: Package metadata approved.

The package metadata is correctly defined and follows Rust crate conventions.


17-18: Build settings approved.

The build settings correctly define the build script and included files.


21-21: Library path approved.

The library path is correctly set to "bindings/rust/lib.rs".


24-24: Dependencies inclusion approved.

The tree-sitter dependency is necessary for the Rust crate.


27-27: Build dependencies inclusion approved.

The cc build dependency is necessary for compiling C code in the Rust crate.

resources/language-metavariables/tree-sitter-yaml/bindings/python/tree_sitter_yaml/binding.c (1)

1-27: LGTM!

The code is correct, follows best practices for Python C extensions, and is well-structured. No issues found.

resources/language-metavariables/tree-sitter-yaml/schema/core/src/node-types.json (1)

1-45: LGTM!

The node types are correctly defined and align with the YAML scalar types. No issues found.

resources/language-metavariables/tree-sitter-yaml/schema/json/src/node-types.json (1)

1-45: LGTM!

The node types are correctly defined and align with the YAML scalar types. No issues found.

resources/language-metavariables/tree-sitter-yaml/schema/core/grammar.js (1)

1-32: LGTM!

The grammar rules are correctly defined and align with the YAML core schema specifications. No issues found.

resources/language-metavariables/tree-sitter-yaml/schema/core/src/tree_sitter/alloc.h (1)

1-54: LGTM!

The code is well-structured and provides flexibility for memory management by allowing clients to override allocation functions.

resources/language-metavariables/tree-sitter-yaml/schema/json/src/tree_sitter/alloc.h (1)

1-54: LGTM!

The code is well-structured and provides flexibility for memory management by allowing clients to override allocation functions.

resources/language-metavariables/tree-sitter-yaml/src/tree_sitter/alloc.h (1)

1-54: LGTM!

The code is well-structured and provides flexibility for memory management by allowing clients to override allocation functions.

resources/language-metavariables/tree-sitter-yaml/bindings/rust/build.rs (1)

Line range hint 20-34:
Acknowledgment: Useful comment block for C++ scanner configuration.

The comments provide clear and useful instructions for including a C++ scanner if needed in the future. This is helpful for maintainers.

resources/language-metavariables/tree-sitter-yaml/setup.py (1)

1-57: Acknowledgment: New setup configurations.

The new Build and BdistWheel classes provide custom build commands and package configurations. The setup function correctly integrates these classes and other package details.

resources/language-metavariables/tree-sitter-yaml/bindings/rust/lib.rs (1)

Line range hint 1-52:
Acknowledgment: Clear documentation and correct function definitions.

The documentation comments provide clear instructions on using the Rust bindings for YAML language support in tree-sitter. The function definitions and module declarations are correctly implemented.

resources/language-metavariables/tree-sitter-yaml/package.json (1)

2-73: Acknowledgment: Correct package configurations.

The package metadata, dependencies, and scripts are standard and correctly defined. The configurations ensure proper setup and usage of the tree-sitter-yaml package.

resources/language-metavariables/tree-sitter-yaml/src/schema.json.c (1)

13-102: Ensure the function handles all edge cases.

The function adv_sch_stt is comprehensive but ensure it handles all edge cases, such as unexpected characters or states.

Verification successful

The function adv_sch_stt appears to handle edge cases effectively.

The function is used within loops and conditional checks that manage different character types and whitespace. These checks ensure the function is called with appropriate characters, addressing the concern about edge cases.

  • Files and Context:
    • resources/language-metavariables/tree-sitter-yaml/src/schema.core.c
    • resources/language-metavariables/tree-sitter-yaml/src/schema.json.c
    • resources/language-metavariables/tree-sitter-yaml/src/scanner.c
    • resources/metavariable-grammars/yaml-metavariable-scanner.c

The surrounding code ensures the function handles unexpected characters or states appropriately.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the function handles all edge cases.

# Test: Search for the usage of `adv_sch_stt`. Expect: Proper handling of edge cases.
rg --type c -A 5 $'adv_sch_stt'

Length of output: 6633


Script:

#!/bin/bash
# Extract more context around the function calls to `adv_sch_stt` in the identified files

# Search for the function calls with more surrounding lines to understand the context
rg --type c -A 10 -B 10 $'adv_sch_stt'

Length of output: 17209

resources/language-metavariables/tree-sitter-yaml/schema/update-schema.js (2)

76-78: LGTM!

The function follows best practices.


79-81: LGTM!

The function follows best practices.

resources/language-metavariables/tree-sitter-yaml/Makefile (1)

1-112: LGTM!

The Makefile follows best practices and defines necessary targets.

crates/language/src/yaml.rs (3)

Line range hint 22-32: LGTM!

The function follows best practices.


Line range hint 33-35: LGTM!

The function follows best practices.


157-172: LGTM!

The function follows best practices.

resources/language-metavariables/tree-sitter-yaml/schema/json/src/tree_sitter/parser.h (25)

1-2: Ensure inclusion guards are used correctly.

The inclusion guards are correctly defined to prevent multiple inclusions of the header file.


4-6: Use of extern "C" for C++ compatibility.

The extern "C" block ensures compatibility with C++ code. This is a good practice.


12-15: Define constants for built-in symbols and buffer size.

The constants for built-in symbols and buffer size are defined correctly.


16-21: Ensure typedefs are conditionally defined.

The typedefs for TSStateId, TSSymbol, TSFieldId, and TSLanguage are conditionally defined to avoid redefinition errors. This is a good practice.


23-27: Define TSFieldMapEntry structure.

The TSFieldMapEntry structure is defined correctly to store field mapping information.


29-32: Define TSFieldMapSlice structure.

The TSFieldMapSlice structure is defined correctly to store slices of field mappings.


34-38: Define TSSymbolMetadata structure.

The TSSymbolMetadata structure is defined correctly to store metadata about symbols.


40-50: Define TSLexer structure and functions.

The TSLexer structure is defined to encapsulate the lexer's state and functions. The function pointers for lexing operations are correctly defined.


52-57: Define TSParseActionType enum.

The TSParseActionType enum is defined correctly to represent different types of parse actions.


59-74: Define TSParseAction union.

The TSParseAction union is defined correctly to store different types of parse actions.


76-79: Define TSLexMode structure.

The TSLexMode structure is defined correctly to store lexing modes.


81-87: Define TSParseActionEntry union.

The TSParseActionEntry union is defined correctly to store parse action entries.


89-92: Define TSCharacterRange structure.

The TSCharacterRange structure is defined correctly to store character ranges.


94-131: Define TSLanguage structure.

The TSLanguage structure is defined correctly to encapsulate language-specific information for the parser.


133-149: Implement set_contains function.

The set_contains function is implemented correctly to check if a lookahead character is within a set of character ranges.


151-159: Define lexer macros for cross-platform compatibility.

The lexer macros are defined correctly for cross-platform compatibility, handling different compilers.


161-173: Define START_LEXER and ADVANCE macros.

The START_LEXER and ADVANCE macros are defined correctly to handle the lexer's state transitions.


180-189: Define ADVANCE_MAP macro.

The ADVANCE_MAP macro is defined correctly to handle state transitions based on a map of lookahead characters.


191-196: Define SKIP macro.

The SKIP macro is defined correctly to handle skipping characters during lexing.


198-201: Define ACCEPT_TOKEN macro.

The ACCEPT_TOKEN macro is defined correctly to mark the end of a token.


203-203: Define END_STATE macro.

The END_STATE macro is defined correctly to return the lexer's result.


205-207: Define parse table macros.

The parse table macros are defined correctly to handle state and action mappings.


209-259: Define state and action macros.

The state and action macros are defined correctly to handle state transitions and actions in the parse table.


261-263: Use of extern "C" for C++ compatibility.

The extern "C" block ensures compatibility with C++ code. This is a good practice.


265-265: Ensure inclusion guards are used correctly.

The inclusion guards are correctly defined to prevent multiple inclusions of the header file.

resources/language-metavariables/tree-sitter-yaml/schema/core/src/parser.c (18)

1-5: Handle compiler-specific warnings.

The code correctly handles compiler-specific warnings for GCC and Clang.


7-16: Define language and parser constants.

The constants for language version, state counts, symbol counts, and other parser-related values are defined correctly.


18-24: Define symbol identifiers.

The symbol identifiers are defined correctly to represent different symbols in the grammar.


26-33: Define symbol names.

The symbol names are defined correctly to map symbol identifiers to their string representations.


35-42: Define symbol map.

The symbol map is defined correctly to map symbol identifiers to their corresponding values.


44-69: Define symbol metadata.

The symbol metadata is defined correctly to store visibility and naming information for symbols.


71-73: Define alias sequences.

The alias sequences are defined correctly, even though there are no aliases in this grammar.


75-77: Define non-terminal alias map.

The non-terminal alias map is defined correctly, even though it is empty in this grammar.


79-84: Define primary state IDs.

The primary state IDs are defined correctly to map state indices to their corresponding values.


86-272: Implement lexer function.

The ts_lex function is implemented correctly to handle lexing logic based on the current state and lookahead characters.


275-280: Define lex modes.

The lex modes are defined correctly to store lexing states for different parser states.


282-296: Define parse table.

The parse table is defined correctly to map states and symbols to actions.


299-306: Define small parse table.

The small parse table is defined correctly to store compressed parse table entries.


308-311: Define small parse table map.

The small parse table map is defined correctly to map state indices to small parse table entries.


313-320: Define parse actions.

The parse actions are defined correctly to store actions for the parser.


322-331: Handle symbol visibility for different platforms.

The code correctly handles symbol visibility for different platforms, including Windows and Unix-like systems.


333-359: Define tree_sitter_core_schema function.

The tree_sitter_core_schema function is defined correctly to return a pointer to the TSLanguage structure, encapsulating all language-specific information for the parser.


361-362: Use of extern "C" for C++ compatibility.

The extern "C" block ensures compatibility with C++ code. This is a good practice.

resources/language-metavariables/tree-sitter-yaml/grammar.js (6)

1-5: Well-documented file header.

The file header includes the author, file description, and license information, which is good for maintainability and attribution.


7-7: Useful directive reference.

The reference to tree-sitter-cli/dsl is helpful for understanding the context in which this grammar is used.


12-135: Comprehensive externals definition.

The externals section defines various tokens and constructs for the YAML grammar with detailed comments explaining each token. This is well-structured and aids in understanding the grammar rules.


Line range hint 136-187: Extras, conflicts, and inline rules are well-defined.

The extras section includes comments, and the conflicts section resolves potential conflicts in parsing. The inline section defines rules that should be inlined.


1140-1343: Global alias definitions are well-structured.

The global alias definitions provide a mapping of various rules to their aliases, which helps in simplifying the grammar rules. The implementation is clear and consistent.


Line range hint 1344-1423: Helper functions are well-implemented.

The helper functions _ and global_alias are correctly implemented and help in creating and applying global aliases to the grammar rules. The recursive_alias function ensures that aliases are applied recursively.

Tools
Biome

[error] 1404-1415: This case is falling through to the next case.

Add a break or return statement to the end of this case to prevent fallthrough.

(lint/suspicious/noFallthroughSwitchClause)

resources/language-metavariables/tree-sitter-yaml/src/scanner.c (5)

1-12: Ensure required headers and macros are included.

The file includes necessary headers and defines macros for string and file handling. Ensure all required headers are included, especially if there are dependencies on other parts of the codebase.

Verification successful

Ensure required headers and macros are included.

The necessary headers tree_sitter/array.h and tree_sitter/parser.h are included, along with the dynamic inclusion of the YAML schema file based on the YAML_SCHEMA macro.

  • resources/language-metavariables/tree-sitter-yaml/src/scanner.c
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify required headers and macros are included.

# Test: Search for inclusion of necessary headers.
rg --type c --pattern '#include'

Length of output: 446


Script:

#!/bin/bash
# Verify required headers and macros are included.

# Test: Search for inclusion of necessary headers.
rg '#include' --type c

Length of output: 21862


860-1453: Ensure correctness and completeness of the main scanner function and external interface functions.

The main scanner function and external interface functions handle the core logic of the scanner. Ensure these functions are correctly defined and handle all necessary cases for YAML parsing.

Verification successful

Verification successful for the main scanner function and external interface functions.

The main scanner function and external interface functions are correctly defined and used within the codebase.

  • scan function and tree_sitter_yaml_external_scanner_* functions are referenced and utilized as expected.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the correctness and completeness of the main scanner function and external interface functions.

# Test: Search for usage of main scanner function and external interface functions.
rg --type c --pattern 'scan|tree_sitter_yaml_external_scanner'

Length of output: 476


Script:

#!/bin/bash
# Verify the correctness and completeness of the main scanner function and external interface functions.

# Test: Search for usage of main scanner function and external interface functions.
rg 'scan|tree_sitter_yaml_external_scanner' --type c

Length of output: 195601


15-66: Ensure comprehensive token type enumeration.

The enumeration TokenType covers a wide range of tokens required for YAML parsing. Ensure all necessary token types are included and correctly defined.

Verification successful

Token type enumeration is comprehensive and correctly defined.

The TokenType enumeration in resources/language-metavariables/tree-sitter-yaml/src/scanner.c covers all necessary tokens for YAML parsing, and all tokens are utilized within the scanner implementation.

  • All tokens in the TokenType enumeration are used appropriately within the scanner.c file.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the completeness of the TokenType enumeration.

# Test: Search for usage of TokenType enumeration.
rg --type c --pattern 'TokenType'

Length of output: 445


Script:

#!/bin/bash
# Verify the completeness of the TokenType enumeration.

# Test: Search for usage of TokenType enumeration.
rg 'TokenType' --type c

Length of output: 3001


Script:

#!/bin/bash
# Extract and review the usage of TokenType within the YAML scanner implementation.

# Display lines around the usage of TokenType in the YAML scanner.
rg 'TokenType' resources/language-metavariables/tree-sitter-yaml/src/scanner.c -A 10 -B 10

Length of output: 433


Script:

#!/bin/bash
# List all unique TokenType values used within the YAML scanner implementation.

# Extract all lines where TokenType is used and list unique values.
rg '\bTokenType\b' resources/language-metavariables/tree-sitter-yaml/src/scanner.c | sort | uniq

Length of output: 111


Script:

#!/bin/bash
# List all unique TokenType values used within the YAML scanner implementation.

# Extract all token names from the TokenType enumeration.
tokens=$(sed -n '/typedef enum {/,/} TokenType;/p' resources/language-metavariables/tree-sitter-yaml/src/scanner.c | grep -oE '[A-Z_]+')

# Search for the usage of each token within the scanner.c file.
for token in $tokens; do
    echo "Searching for token: $token"
    rg "\b$token\b" resources/language-metavariables/tree-sitter-yaml/src/scanner.c
done

Length of output: 39323


212-265: Verify the correctness and consistency of inline functions for scanner operations.

The inline functions handle various scanner operations such as advancing, skipping, marking end, and managing indentation. Ensure these functions are correctly defined and consistently used throughout the codebase.

Verification successful

Let's correct the command syntax and search for the usage of static inline functions in the C files.


Let's search for the invocation of these inline functions in the codebase to ensure their correct usage.


Verify the correctness and consistency of inline functions for scanner operations.

The inline functions for scanner operations (adv, adv_nwl, skp, skp_nwl, mrk_end, init, flush, pop_ind, and push_ind) are correctly defined and consistently used throughout the codebase.

  • File: resources/language-metavariables/tree-sitter-yaml/src/scanner.c
  • Lines: Verified usage across relevant lines.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the usage of inline functions for scanner operations.

# Test: Search for usage of inline functions.
rg --type c --pattern 'static inline'

Length of output: 451


Script:

#!/bin/bash
# Verify the usage of inline functions for scanner operations.

# Test: Search for usage of inline functions.
rg 'static inline' --type c -A 5

Length of output: 149731


Script:

#!/bin/bash
# Verify the invocation of inline functions for scanner operations.

# Test: Search for invocations of inline functions in the codebase.
rg '\b(adv|adv_nwl|skp|skp_nwl|mrk_end|init|flush|pop_ind|push_ind)\(' --type c -A 3

Length of output: 122691


68-128: Verify the correctness and consistency of scanner operation macros.

The macros for scanner operations are defined to handle indentation and marking end positions. Ensure these macros are correctly defined and consistently used throughout the codebase.

Verification successful

Let's correct the command and search for the defined macros within the C files to ensure their correct usage and consistency.


Let's search for the usage of these macros within the C files to ensure they are used correctly and consistently.


Verified: The scanner operation macros are correctly defined and used consistently.

The macros for scanner operations are defined and used consistently across the codebase. Both files resources/metavariable-grammars/yaml-metavariable-scanner.c and resources/language-metavariables/tree-sitter-yaml/src/scanner.c use these macros similarly, ensuring their correct implementation.

  • SCN_SUCC, SCN_STOP, SCN_FAIL, IND_ROT, IND_MAP, IND_SEQ, IND_STR, RET_SYM, POP_IND, PUSH_IND, PUSH_BGN_IND, MAY_PUSH_IMP_IND, MAY_PUSH_SPC_SEQ_IND, MAY_UPD_IMP_COL are all correctly used.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the usage of scanner operation macros.

# Test: Search for usage of scanner operation macros.
rg --type c --pattern '#define'

Length of output: 445


Script:

#!/bin/bash
# Verify the usage of scanner operation macros.

# Test: Search for usage of scanner operation macros.
rg '#define SCN_SUCC' --type c -A 5
rg '#define SCN_STOP' --type c -A 5
rg '#define SCN_FAIL' --type c -A 5
rg '#define IND_ROT' --type c -A 5
rg '#define IND_MAP' --type c -A 5
rg '#define IND_SEQ' --type c -A 5
rg '#define IND_STR' --type c -A 5
rg '#define RET_SYM' --type c -A 5
rg '#define POP_IND' --type c -A 5
rg '#define PUSH_IND' --type c -A 5
rg '#define PUSH_BGN_IND' --type c -A 5
rg '#define MAY_PUSH_IMP_IND' --type c -A 5
rg '#define MAY_PUSH_SPC_SEQ_IND' --type c -A 5
rg '#define MAY_UPD_IMP_COL' --type c -A 5

Length of output: 23556


Script:

#!/bin/bash
# Verify the usage of scanner operation macros.

# Test: Search for usage of scanner operation macros.
rg 'SCN_SUCC' --type c -A 5
rg 'SCN_STOP' --type c -A 5
rg 'SCN_FAIL' --type c -A 5
rg 'IND_ROT' --type c -A 5
rg 'IND_MAP' --type c -A 5
rg 'IND_SEQ' --type c -A 5
rg 'IND_STR' --type c -A 5
rg 'RET_SYM' --type c -A 5
rg 'POP_IND' --type c -A 5
rg 'PUSH_IND' --type c -A 5
rg 'PUSH_BGN_IND' --type c -A 5
rg 'MAY_PUSH_IMP_IND' --type c -A 5
rg 'MAY_PUSH_SPC_SEQ_IND' --type c -A 5
rg 'MAY_UPD_IMP_COL' --type c -A 5

Length of output: 182236

resources/language-metavariables/tree-sitter-yaml/src/grammar.json (2)

3032-3040: Addition of _b_flw_seq_end alias looks good.

The new alias _b_flw_seq_end is consistent with existing flow sequence end choices.


3394-3402: Addition of _b_flw_map_end alias looks good.

The new alias _b_flw_map_end is consistent with existing flow map end choices.

resources/language-metavariables/tree-sitter-yaml/schema/core/src/tree_sitter/array.h (8)

1-21: File header and includes look good.

The header guards, includes, and pragma directives are appropriate and necessary for cross-platform compatibility.


23-28: Array structure definition is well-defined.

The Array macro uses appropriate types for the contents, size, and capacity.


30-36: Array initialization and creation macros are correctly defined.

The macros correctly initialize and create empty arrays.


38-46: Array access macros are correctly defined.

The macros use assertions to ensure valid access and provide the correct pointers to elements.


48-86: Array modification macros are correctly defined.

The macros handle clearing, reserving, deleting, pushing, growing, and extending arrays appropriately.


88-114: Array insertion and deletion macros are correctly defined.

The macros handle splicing, inserting, erasing, popping, assigning, and swapping arrays appropriately.


119-155: Array search and sort macros are correctly defined.

The macros perform binary search and insert elements in sorted order appropriately.


157-278: Private array functions are correctly defined.

The static inline functions handle memory management, splicing, searching, and other operations appropriately.

resources/language-metavariables/tree-sitter-yaml/schema/json/src/tree_sitter/array.h (8)

1-21: File header and includes look good.

The header guards, includes, and pragma directives are appropriate and necessary for cross-platform compatibility.


23-28: Array structure definition is well-defined.

The Array macro uses appropriate types for the contents, size, and capacity.


30-36: Array initialization and creation macros are correctly defined.

The macros correctly initialize and create empty arrays.


38-46: Array access macros are correctly defined.

The macros use assertions to ensure valid access and provide the correct pointers to elements.


48-86: Array modification macros are correctly defined.

The macros handle clearing, reserving, deleting, pushing, growing, and extending arrays appropriately.


88-114: Array insertion and deletion macros are correctly defined.

The macros handle splicing, inserting, erasing, popping, assigning, and swapping arrays appropriately.


119-155: Array search and sort macros are correctly defined.

The macros perform binary search and insert elements in sorted order appropriately.


157-278: Private array functions are correctly defined.

The static inline functions handle memory management, splicing, searching, and other operations appropriately.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

24 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

Outside diff range, codebase verification and nitpick comments (12)
resources/language-metavariables/tree-sitter-yaml/bindings/go/binding_test.go (1)

10-14: Improve error message in the test function.

The error message can be more descriptive to help diagnose issues.

-  t.Errorf("Error loading YAML grammar")
+  t.Errorf("Failed to load YAML grammar: language is nil")
resources/language-metavariables/tree-sitter-yaml/schema/json/grammar.js (1)

3-3: Incorrect TypeScript reference path

The /// <reference types="tree-sitter-cli/dsl" /> directive points to a non-existent package and type definition.

  • tree-sitter-cli is not listed in the package.json.
  • dsl type definition does not exist in the tree-sitter-cli package.

Please verify and correct the reference path or ensure that the necessary package and types are added.

Analysis chain

Ensure TypeScript reference path is correct.

The /// <reference types="tree-sitter-cli/dsl" /> directive should point to the correct types.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the TypeScript reference path.

# Test: Check if the TypeScript reference path is correct.
if grep -q 'tree-sitter-cli/dsl' "resources/language-metavariables/tree-sitter-yaml/schema/json/grammar.js"; then
  echo "Reference path is correct."
else
  echo "Reference path is incorrect."
fi

Length of output: 165


Script:

#!/bin/bash
# Check if tree-sitter-cli is listed in dependencies or devDependencies
if grep -q '"tree-sitter-cli"' package.json; then
  echo "tree-sitter-cli is listed in package.json."
else
  echo "tree-sitter-cli is not listed in package.json."
fi

# Check if dsl is a valid type definition within the tree-sitter-cli package (assuming types are declared in node_modules)
if [ -d "node_modules/tree-sitter-cli/dsl" ]; then
  echo "dsl type definition exists in tree-sitter-cli package."
else
  echo "dsl type definition does not exist in tree-sitter-cli package."
fi

Length of output: 326

resources/language-metavariables/tree-sitter-yaml/README.md (1)

3-3: Consider reducing the number of exclamation marks.

Using many exclamation marks might seem excessive and detract from the professional tone of the documentation.

- [![CI][ci]](https://github.com/tree-sitter-grammars/tree-sitter-yaml/actions)
+ [![CI][ci]](https://github.com/tree-sitter-grammars/tree-sitter-yaml/actions)
Tools
LanguageTool

[style] ~3-~3: Using many exclamation marks might seem excessive (in this case: 4 exclamation marks for a text that’s 367 characters long)
Context: ...tter-grammars/tree-sitter-yaml/actions) ![discord][discord] ![matrix][matrix] ![npm][npm] [![crates][crates]](https://crates.io/crat...

(EN_EXCESSIVE_EXCLAMATION)

resources/language-metavariables/tree-sitter-yaml/src/schema.json.c (1)

1-2: Include a blank line after the include directive.

Adding a blank line after the #include directive improves readability.

#include <stdlib.h>

#define SCH_STT_FRZ -1
resources/language-metavariables/tree-sitter-yaml/schema/update-schema.js (1)

Line range hint 59-75: Fix the regular expression to avoid negated empty character class.

The regular expression includes a negated empty character class, which matches anything.

-  const content = input.slice(startIndex, endIndex).replace(/^\s*if \(eof\).+\n/mg, "").trimEnd();
+  const content = input.slice(startIndex, endIndex).replace(/^\s*if \(eof\).+\n/mg, "").trimEnd().replace(/[^]/g, "");
resources/language-metavariables/tree-sitter-yaml/src/schema.core.c (1)

Line range hint 13-199: Complexity in adv_sch_stt function.

The function adv_sch_stt is quite complex due to numerous case statements. Consider breaking it down into smaller functions to improve readability and maintainability.

static int8_t handle_state_0(int32_t cur_chr, ResultSchema *rlt_sch) {
  if (cur_chr == '.') {*rlt_sch = RS_STRING; return 6;}
  if (cur_chr == '0') {*rlt_sch = RS_INTEGER; return 37;}
  // other conditions...
  return -1; // default case
}

static int8_t adv_sch_stt(int8_t sch_stt, int32_t cur_chr, ResultSchema *rlt_sch) {
  switch (sch_stt) {
    case SCH_STT_FRZ:
      break;
    case 0:
      return handle_state_0(cur_chr, rlt_sch);
    case 1:
      // handle state 1...
    // other cases...
    default:
      *rlt_sch = RS_STRING;
      return SCH_STT_FRZ;
  }
  if (cur_chr != '\r' && cur_chr != '\n' && cur_chr != ' ' && cur_chr != 0) *rlt_sch = RS_STRING;
  return SCH_STT_FRZ;
}
resources/language-metavariables/tree-sitter-yaml/schema/json/src/parser.c (3)

7-16: Ensure Consistency in Macro Definitions.

The macro definitions for various constants like LANGUAGE_VERSION, STATE_COUNT, etc., should be documented to provide context for their values.

- #define LANGUAGE_VERSION 14
+ // Version of the language grammar
+ #define LANGUAGE_VERSION 14

18-24: Symbol Identifiers Enumeration.

The enumeration ts_symbol_identifiers defines symbol identifiers for the parser. Ensure that these symbols are consistent with the grammar definitions and are well-documented.

- enum ts_symbol_identifiers {
+ // Enumeration for symbol identifiers
+ enum ts_symbol_identifiers {

26-33: Document Symbol Names Array.

The ts_symbol_names array maps symbol identifiers to their string representations. Adding a comment to explain this mapping can improve readability.

- static const char * const ts_symbol_names[] = {
+ // Mapping of symbol identifiers to their string representations
+ static const char * const ts_symbol_names[] = {
CONTRIBUTING.md (2)

65-67: Specify Language for Code Block.

Fenced code blocks should have a language specified for proper syntax highlighting.

- ```
+ ```bash
  node ./resources/edit_grammars.mjs yaml
Tools
Markdownlint

65-65: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


102-104: Avoid Bare URLs.

Use Markdown syntax to format URLs to avoid bare URLs and improve readability.

- LSP target languages list: https://github.com/getgrit/rewriter/pull/7734/files#diff-f9d4f097b08d33241c5c8d15a2fbde0e37086c265ce0eba8decac20d5cd989c6R23
- VS Code client list: https://github.com/getgrit/rewriter/blob/f992490394a4807789504f1cea6a04b934ad3b24/apps/poolish/src/lsp-client.ts
- VS Code command palette triggers: https://github.com/getgrit/rewriter/pull/7734/files#diff-b38f1d6304993a250903310722206e6c89c58c52c2d1bd4b6fdd8f7218810570R103
+ [LSP target languages list](https://github.com/getgrit/rewriter/pull/7734/files#diff-f9d4f097b08d33241c5c8d15a2fbde0e37086c265ce0eba8decac20d5cd989c6R23)
+ [VS Code client list](https://github.com/getgrit/rewriter/blob/f992490394a4807789504f1cea6a04b934ad3b24/apps/poolish/src/lsp-client.ts)
+ [VS Code command palette triggers](https://github.com/getgrit/rewriter/pull/7734/files#diff-b38f1d6304993a250903310722206e6c89c58c52c2d1bd4b6fdd8f7218810570R103)
Tools
Markdownlint

102-102: null
Bare URL used

(MD034, no-bare-urls)


103-103: null
Bare URL used

(MD034, no-bare-urls)


104-104: null
Bare URL used

(MD034, no-bare-urls)

resources/language-metavariables/tree-sitter-yaml/schema/core/src/tree_sitter/parser.h (1)

3-6: Document C++ Compatibility Macros.

Add comments to explain the purpose of the extern "C" block for C++ compatibility.

- #ifdef __cplusplus
+ // Ensure C++ compatibility
+ #ifdef __cplusplus

Comment on lines +334 to +338
`${METAVARIABLE_GRAMMARS_DIR}/${language}-metavariable-scanner.c`,
`${tsLangDir}/src/scanner.c`
);
await buildSimpleLanguage(log, language);
await copyMyBuild("c", language);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure proper handling of YAML language build steps.

The steps for copying the scanner file and building the language are correctly defined. Consider adding error handling for the file copy and build operations to improve robustness.

  try {
    await fs.copyFile(
      `${METAVARIABLE_GRAMMARS_DIR}/${language}-metavariable-scanner.c`,
      `${tsLangDir}/src/scanner.c`
    );
    await buildSimpleLanguage(log, language);
    await copyMyBuild("c", language);
  } catch (error) {
    log(`Error handling YAML language build steps:`, error);
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
`${METAVARIABLE_GRAMMARS_DIR}/${language}-metavariable-scanner.c`,
`${tsLangDir}/src/scanner.c`
);
await buildSimpleLanguage(log, language);
await copyMyBuild("c", language);
try {
await fs.copyFile(
`${METAVARIABLE_GRAMMARS_DIR}/${language}-metavariable-scanner.c`,
`${tsLangDir}/src/scanner.c`
);
await buildSimpleLanguage(log, language);
await copyMyBuild("c", language);
} catch (error) {
log(`Error handling YAML language build steps:`, error);
}

Comment on lines +95 to +101
let from = `${METAVARIABLE_GRAMMARS_DIR}/${lang}-metavariable-grammar.js`;
let to = path.join(
LANGUAGE_METAVARIABLES_DIR,
`tree-sitter-${dest ?? lang}/grammar.js`
);
await fs.copyFile(from, to);
console.log(`Copied ${from} to ${to}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure path definitions are correct and handle potential errors.

The paths for source and destination are defined correctly. However, it is good practice to handle potential errors during the file copy operation to improve robustness.

  let from = `${METAVARIABLE_GRAMMARS_DIR}/${lang}-metavariable-grammar.js`;
  let to = path.join(
    LANGUAGE_METAVARIABLES_DIR,
    `tree-sitter-${dest ?? lang}/grammar.js`
  );
  try {
    await fs.copyFile(from, to);
    console.log(`Copied ${from} to ${to}`);
  } catch (error) {
    console.error(`Failed to copy ${from} to ${to}:`, error);
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let from = `${METAVARIABLE_GRAMMARS_DIR}/${lang}-metavariable-grammar.js`;
let to = path.join(
LANGUAGE_METAVARIABLES_DIR,
`tree-sitter-${dest ?? lang}/grammar.js`
);
await fs.copyFile(from, to);
console.log(`Copied ${from} to ${to}`);
let from = `${METAVARIABLE_GRAMMARS_DIR}/${lang}-metavariable-grammar.js`;
let to = path.join(
LANGUAGE_METAVARIABLES_DIR,
`tree-sitter-${dest ?? lang}/grammar.js`
);
try {
await fs.copyFile(from, to);
console.log(`Copied ${from} to ${to}`);
} catch (error) {
console.error(`Failed to copy ${from} to ${to}:`, error);
}


namespace tree_sitter_yaml {
#define SCH_STT_FRZ -1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use const for defining constants.

Defining SCH_STT_FRZ as a constant improves readability and prevents accidental modifications.

- #define SCH_STT_FRZ -1
+ const int8_t SCH_STT_FRZ = -1;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#define SCH_STT_FRZ -1
const int8_t SCH_STT_FRZ = -1;

Comment on lines +5 to +11
typedef enum {
RS_STR,
RS_INT,
RS_NUL,
RS_BOL,
RS_FLT,
};
RS_NULL,
RS_BOOL,
RS_FLOAT,
} ResultSchema;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enum Naming Consistency.

The enum values RS_NULL, RS_BOOL, and RS_FLOAT should be consistent with the existing naming convention. Consider renaming RS_STR and RS_INT to RS_STRING and RS_INTEGER for better readability and consistency.

- RS_STR,
- RS_INT,
+ RS_STRING,
+ RS_INTEGER,
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
typedef enum {
RS_STR,
RS_INT,
RS_NUL,
RS_BOL,
RS_FLT,
};
RS_NULL,
RS_BOOL,
RS_FLOAT,
} ResultSchema;
typedef enum {
RS_STRING,
RS_INTEGER,
RS_NULL,
RS_BOOL,
RS_FLOAT,
} ResultSchema;

Comment on lines +6 to +10
type ChildNode = {
multiple: boolean;
required: boolean;
types: BaseNode[];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define ChildNode as an interface.

Defining ChildNode as an interface instead of a type may provide better flexibility and clarity.

-  type ChildNode = {
+  interface ChildNode {
    multiple: boolean;
    required: boolean;
    types: BaseNode[];
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type ChildNode = {
multiple: boolean;
required: boolean;
types: BaseNode[];
};
interface ChildNode {
multiple: boolean;
required: boolean;
types: BaseNode[];
}

Comment on lines +12 to +19
type NodeInfo =
| (BaseNode & {
subtypes: BaseNode[];
})
| (BaseNode & {
fields: { [name: string]: ChildNode };
children: ChildNode[];
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define NodeInfo as an interface.

Defining NodeInfo as an interface instead of a type may provide better flexibility and clarity.

-  type NodeInfo =
+  interface NodeInfoBase extends BaseNode {
+    subtypes?: BaseNode[];
+    fields?: { [name: string]: ChildNode };
+    children?: ChildNode[];
+  }
+  type NodeInfo = NodeInfoBase;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type NodeInfo =
| (BaseNode & {
subtypes: BaseNode[];
})
| (BaseNode & {
fields: { [name: string]: ChildNode };
children: ChildNode[];
});
interface NodeInfoBase extends BaseNode {
subtypes?: BaseNode[];
fields?: { [name: string]: ChildNode };
children?: ChildNode[];
}
type NodeInfo = NodeInfoBase;

Comment on lines +1 to +4
type BaseNode = {
type: string;
named: boolean;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define BaseNode as an interface.

Defining BaseNode as an interface instead of a type may provide better flexibility and clarity.

-  type BaseNode = {
+  interface BaseNode {
    type: string;
    named: boolean;
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type BaseNode = {
type: string;
named: boolean;
};
interface BaseNode {
type: string;
named: boolean;
}

Comment on lines +21 to +25
type Language = {
name: string;
language: unknown;
nodeTypeInfo: NodeInfo[];
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define Language as an interface.

Defining Language as an interface instead of a type may provide better flexibility and clarity.

-  type Language = {
+  interface Language {
    name: string;
    language: unknown;
    nodeTypeInfo: NodeInfo[];
  }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type Language = {
name: string;
language: unknown;
nodeTypeInfo: NodeInfo[];
};
interface Language {
name: string;
language: unknown;
nodeTypeInfo: NodeInfo[];
}

Comment on lines +86 to +172
static bool ts_lex(TSLexer *lexer, TSStateId state) {
START_LEXER();
eof = lexer->eof(lexer);
switch (state) {
case 0:
if (eof) ADVANCE(13);
if (lookahead == '-') ADVANCE(1);
if (lookahead == '0') ADVANCE(16);
if (lookahead == 'f') ADVANCE(2);
if (lookahead == 'n') ADVANCE(10);
if (lookahead == 't') ADVANCE(7);
if (('1' <= lookahead && lookahead <= '9')) ADVANCE(17);
END_STATE();
case 1:
if (lookahead == '0') ADVANCE(16);
if (('1' <= lookahead && lookahead <= '9')) ADVANCE(17);
END_STATE();
case 2:
if (lookahead == 'a') ADVANCE(4);
END_STATE();
case 3:
if (lookahead == 'e') ADVANCE(15);
END_STATE();
case 4:
if (lookahead == 'l') ADVANCE(8);
END_STATE();
case 5:
if (lookahead == 'l') ADVANCE(14);
END_STATE();
case 6:
if (lookahead == 'l') ADVANCE(5);
END_STATE();
case 7:
if (lookahead == 'r') ADVANCE(9);
END_STATE();
case 8:
if (lookahead == 's') ADVANCE(3);
END_STATE();
case 9:
if (lookahead == 'u') ADVANCE(3);
END_STATE();
case 10:
if (lookahead == 'u') ADVANCE(6);
END_STATE();
case 11:
if (lookahead == '+' ||
lookahead == '-') ADVANCE(12);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(19);
END_STATE();
case 12:
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(19);
END_STATE();
case 13:
ACCEPT_TOKEN(ts_builtin_sym_end);
END_STATE();
case 14:
ACCEPT_TOKEN(sym_null);
END_STATE();
case 15:
ACCEPT_TOKEN(sym_bool);
END_STATE();
case 16:
ACCEPT_TOKEN(sym_int);
if (lookahead == '.') ADVANCE(18);
if (lookahead == 'E' ||
lookahead == 'e') ADVANCE(11);
END_STATE();
case 17:
ACCEPT_TOKEN(sym_int);
if (lookahead == '.') ADVANCE(18);
if (lookahead == 'E' ||
lookahead == 'e') ADVANCE(11);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(17);
END_STATE();
case 18:
ACCEPT_TOKEN(sym_float);
if (lookahead == 'E' ||
lookahead == 'e') ADVANCE(11);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(18);
END_STATE();
case 19:
ACCEPT_TOKEN(sym_float);
if (('0' <= lookahead && lookahead <= '9')) ADVANCE(19);
END_STATE();
default:
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lexing Function Complexity.

The ts_lex function has multiple case statements to handle different lexing states. Consider breaking it down into smaller functions for each state to improve readability and maintainability.

static bool lex_state_0(TSLexer *lexer) {
  if (eof) ADVANCE(13);
  if (lookahead == '-') ADVANCE(1);
  // other conditions...
  return false; // default case
}

static bool ts_lex(TSLexer *lexer, TSStateId state) {
  START_LEXER();
  eof = lexer->eof(lexer);
  switch (state) {
    case 0:
      return lex_state_0(lexer);
    // other cases...
    default:
      return false;
  }
}

Committable suggestion was skipped due to low confidence.

Comment on lines +133 to +149
static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
uint32_t index = 0;
uint32_t size = len - index;
while (size > 1) {
uint32_t half_size = size / 2;
uint32_t mid_index = index + half_size;
TSCharacterRange *range = &ranges[mid_index];
if (lookahead >= range->start && lookahead <= range->end) {
return true;
} else if (lookahead > range->end) {
index = mid_index;
}
size -= half_size;
}
TSCharacterRange *range = &ranges[index];
return (lookahead >= range->start && lookahead <= range->end);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve Readability of set_contains Function.

The set_contains function can be simplified for better readability and performance.

static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
  for (uint32_t i = 0; i < len; i++) {
    if (lookahead >= ranges[i].start && lookahead <= ranges[i].end) {
      return true;
    }
  }
  return false;
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
uint32_t index = 0;
uint32_t size = len - index;
while (size > 1) {
uint32_t half_size = size / 2;
uint32_t mid_index = index + half_size;
TSCharacterRange *range = &ranges[mid_index];
if (lookahead >= range->start && lookahead <= range->end) {
return true;
} else if (lookahead > range->end) {
index = mid_index;
}
size -= half_size;
}
TSCharacterRange *range = &ranges[index];
return (lookahead >= range->start && lookahead <= range->end);
}
static inline bool set_contains(TSCharacterRange *ranges, uint32_t len, int32_t lookahead) {
for (uint32_t i = 0; i < len; i++) {
if (lookahead >= ranges[i].start && lookahead <= ranges[i].end) {
return true;
}
}
return false;
}

@morgante morgante merged commit f1dedc0 into main Jul 10, 2024
9 of 12 checks passed
@morgante morgante deleted the switch-yaml branch July 10, 2024 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant