Skip to content

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tree-sitter-plain

Tree-sitter grammar for the ***plain spec-driven language (Codeplain). It powers .plain syntax highlighting in editors — it's the grammar behind the plyn editor tooling (Zed, VS Code, Cursor).

  • Language scope: source.plain
  • File extension: .plain
  • Grammar id: plain

The language in one minute

***plain is a prose-heavy, line-oriented spec format: mostly free natural-language text with a few special constructs.

  • Concepts:concept_name: tokens.
  • Section headers***definitions***, ***functional specs***, ***test reqs***, ***implementation reqs***, and (indented) ***acceptance tests***.
  • Frontmatter — a ------ block with keys like import, requires, description, required_concepts, exported_concepts.
  • Comments — lines starting with > .
  • Bullets (- ), template expressions ({{ … }}), include directives, markdown links, and strings.

See test/sample.plain for a full example.

Using the grammar

Editors normally consume this grammar through the relevant plyn extension, which references it by Git URL + commit. To work with it directly:

npm install
npx tree-sitter generate     # regenerate src/parser.c from grammar.js
npx tree-sitter test         # run the corpus tests in test/corpus/
npx tree-sitter parse test/sample.plain   # print the parse tree for a file

Development

  • The grammar source of truth is grammar.js. After editing it you must run npx tree-sitter generatesrc/parser.c (and src/grammar.json, src/node-types.json) are committed and do not regenerate automatically.
  • Disambiguation is driven entirely by lexer token precedence (no external scanner, no conflicts). Place a new construct's token precedence correctly or it loses the longest-match race to the catch-all text token.
  • New top-level section names and frontmatter keys are added to the TOP_SECTION_NAMES / FRONTMATTER_KEYS constants at the top of grammar.js.
  • Highlight queries live in queries/highlights.scm; add an entry whenever you introduce a node that should be highlighted. The injections.scm and brackets.scm queries are intentionally empty placeholders.
  • Add a case to test/corpus/ for any grammar change and keep npx tree-sitter test green.

License

MIT

About

Tree-sitter grammar for the ***plain spec-driven language

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages