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.9.0.tar.gz (8.9 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.9.0-cp38-abi3-win_arm64.whl (2.5 MB view details)

Uploaded CPython 3.8+Windows ARM64

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

Uploaded CPython 3.8+Windows x86-64

tree_sitter_objectscript-1.9.0-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.9.0-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.9.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.8+macOS 11.0+ ARM64

tree_sitter_objectscript-1.9.0-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.9.0.tar.gz.

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.0.tar.gz
Algorithm Hash digest
SHA256 350e68c01f5eaaf5c6315a4e03bd42fab1371a3e072109dd3def1d6d7d3a1862
MD5 c04871ae918d5594b312d922046276ed
BLAKE2b-256 0c9e552048e93755e6cb780c1f44215e6ae4d0b4cb2e7efa94bce58522112331

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.0-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 48da35aebaaee267ca6833a7ef602bfa3ee0680a5ba9bde670fc7e394ac265bd
MD5 7cf07864ee29f37b1c2a32bdafe0389d
BLAKE2b-256 e2bc368235e3962aa86e7531066da1be73e244f4ec72bc51c22ccd13d44465b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b5771eaf24a17497e14a7d16976e61febaecc3c6eeccdbf628f48a5881d3bdfc
MD5 1ab89e25b45ee6f4946866cbe693d399
BLAKE2b-256 8448dc0fbd0a75526d3a42a7c72c0a768cddacf9a25ed15fdf048f3a2fa9736d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.0-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 148f5ade6b1b4eb13c2aa69d5ac8ee140e42a6abf8430ec21d11773fed72e1f1
MD5 d61df8f8fab48d03915259e46dd04395
BLAKE2b-256 b5b5eb34c6fd615aa218f9ce6023a27f46b37af799811adc10aa6419a8cc7c9a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 647ffbb4629da04dea42c1c3480dc5117aaaddfea2af9ab3ba3dc2b692daa743
MD5 a6622ff69e8d3625662261f8584063ee
BLAKE2b-256 e88ca3e98aced62e6985783271c0f117af7ae1c2cac63b8234f7a1a6d85a303c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6b34baf4cc9b9e8e479b0514c13a0e17e4d4ce09daffc169b56215e1d8a5e566
MD5 417b009b8144e52502806f20a2552c6f
BLAKE2b-256 fa6b65f50d8654528b84d7a4f4ba1f71d27806c6d3b339d734201977a8424c49

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2786bc3c3d762e209689daace76173a3920597b98189230403cf480dee32ea0d
MD5 1132f9b3ad0dcbef57e1adc5900c9fd4
BLAKE2b-256 7f4f4f81e6e2bfe49b84b9dfcd91ed44c84ca1381731782dea9e08344b335e36

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.0-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 734cbd37acdd4b3461b98ed6aa7b549c4475c5d543e9eefffc4c732813657a6b
MD5 621effe6dce4ff1fb9100046123d1d6d
BLAKE2b-256 6a283122dfdeef62eb77143aa6bde1c085d964a32ed5817597f8449f5bb669ee

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