Skip to main content

Objectscript grammar for tree-sitter

Project description

tree-sitter-objectscript

CI npm crates-udl crates-routine crates-playground pypi

Tree-sitter grammars for InterSystems ObjectScript.

Grammars

This repository publishes five related grammars:

  • objectscript: playground/snippet grammar.
  • objectscript_udl: class-file grammar for .cls.
  • objectscript_core: routine/statement grammar.
  • objectscript_expr: expression grammar.
  • objectscript_routine: routine-file grammar for .mac, .inc, .rtn, and .int.

Grammar extension graph: objectscript_expr -> objectscript_core -> objectscript_udl -> objectscript objectscript_expr -> objectscript_core -> objectscript_routine

Packages

  • npm: tree-sitter-objectscript
  • PyPI: tree-sitter-objectscript (ships tree_sitter_objectscript, tree_sitter_objectscript_udl, and tree_sitter_objectscript_routine)
  • Rust crates:
    • tree-sitter-objectscript (UDL grammar)
    • tree-sitter-objectscript-routine (routine grammar)
    • tree-sitter-objectscript-playground (playground grammar)

Bindings

Language bindings are available under bindings/:

  • C: bindings/c
  • Go: bindings/go
  • Node.js: bindings/node
  • Python: bindings/python
  • Rust: bindings/rust, bindings/rust-routine, and bindings/rust-playground
  • Swift: bindings/swift

Quick binding checks from repo root:

nvm use
npm ci
cargo test --lib --package tree-sitter-objectscript
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -U pip setuptools wheel pytest tree-sitter
python3 setup.py build_ext --inplace
PYTHONPATH=$PWD/bindings/python python3 -m pytest -q bindings/python/tests/test_binding.py
npm test
go test ./bindings/go/...
swift test
make test

The routine and playground Rust crates are staged from bindings/rust-routine and bindings/rust-playground via helper scripts. See CONTRIBUTING.md for the current local build workflow and the temporary studio-highlights.scm copy step those staged crates need today.

For Node bindings specifically, .nvmrc pins the expected Node version.

Quick Development

Install the tree-sitter CLI, then run commands from a grammar directory (objectscript, udl, core, expr, or objectscript_routine):

tree-sitter generate
tree-sitter test
tree-sitter build

For playground work:

tree-sitter build --wasm
tree-sitter playground

If you change an upstream grammar (expr or core), regenerate downstream grammars as needed (udl, objectscript, objectscript_routine).

Query Sync

scripts/sync_queries.py manages the canonical query trio for each grammar:

  • highlights.scm
  • indents.scm
  • injections.scm

It composes the layered query trees for core, udl, objectscript, and objectscript_routine, then mirrors those composed files into the Python binding query directories. studio-highlights.scm files are intentionally left out of that sync process and are maintained separately.

Corpus Sync

objectscript/test/corpus is treated as a synced corpus directory. On commit, the repository pre-commit hook:

  • Replaces objectscript/test/corpus contents with files from:
    • core/test/corpus
    • udl/test/corpus
    • objectscript_routine/test/corpus
  • Removes objectscript/test/corpus/invalid.txt
  • Removes objectscript/test/corpus/compiled-header.txt

Contributing

See CONTRIBUTING.md for setup, workflow, query sync, and binding test instructions.

References

