npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

tree-sitter-scpi

v0.1.4

Published

Tree-sitter grammar for SCPI (Standard Commands for Programmable Instruments)

Readme

tree-sitter-scpi

Tree-sitter grammar for SCPI (Standard Commands for Programmable Instruments).

Overview

This grammar provides syntax parsing for SCPI commands used in programmable instruments. It supports:

  • Common commands: Asterisk-prefixed commands like *IDN?, *RST
  • Hierarchical commands: Colon-separated command paths like :MEASure:VOLTage?
  • Query commands: Commands ending with ?
  • Command parameters: Numeric values, strings, and enumerated values
  • Command chaining: Multiple commands separated by semicolons

Installation

npm install

Building

Generate the parser from the grammar:

npm run generate

Or using tree-sitter CLI directly:

tree-sitter generate

Building WASM

To build the WebAssembly version for use in VS Code extensions or web applications:

npm run build-wasm

This generates tree-sitter-scpi.wasm in the root directory. The WASM file is automatically built before publishing to npm.

Testing

Run the test suite:

npm test

Or using tree-sitter CLI directly:

tree-sitter test

Grammar Structure

Command Types

Common Commands

Common commands start with an asterisk (*) and may include a query marker (?):

*IDN?
*RST
*OPC?

Hierarchical Commands

Hierarchical commands use colons (:) to separate command nodes. The leading colon is optional:

:MEASure:VOLTage?
MEASure:VOLTage?
:SYSTem:COMMunicate:SERial:BAUD 9600

Parameters

Commands can include parameters separated by commas:

  • Numbers: 5.0, -10, 1.5e3, 0.001
  • Strings: "192.168.1.100", "AUTO"
  • Enumerations: EXTernal, INTernal, AUTO

Example:

:MEASure:VOLTage:DC? 10,0.001
:SYSTem:COMMunicate:LAN:IPADdress "192.168.1.100"
:TRIGger:SOURce EXTernal

Command Chaining

Multiple commands can be chained on a single line using semicolons:

*IDN?;*RST
:MEASure:VOLTage?;:SOURce:VOLTage 5.0

Example Usage

Node.js (Native Binding)

const Parser = require('tree-sitter');
const SCPI = require('tree-sitter-scpi');

const parser = new Parser();
parser.setLanguage(SCPI);

const sourceCode = `*IDN?
:MEASure:VOLTage?
:SOURce:VOLTage 5.0`;

const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());

WebAssembly (for VS Code Extensions and Web)

For VS Code extensions or web applications, use the WASM version with web-tree-sitter:

const Parser = require('web-tree-sitter');

async function initializeParser() {
  await Parser.init();
  const SCPI = await Parser.Language.load(
    require.resolve('tree-sitter-scpi/tree-sitter-scpi.wasm')
  );
  const parser = new Parser();
  parser.setLanguage(SCPI);
  return parser;
}

// Usage
initializeParser().then(parser => {
  const sourceCode = `*IDN?
:MEASure:VOLTage?
:SOURce:VOLTage 5.0`;
  
  const tree = parser.parse(sourceCode);
  console.log(tree.rootNode.toString());
});

Note: Make sure to install web-tree-sitter as a dependency in your project:

npm install web-tree-sitter

Grammar Rules

The grammar defines the following main rules:

  • program: Root node containing one or more commands
  • command: Individual SCPI command (common or hierarchical)
  • common_command: Asterisk-prefixed commands
  • hierarchical_command: Colon-separated command path
  • command_path: Sequence of command nodes separated by colons
  • command_node: Individual node in hierarchical path
  • query_marker: Optional ? at end of commands
  • parameter_list: Optional parameters following command
  • parameter: Individual parameter (number, string, or enumeration)
  • number: Numeric values (integers, floats, scientific notation)
  • string: Quoted string parameters
  • enumeration: Enumerated values (keywords)

License

MIT