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

Update keywords #2

Open
fubark opened this issue Dec 9, 2023 · 1 comment
Open

Update keywords #2

fubark opened this issue Dec 9, 2023 · 1 comment

Comments

@fubark
Copy link

fubark commented Dec 9, 2023

I was going to update the keywords to reflect this: https://fubark.github.io/cyber/docs/toc/syntax/#keywords but then couldn't find a single source to edit/add keywords. I'm assuming its grammar.js but it's still not obvious where. Would be nice to have some instructions on how to test out the generated grammars.

@instance-id
Copy link
Owner

Yeah, unfortunately there can be a few places in which they need to be updated depending on how they are used.

For the most part, they must first exist in grammar.js (either for use in the active syntax rules, or queries for highlights and the like) The bottom of grammar.js is where a general listing of them are, then in queries/highlights.scm is where they are assigned their highlight type.

Testing and building is done using Just (a general purpose 'Make', with less headaches) and Powershell Core (with the idea of having it be cross-platform, though I have only tested things on Linux) which will call into scripts/build_steps.ps1

I will update the readme with a list of requirements, but they are:
Needed:
tree-sitter-cli

Helpful:
Just
Powershell (Mostly for the testing aspect)

With those in place, from the repo root I run:
(Since it was only ever just me, I might need to clean it up a bit, I believe there is a script dependency on wl_copy)

The commands all build first, by calling tree-sitter generate

For single files:
just test /mnt/x/GitHub/fubark/cyber/test/bench/fib/fib.cy

All .cy files in 'fubark/cyber/test'
(Top of scripts/build_steps.ps1 : I have set $testFolder = "/mnt/x/GitHub/fubark/cyber/test")
just test-all # Calls RunTestAll() in scripts/build_steps.ps1
This gives feedback on the parse tests:

zsh ❯ just test-all
Testing parser
Parser Test Successful

Parsing Test Scripts
Passed: ✓ /mnt/x/GitHub/fubark/cyber/test/arc_cases_test.cy
Passed: ✓ /mnt/x/GitHub/fubark/cyber/test/arithmetic_op_test.cy
Passed: ✓ /mnt/x/GitHub/fubark/cyber/test/astring_slice_test.cy
Passed: ✓ /mnt/x/GitHub/fubark/cyber/test/astring_test.cy
Passed: ✓ /mnt/x/GitHub/fubark/cyber/test/bitwise_op_test.cy

Though, without Just or Pwsh, you can just run the following to test out the parsing of a script:

CYBER_TREE_SITTER_DEBUG=true tree-sitter generate && tree-sitter parse </path/to/cyber_script.cy>

zsh >   CYBER_TREE_SITTER_DEBUG=true tree-sitter generate && tree-sitter parse /mnt/x/GitHub/fubark/cyber/test/bench/fib/fib.cy
(source_file [0, 0] - [5, 0]
  (function_definition [0, 0] - [3, 34]
    (function_declaration [0, 5] - [0, 15]
      name: (identifier [0, 5] - [0, 8])
      parameters: (typed_parameter [0, 9] - [0, 14]
        name: (identifier [0, 9] - [0, 10])
        type: (_identifier [0, 11] - [0, 14])))
    return_type: (type_identifier [0, 16] - [0, 19])
    body: (block [0, 20] - [3, 34]
      (if_statement [1, 4] - [2, 16]
        condition: (comparison_operator [1, 7] - [1, 12]
          left: (identifier [1, 7] - [1, 8])
          right: (numeric_literal [1, 11] - [1, 12]))
        body: (block [1, 13] - [2, 16]
          (return_statement [2, 8] - [2, 16]
            (identifier [2, 15] - [2, 16]))))
      (return_statement [3, 4] - [3, 34]
        (binary_operator [3, 11] - [3, 34]
          left: (parameter [3, 11] - [3, 21]
            (call_expression [3, 11] - [3, 21]
              name: (identifier [3, 11] - [3, 14])
              (parameter [3, 15] - [3, 20]
                (binary_operator [3, 15] - [3, 20]
                  left: (parameter [3, 15] - [3, 16]
                    name: (identifier [3, 15] - [3, 16]))
                  right: (parameter [3, 19] - [3, 20]
                    (numeric_literal [3, 19] - [3, 20]))))))
          right: (parameter [3, 24] - [3, 34]
            (call_expression [3, 24] - [3, 34]
              name: (identifier [3, 24] - [3, 27])
              (parameter [3, 28] - [3, 33]
                (binary_operator [3, 28] - [3, 33]
                  left: (parameter [3, 28] - [3, 29]
                    name: (identifier [3, 28] - [3, 29]))
                  right: (parameter [3, 32] - [3, 33]
                    (numeric_literal [3, 32] - [3, 33]))))))))))
  (print_statement [4, 0] - [4, 14]
    (parenthesized_expression [4, 5] - [4, 14]
      (call_expression [4, 6] - [4, 13]
        name: (identifier [4, 6] - [4, 9])
        (parameter [4, 10] - [4, 12]
          (numeric_literal [4, 10] - [4, 12]))))))

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

No branches or pull requests

2 participants