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

atom-syntax-tools

v0.9.1

Published

Tool for grammar specification with coffee script for atom languages

Readme

atom-syntax-tools

Tools for easier language grammar specification for atom editor.

  • This tool lets you define grammar in a coffeescript file and takes the input cson, and generates a full grammar cson.

  • Make use of syntax highlighting of javascript regular expressions, which will be used as Oniguruma Regexes. This way you do not need escape too much.

  • make use of macros in scopenames and regexes

  • grammar scopename is autoappended to scopenames

  • you can shortcut the keys like follows:

    | shortcut | name | | :------: | ---------------------- | | n | name | | N | contentName | | p | patterns | | i | include | | I | injections | | m | match | | b | begin | | e | end | | c | captures/beginCaptures | | C | endCaptures | | L | applyEndPatternLast |

Here a little example, how to produce json.cson file:

{makeGrammar, rule} = require('atom-syntax-tools')

grammar =
  name: "JSON"
  scopeName: "source.json"
  keyEquivalent: "^~J"
  fileTypes: [ "json" ]

  macros:
    # for demonstartion purpose, how to use regexes as macros
    hexdigit: /[0-9a-fA-F]/
    en: "entity.name"
    pd: "punctuation.definition"
    ps: "punctuation.separator"
    ii: "invalid.illegal"

  patterns: [
    "#value"
  ]

  repository:
    array:
      n: "meta.structure.array"
      b: /\[/
      c: "{pd}.array.begin"
      e: /\]/
      C: "{pd}.array.end"
      p: [
        "#value"

        rule
          m: /,/
          n: "{ps}.array"

        rule
          m: /[^\s\]]/
          n: "{ii}.expected-array-separator"

      ]
    constant:
      n: "constant.language"
      m: /\b(?:true|false|null)\b/
    number:
      # this comment is just for demonstration, you will rather use
      # normal coffee comments
      comment: "handles integer and decimal numbers"
      n: "constant.numeric"
      # This multiline match with be boiled down into a single linen regular
      # expression. See http://coffeescript.org
      m: ///
        -?        # an optional minus
        (?:
          0       # a zero
        |         # ...or...
          [1-9]   # a 1-9 character
          \d*     # followed by zero or more digits
        )
        (?:       # optional decimal portion
          (?:
            \.    # a period
            \d+   # followed by one or more digits
          )?
          (?:
            [eE]  # an e character
            [+-]? # followed by an optional +/-
            \d+   # followed by one of more digits
          )?      # make exponent optional
        )? ///

    object:
      # "a JSON object"
      n: "meta.structure.dictionary"
      b: /\{/
      c: "{pd}.dictionary.begin"
      e: /\}/
      C: "{pd}.dictionary.end"
      p: [
        "#string"   # JSON object key

        rule
          b: /:/
          c: "{ps}.dictionary.key-value"
          e: /(,)|(?=\})/
          C:
            1: "{ps}.dictionary.pair"
          n: "meta.structure.dictionary.value"
          p: [
            "#value" # JSON object value
            rule m: /[^\s,]/, n: "{ii}.expected-dictionary-separator"
          ]

        rule
          m: /[^\s\}]/
          n: "{ii}.expected-dictionary-separator"

      ]
    string:
      b: /"/
      c: "{pd}.string.begin"
      e: /"/
      C: "{pd}.definition.string.end"
      n: "string.quoted.double"
      p: [
        rule
          n: "constant.character.escape"
          m: ///
            \\               # literal backslash
            (?:              # ...followed by...
              ["\\/bfnrt]    # one of these characters
              |              # ...or...
              u              # a u
              {hexdigit}{4}  # and four hex digits
            ) ///
        rule
          m: /\\./
          n: "{ii}.unrecognized-string-escape"
        }
      ]
    value: [     # the 'value' diagram at http://json.org
      "#constant"
      "#number"
      "#string"
      "#array"
      "#object"
    ]

makeGrammar grammar, "CSON"

Then run your script with coffee grammar-json.coffee > json.cson

Or create grammar directly with

    {CompositeDisposable} = require 'atom'
    subscriptions = new CompositeDisposable
    subscriptions.add atom.grammars.createGrammar __filename, makeGrammar grammar

Here an example for a package code for a complete dynamical managed grammar:

{CompositeDisposable} = require 'atom'
grammar = require './my-grammar.coffee'

module.exports =
  activate: (state) ->
    @subscriptions = new CompositeDisposable
    @subscriptions.add atom.grammars.createGrammar __filename, makeGrammar grammar

  deactivate: ->
    @subscriptions.dispose()

  serialize: ->

Functions exported

makeGrammar grammar, [format | path]

Create and return a grammar object from input grammar grammar. If format given print a CSON or JSON string to STDOUT, if path given, write grammar to file. It can be a .json or .cson file.

makeWords {string | list}...

This will split all given strings at whitespace and return a list of strings. Given lists are taken returned unchanged

rule obj, makeRule obj

Return the obj. This is a convenience method for nicer separating rules in pattern lists.

escapeRegex string, escapeRegExp string

Escape special characters for use in regular expression.

makeRegexFromWords {string | list}...

arguments are processed by makeWords(). Then there is created an optimized regex from it like in following example:

makeRegexFromWords """
  STDIN
  STDOUT
  STDERR
"""
# returns "STD(?:ERR|IN|OUT)"

makeRegexFromWords """
  STDIN
  STDINOUT
  STDERR
  .OTHER
"""
# returns "(?:STD(?:ERR|IN(?:OUT)?)|\\.OTHER)"