Editor Integration

  • Zed On Zed, you can use tree-sitter-objectscript by downloading the InterSystems ObjectScript extension

  • Neovim We currently have a PR open with nvim-treesitter, and if that gets merged in, the setup process will be automated. However, this repo is currently archived, so for now do the following to setup the grammars in neovim:

    Step 1: Create ~/.config/nvim/lua/plugins/objectscript-treesitter.lua

    Add the following content to that file: IMPORTANT: Make sure to replace the revision section with the commit that you want.

    return {
    -- configure nvim-treesitter
    {
      "nvim-treesitter/nvim-treesitter",
      init = function()
        vim.filetype.add({
          extension = {
            cls = "objectscript_udl",
            mac = "objectscript_routine",
            inc = "objectscript_routine",
            int = "objectscript_routine",
            rtn = "objectscript_routine"
          },
        })
    
        vim.api.nvim_create_autocmd("FileType", {
          pattern = { "objectscript_udl", "objectscript_routine" },
          callback = function(args)
            vim.treesitter.start(args.buf)
          end,
        })
    
        vim.api.nvim_create_autocmd('User', { pattern = 'TSUpdate',
        callback = function()
        local parsers = require("nvim-treesitter.parsers")
    
          parsers.objectscript_udl = {
            install_info = {
              url = "https://github.com/intersystems/tree-sitter-objectscript",
              revision = "58450fe03f6fa51de38ac689fbf0af63f455494a", 
              location = "udl",
              queries = "udl/queries",
            }
          }
    
          parsers.objectscript = {
            install_info = {
              url = "https://github.com/intersystems/tree-sitter-objectscript",
              revision = "58450fe03f6fa51de38ac689fbf0af63f455494a", 
              location = "objectscript",
              queries = "objectscript/queries",
            }
          }
    
          parsers.objectscript_routine = {
            install_info = {
              url = "https://github.com/intersystems/tree-sitter-objectscript",
              revision = "58450fe03f6fa51de38ac689fbf0af63f455494a", 
              location = "objectscript_routine",
              queries = "objectscript_routine/queries",
            }
          }
        end})
      end,
    
        opts = function(_, opts)
          opts.ensure_installed = opts.ensure_installed or {}
          for _, lang in ipairs({ "objectscript_udl", "objectscript_routine", "objectscript" }) do
            if not vim.tbl_contains(opts.ensure_installed, lang) then
              table.insert(opts.ensure_installed, lang)
            end
          end
        end,
      },
    }
    

    Step 2: Create ~/.config/nvim/after/queries/xml/injections.scm

    Add the following content to that file:

    ;; extends
    
    (
      element
        (STag (Name) @_start_tag)
        (content (CDSect (CData) @injection.content))
        (ETag (Name) @_end_tag)
      (#eq? @_start_tag "Implementation")
      (#eq? @_end_tag "Implementation")
      (#set! injection.language "objectscript")
    )
    (
      element
        (STag (Name) @_start_tag)
        (content (CharData) @injection.content)
        (ETag (Name) @_end_tag)
      (#eq? @_start_tag "Implementation")
      (#eq? @_end_tag "Implementation")
      (#set! injection.language "objectscript")
    )
    

    Step 3: Create ~/.config/nvim/queries/xml/highlights.scm

    ;; XML declaration
    
    "xml" @keyword
    
    [ "version" "encoding" "standalone" ] @property
    
    (EncName) @string.special
    
    (VersionNum) @number
    
    [ "yes" "no" ] @boolean
    
    ;; Processing instructions
    
    (PI) @embedded
    
    (PI (PITarget) @keyword)
    
    ;; Element declaration
    
    (elementdecl
      "ELEMENT" @keyword
      (Name) @tag)
    
    (contentspec
      (_ (Name) @property))
    
    "#PCDATA" @type.builtin
    
    [ "EMPTY" "ANY" ] @string.special.symbol
    
    [ "*" "?" "+" ] @operator
    
    ;; Entity declaration
    
    (GEDecl
      "ENTITY" @keyword
      (Name) @constant)
    
    (GEDecl (EntityValue) @string)
    
    (NDataDecl
      "NDATA" @keyword
      (Name) @label)
    
    ;; Parsed entity declaration
    
    (PEDecl
      "ENTITY" @keyword
      "%" @operator
      (Name) @constant)
    
    (PEDecl (EntityValue) @string)
    
    ;; Notation declaration
    
    (NotationDecl
      "NOTATION" @keyword
      (Name) @constant)
    
    (NotationDecl
      (ExternalID
        (SystemLiteral (URI) @string.special)))
    
    ;; Attlist declaration
    
    (AttlistDecl
      "ATTLIST" @keyword
      (Name) @tag)
    
    (AttDef (Name) @property)
    
    (AttDef (Enumeration (Nmtoken) @string))
    
    (DefaultDecl (AttValue) @string)
    
    [
      (StringType)
      (TokenizedType)
    ] @type.builtin
    
    (NotationType "NOTATION" @type.builtin)
    
    [
      "#REQUIRED"
      "#IMPLIED"
      "#FIXED"
    ] @attribute
    
    ;; Entities
    
    (EntityRef) @constant
    
    ((EntityRef) @constant.builtin
    (#any-of? @constant.builtin
      "&" "<" ">" """ "'"))
    
    (CharRef) @constant
    
    (PEReference) @constant
    
    ;; External references
    
    [ "PUBLIC" "SYSTEM" ] @keyword
    
    (PubidLiteral) @string.special
    
    (SystemLiteral (URI) @markup.link)
    
    ;; Processing instructions
    
    (XmlModelPI "xml-model" @keyword)
    
    (StyleSheetPI "xml-stylesheet" @keyword)
    
    (PseudoAtt (Name) @property)
    
    (PseudoAtt (PseudoAttValue) @string)
    
    ;; Doctype declaration
    
    (doctypedecl "DOCTYPE" @keyword)
    
    (doctypedecl (Name) @type)
    
    ;; Tags
    
    (STag (Name) @tag)
    
    (ETag (Name) @tag)
    
    (EmptyElemTag (Name) @tag)
    
    ;; Attributes
    
    (Attribute (Name) @property)
    
    (Attribute (AttValue) @string)
    
    ;; Delimiters & punctuation
    
    [
    "<?" "?>"
    "<!" "]]>"
    "<" ">"
    "</" "/>"
    ] @punctuation.delimiter
    
    [ "(" ")" "[" "]" ] @punctuation.bracket
    
    [ "\"" "'" ] @punctuation.delimiter
    
    [ "," "|" "=" ] @operator
    
    ;; Text
    
    (CharData) @markup
    
    (
      element
        (STag (Name) @_start_tag)
        (content (CDSect (CData) @injection.content))
        (ETag (Name) @_end_tag)
      (#eq? @_start_tag "Implementation")
      (#eq? @_end_tag "Implementation")
      (#set! priority 90)
    )
    
    (
      element
        (STag (Name) @_start_tag)
        (content (CharData) @injection.content)
        (ETag (Name) @_end_tag)
      (#eq? @_start_tag "Implementation")
      (#eq? @_end_tag "Implementation")
      (#set! priority 90)
    )
    
    (CDSect
      (CDStart) @markup.heading
      (CData) @markup.raw
      "]]>" @markup.heading)
    
    ;; Misc
    
    (Comment) @comment
    
    (ERROR) @error
    

    Step 4: Remove cached data from nvim if necessary (if previously installed)

    rm -rf ~/.local/share/nvim/site/parser \
      ~/.local/share/nvim/site/parser-info \
      ~/.local/share/nvim/site/queries
    

    Step 5: Open Neovim and Install objectscript_udl, objectscript_routine, and objectscript

    :TSInstall objectscript_udl objectscript_routine objectscript
    

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_objectscript-1.8.5.tar.gz (8.8 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tree_sitter_objectscript-1.8.5-cp38-abi3-win_arm64.whl (2.5 MB view details)

Uploaded CPython 3.8+Windows ARM64

tree_sitter_objectscript-1.8.5-cp38-abi3-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.8+Windows x86-64

tree_sitter_objectscript-1.8.5-cp38-abi3-musllinux_1_2_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8+musllinux: musl 1.2+ x86-64

tree_sitter_objectscript-1.8.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

tree_sitter_objectscript-1.8.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

tree_sitter_objectscript-1.8.5-cp38-abi3-macosx_11_0_arm64.whl (2.9 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

tree_sitter_objectscript-1.8.5-cp38-abi3-macosx_10_9_x86_64.whl (2.5 MB view details)

Uploaded CPython 3.8+macOS 10.9+ x86-64

File details

Details for the file tree_sitter_objectscript-1.8.5.tar.gz.

File metadata

  • Download URL: tree_sitter_objectscript-1.8.5.tar.gz
  • Upload date:
  • Size: 8.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for tree_sitter_objectscript-1.8.5.tar.gz
Algorithm Hash digest
SHA256 f7ed322b982222f587b25569b2ac38eba1c2f9592acb0b999f9e9a239ba39c11
MD5 e0c51bb4072984626a0da726c5183a56
BLAKE2b-256 02647a412b7091a6934893d283601b2385469e11d530ecc40593042a3ca8ac6e

See more details on using hashes here.

File details

Details for the file tree_sitter_objectscript-1.8.5-cp38-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.8.5-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 3a20ba1d6949c9dfb4a8f962c868262fc7f109fa846e5e95f9aca09d3cc1c236
MD5 5a65d4171b4a6e6bb5c1ff9a09c36831
BLAKE2b-256 eb7f5a9e83c26af78666447451e809d07b559e4139062af9fe1147386a521fa0

See more details on using hashes here.

File details

Details for the file tree_sitter_objectscript-1.8.5-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.8.5-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f401c3791fe504bcbea1160ced399c8ed3e6bb3c844444ce04e8a4928ff04ee2
MD5 65fb1d14b3cd7ea0c30627b43d00f5b1
BLAKE2b-256 7cb0b93b99d115e30e51180229be8696cbbb03f8e7ca021fd02f501d5ee5151d

See more details on using hashes here.

File details

Details for the file tree_sitter_objectscript-1.8.5-cp38-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.8.5-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d4b38c2cc417cc372000b9d6f86d1411518f4aba26bf708f91d201b8f6908242
MD5 1720041972f77d3d0c40248dfa398f68
BLAKE2b-256 4bbf95f437489b2c628ec1b2735c6e82fa0042a82340a4f0e555016aa4a444a0

See more details on using hashes here.

File details

Details for the file tree_sitter_objectscript-1.8.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.8.5-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2ac0c9d7df1a6c0dda41b5f00c1a99dac9add4054648cf738b4038709edad99e
MD5 378e77f5408aa506562919016e91cc22
BLAKE2b-256 f63fb292272de471aa3e9394933d47b6d2fb6e2acad325bcc4d6dfcda8dab4bb

See more details on using hashes here.

File details

Details for the file tree_sitter_objectscript-1.8.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.8.5-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 375f2594025d14ff16c414c305ceae5fc1f74f333ca416df8f32f8927623f80d
MD5 04786c8bb601c17ebf7e8f70b0fdfa90
BLAKE2b-256 4640a8f9bdf22a56cf8c229b16e79b9976e96738a8f0b1b0333d8102b54da3e9

See more details on using hashes here.

File details

Details for the file tree_sitter_objectscript-1.8.5-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.8.5-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ee05b05be52c9f6bf1ce8a9ae740e97db26d0ddbab42f7b3798027fb5d09a52e
MD5 fe32b2436d7bbed89ecac449f27267c6
BLAKE2b-256 508434a918962e38dbed6384fe968617d858a1030f1fb14ae1cd7eac621c2fcc

See more details on using hashes here.

File details

Details for the file tree_sitter_objectscript-1.8.5-cp38-abi3-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.8.5-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 3719faee3b1d8e422e335beb5713883b7a46a3211267bab289e8dfc7973eb525
MD5 82540e99f989c81eda70e177202cc401
BLAKE2b-256 78f78f15af0cef419e90d2bd9a1e363f79557c0192003d8e20cba517554e10d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page