Skip to content

(MIRROR) Utils for working with Lezer grammars

License

Notifications You must be signed in to change notification settings

mattmundell/lezer-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Utils for working with Lezer grammars.

Requirements

Your grammar package must export your LRLanguage as lr, and your support function as language.

export const zigLanguage = LRLanguage.define({ ... })
export function zig() {
  return new LanguageSupport(zigLanguage)
}

// You'll probably need to add something like this.
export const lr = zigLanguage
export const language = zig

Examples

Check a dir

In your grammar package, add bin/chk containing this:

#!/usr/bin/env node
import { mainChk } from 'lezer-utils'
import { lr } from '../dist/index.js'
mainChk(lr)

then use chk to test the parser against a dir:

$ ./bin/chk -r ~/src/zig/src/link/tapi/ --ext zig
Checking /home/you/src/zig/src/link/tapi/
/home/you/src/zig/src/link/tapi/Tokenizer.zig 13087
/home/you/src/zig/src/link/tapi/parse.zig 23795
/home/you/src/zig/src/link/tapi/yaml.zig 17604
/home/you/src/zig/src/link/tapi/parse/test.zig 23445
/home/you/src/zig/src/link/tapi/yaml/test.zig 12873

ALL GOOD

Print a tree

In your grammar package, add bin/show containing this:

#!/usr/bin/env node
import { mainShow } from 'lezer-utils'
import { lr } from '../dist/index.js'
mainShow(lr)

then use show to print the tree:

$ ./bin/show ~/src/zig/lib/std/os/uefi/tables/table_header.zig
tree contains error: no
tree covers source: yes
tree length: 214
tree:
Program(pub,
        Decl(GlobalVarDecl(VarDeclProto(const,
                                        Name),
                           Expr(TypeExpr(ContainerDecl(extern,
                                                       ContainerDeclAuto(ContainerDeclType(struct),
                                                                         ContainerField(Identifier,
                                                                                        TypeExpr(Identifier)),
                                                                         ContainerField(Identifier,
                                                                                        TypeExpr(Identifier)),
                                                                         ContainerField(DocComment,
                                                                                        Identifier,
                                                                                        TypeExpr(Identifier)),
                                                                         ContainerField(Identifier,
                                                                                        TypeExpr(Identifier)),
                                                                         ContainerField(Identifier,
                                                                                        TypeExpr(Identifier)))))))))

Build from source

npm i
npm run prepare

About

(MIRROR) Utils for working with Lezer grammars

Resources

License

Stars

Watchers

Forks