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.

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.

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.13.tar.gz (7.5 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.13-cp38-abi3-win_arm64.whl (2.1 MB view details)

Uploaded CPython 3.8+Windows ARM64

tree_sitter_objectscript-1.9.13-cp38-abi3-win_amd64.whl (2.1 MB view details)

Uploaded CPython 3.8+Windows x86-64

tree_sitter_objectscript-1.9.13-cp38-abi3-musllinux_1_2_x86_64.whl (2.2 MB view details)

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

tree_sitter_objectscript-1.9.13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

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

tree_sitter_objectscript-1.9.13-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (2.4 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

tree_sitter_objectscript-1.9.13-cp38-abi3-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

tree_sitter_objectscript-1.9.13-cp38-abi3-macosx_10_9_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.8+macOS 10.9+ x86-64

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.13.tar.gz
Algorithm Hash digest
SHA256 1b544264a88d4743deb446a583ab4722b53c5d9701233a8a1c0df9bd0af93161
MD5 cfe358413dfa622a51cf85e2bf6dc0b0
BLAKE2b-256 96c0b0198fbc9d6048bdf4ec6c97a5d3369f7fb4ac57e657e237c2cc3ad97265

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.13-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 96d34ad2a08f1c5c8f1bfc74cb8863938ce35d9aa6d0da2cfe04f5749977efe0
MD5 8b6b70ee4f96f859f986852439c219dd
BLAKE2b-256 34609c405be2832a7e35f476989b6696a5cb084b4d337086211d8bb998e70b28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.13-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7f06c1643c578b63b1e1d94a1a34e862e0e39eaa7d8004b021deaeb5e7aca5fe
MD5 86f36ee4a3074eed0f92a14534e6a658
BLAKE2b-256 f2e2ea7b2e753f2b1587a0b858a93883beddd2e67b9521d3bb3776360a555dc1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.13-cp38-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 27b5d7f69aa12bbaff1ecd5b0babc6099d77d3b69c0b4b9ccec380b4afbcfca9
MD5 cf442e332a6b2b1de3dcbc433ed322ac
BLAKE2b-256 a52ea5af1611dd9eebd9d3f6b58722758092df32168a441058421257b8833d2d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 431efc5235b508d7ee3207ca8f7efc3f3dde19103346882a11c9c467a8c6c348
MD5 1206086d31eb05587bc27a7fd0d656f5
BLAKE2b-256 73a003d4f8df6d1cc6978c6e3b13629f1e16dbed2e086f0a5935f694cfe240fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.13-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 dd2a8dd9e719930b6f2507e5918f66444a1a2240083ef63c4aaf10559d9cc07c
MD5 5e4b13550134b5cd6729cb793cceaad0
BLAKE2b-256 4628a7f55ca6c4de8d97a6e0aa76f988ebe3254d2f4f8bc1d70a3548dea7adce

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.13-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f9f6e209027a59547a3b88d81f89a2bff4fc79aef964a63e56a280b0bbddc10
MD5 48b4338e5e0a54f204d767410cd02b6d
BLAKE2b-256 d9028c62aa8c5ceb77224775b1f4d3f8ba931f77afde9f0b94c90040ab54225c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tree_sitter_objectscript-1.9.13-cp38-abi3-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4b737f29429f624cb870d55a40e5df204fe50610c3615527b54a042a4a0f7fd6
MD5 d048c8f18b12f53d501497c3374e6542
BLAKE2b-256 00b0081d390152bd3cad876e088d813f6ebfabef26affc2031c81fb77d34c158

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