1.1.0 • Published 1 year ago

@hurx/textmate-grammar-builder v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Textmate grammar builder

A fully typed, documented and easy to use textmate language grammar builder in Typescript by Hurx (Stan Hurks) 📧

The documentation and example should give you a basic understanding on how to create a language grammar with text mate.

Example

import path from "path"
import Grammar from "@hurx/textmate-grammar-builder"

// Provide a union type of repository names
type RepositoryNames = 'string'

// Provide a union type of pattern names
type PatternNames = `${
    `constant${
        `.character${
            `.escape`
        }`
    }`|
    `punctuation${
        `.definition${
            `.string${
                `.begin`|
                `.end`|
                `.template${
                    `.begin`|
                    `.end`
                }`
            }`
        }`
    }`|
    `string${
        `.quoted${
            `.double`
        }`|
        `.template`
    }`
}.language-name`

// Make the grammar
Grammar

// Declare the name and included repositories/patterns in the root of your grammar
.root<RepositoryNames, PatternNames>('language-name', '#string')

// Adds a repository to match strings
.repository('string',
    {
        name: 'string.quoted.double.language-name',
        begin: [
            /\"/
        ],
        beginCaptures: {
            1: 'punctuation.definition.string.begin.language-name'
        },
        end: [
            /\"/
        ],
        endCaptures: {
            1: 'punctuation.definition.string.end.language-name'
        },
        children: [
            {
                name: 'constant.character.escape.language-name',
                match: [
                    /\\\"/
                ]
            }
        ]
    },
    {
        name: 'string.template.language-name',
        begin: [
            /\`/
        ],
        beginCaptures: {
            1: 'punctuation.definition.string.template.begin.language-name'
        },
        end: [
            /\`/
        ],
        endCaptures: {
            1: 'punctuation.definition.string.template.end.language-name'
        },
        children: [
            {
                name: 'constant.character.escape.language-name',
                match: [
                    /\\\`/
                ]
            }
        ]
    }
)

// Builds the grammar at the path: /[project root]/language/grammars/[name].tmLanguage.json
.build(path.resolve('./language', 'grammars'))

Made with ♥️

Buying me a coffee ☕ contributes to making easy to use and efficient software tools and products for free!

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago