chore!: Version 1.0.0
This commit is contained in:
parent
e2a7a19473
commit
fab7af32a2
4 changed files with 78 additions and 48 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tree-sitter-org"
|
name = "tree-sitter-org"
|
||||||
description = "org grammar for the tree-sitter parsing library"
|
description = "org grammar for the tree-sitter parsing library"
|
||||||
version = "0.0.1"
|
version = "1.0.0"
|
||||||
keywords = ["incremental", "parsing", "org"]
|
keywords = ["incremental", "parsing", "org"]
|
||||||
categories = ["parsing", "text-editors"]
|
categories = ["parsing", "text-editors"]
|
||||||
repository = "https://github.com/milisims/tree-sitter-org"
|
repository = "https://github.com/milisims/tree-sitter-org"
|
||||||
edition = "2021"
|
edition = "2022"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
build = "bindings/rust/build.rs"
|
build = "bindings/rust/build.rs"
|
||||||
|
|
|
||||||
2
LICENSE
2
LICENSE
|
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2021 Emilia Simmons
|
Copyright (c) 2021-2022 Emilia Simmons
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
|
||||||
118
README.md
118
README.md
|
|
@ -1,10 +1,9 @@
|
||||||
# tree-sitter-org
|
# tree-sitter-org
|
||||||
|
|
||||||
**Unstable**: This build will change.
|
Org grammar for tree-sitter. Here, the goal is to implement a grammar that can
|
||||||
|
usefully parse org files to be used in any library that uses tree-sitter
|
||||||
Org grammar for tree-sitter. It is not meant to implement emacs' orgmode
|
parsers. It is not meant to implement emacs' orgmode parser exactly, which is
|
||||||
parser, but to implement a grammar that can usefully parse org files to be used
|
inherently more dynamic than tree-sitter easily allows.
|
||||||
in neovim and any library that uses tree-sitter parsers.
|
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
|
|
@ -14,11 +13,11 @@ Refer to the tests in `corpus` for examples.
|
||||||
- Top level node: `(document)`
|
- Top level node: `(document)`
|
||||||
- Document contains: `(directive)* (body)? (section)*`
|
- Document contains: `(directive)* (body)? (section)*`
|
||||||
- Section contains: `(headline) (plan)? (property_drawer)? (body)?`
|
- Section contains: `(headline) (plan)? (property_drawer)? (body)?`
|
||||||
- headline contains: (stars, title, tag?+)
|
- headline contains: `((stars), (item)?, (tag_list)?)`
|
||||||
- body contains: `(element)+`
|
- body contains: `(element)+`
|
||||||
- element contains: `(directive)* choose(paragraph, drawer, comment, footnote def, list, block, dynamic block, table)`
|
- element contains: `(directive)* choose(paragraph, drawer, comment, footnote def, list, block, dynamic block, table)` or a bare `(directive)`
|
||||||
- paragraph contains: (textelement)+
|
- paragraph contains: `(expr)+`
|
||||||
- text element: choose(unmarked text, markup text, timestamps, footnotes, links, latex fragments)
|
- expr contains: anonymous nodes for 'str', 'num', 'sym', and any ascii symbol that is not letters or numbers. (See top of grammar.js and queries for details)
|
||||||
|
|
||||||
Like in many regex systems, `*/+` is read as "0/1 or more", and `?` is 0 or 1.
|
Like in many regex systems, `*/+` is read as "0/1 or more", and `?` is 0 or 1.
|
||||||
|
|
||||||
|
|
@ -46,54 +45,86 @@ Text
|
||||||
Parses as:
|
Parses as:
|
||||||
```
|
```
|
||||||
(document [0, 0] - [16, 0]
|
(document [0, 0] - [16, 0]
|
||||||
(directive [0, 0] - [1, 0]
|
(body [0, 0] - [4, 0]
|
||||||
name: (name [0, 2] - [0, 7])
|
directive: (directive [0, 0] - [1, 0]
|
||||||
value: (value [0, 9] - [0, 16]))
|
name: (expr [0, 2] - [0, 7])
|
||||||
(body [2, 0] - [3, 0]
|
value: (value [0, 9] - [0, 16]
|
||||||
|
(expr [0, 9] - [0, 16])))
|
||||||
(paragraph [2, 0] - [3, 0]
|
(paragraph [2, 0] - [3, 0]
|
||||||
(markup [2, 5] - [2, 16])))
|
(expr [2, 0] - [2, 4])
|
||||||
|
(expr [2, 5] - [2, 12])
|
||||||
|
(expr [2, 13] - [2, 16])
|
||||||
|
(expr [2, 17] - [2, 22])))
|
||||||
(section [4, 0] - [16, 0]
|
(section [4, 0] - [16, 0]
|
||||||
(headline [4, 0] - [4, 12]
|
(headline [4, 0] - [5, 0]
|
||||||
(stars [4, 0] - [4, 1])
|
stars: (stars [4, 0] - [4, 1])
|
||||||
(item [4, 2] - [4, 12]))
|
item: (item [4, 2] - [4, 12]
|
||||||
|
(expr [4, 2] - [4, 6])
|
||||||
|
(expr [4, 7] - [4, 12])))
|
||||||
(plan [5, 0] - [6, 0]
|
(plan [5, 0] - [6, 0]
|
||||||
(timestamp [5, 0] - [5, 16]
|
(entry [5, 0] - [5, 16]
|
||||||
(date [5, 1] - [5, 15])))
|
timestamp: (timestamp [5, 0] - [5, 16]
|
||||||
(body [7, 0] - [11, 10]
|
(date [5, 1] - [5, 11])
|
||||||
(list [7, 0] - [11, 10]
|
(day [5, 12] - [5, 15]))))
|
||||||
(listitem [7, 3] - [7, 10])
|
(body [6, 0] - [13, 0]
|
||||||
(listitem [8, 3] - [10, 16]
|
(list [7, 0] - [12, 0]
|
||||||
(list [9, 0] - [10, 16]
|
(listitem [7, 2] - [8, 0]
|
||||||
(listitem [9, 5] - [9, 16])
|
bullet: (bullet [7, 2] - [7, 3])
|
||||||
(listitem [10, 5] - [10, 16])))
|
contents: (paragraph [7, 4] - [8, 0]
|
||||||
(listitem [11, 3] - [11, 10])))
|
(expr [7, 4] - [7, 8])
|
||||||
|
(expr [7, 9] - [7, 10])))
|
||||||
|
(listitem [8, 2] - [11, 0]
|
||||||
|
bullet: (bullet [8, 2] - [8, 3])
|
||||||
|
contents: (paragraph [8, 4] - [9, 0]
|
||||||
|
(expr [8, 4] - [8, 5])
|
||||||
|
(expr [8, 6] - [8, 7])
|
||||||
|
(expr [8, 8] - [8, 12])
|
||||||
|
(expr [8, 13] - [8, 14]))
|
||||||
|
contents: (list [9, 0] - [11, 0]
|
||||||
|
(listitem [9, 4] - [10, 0]
|
||||||
|
bullet: (bullet [9, 4] - [9, 5])
|
||||||
|
contents: (paragraph [9, 6] - [10, 0]
|
||||||
|
(expr [9, 6] - [9, 7])
|
||||||
|
(expr [9, 8] - [9, 9])
|
||||||
|
(expr [9, 10] - [9, 14])
|
||||||
|
(expr [9, 15] - [9, 16])))
|
||||||
|
(listitem [10, 4] - [11, 0]
|
||||||
|
bullet: (bullet [10, 4] - [10, 5])
|
||||||
|
contents: (paragraph [10, 6] - [11, 0]
|
||||||
|
(expr [10, 6] - [10, 7])
|
||||||
|
(expr [10, 8] - [10, 9])
|
||||||
|
(expr [10, 10] - [10, 14])
|
||||||
|
(expr [10, 15] - [10, 16])))))
|
||||||
|
(listitem [11, 2] - [12, 0]
|
||||||
|
bullet: (bullet [11, 2] - [11, 3])
|
||||||
|
contents: (paragraph [11, 4] - [12, 0]
|
||||||
|
(expr [11, 4] - [11, 8])
|
||||||
|
(expr [11, 9] - [11, 10])))))
|
||||||
(section [13, 0] - [16, 0]
|
(section [13, 0] - [16, 0]
|
||||||
(headline [13, 0] - [13, 19]
|
(headline [13, 0] - [14, 0]
|
||||||
(stars [13, 0] - [13, 2])
|
stars: (stars [13, 0] - [13, 2])
|
||||||
(item [13, 3] - [13, 13])
|
item: (item [13, 3] - [13, 13]
|
||||||
tags: (tag [13, 15] - [13, 18]))
|
(expr [13, 3] - [13, 13]))
|
||||||
(body [15, 0] - [16, 0]
|
tags: (tag_list [13, 14] - [13, 19]
|
||||||
(paragraph [15, 0] - [16, 0])))))
|
tag: (tag [13, 15] - [13, 18])))
|
||||||
|
(body [14, 0] - [16, 0]
|
||||||
|
(paragraph [15, 0] - [16, 0]
|
||||||
|
(expr [15, 0] - [15, 4]))))))
|
||||||
```
|
```
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
To compile the parser library for use in neovim & others:
|
For manual install, use `make`.
|
||||||
|
|
||||||
`gcc -o org.so -I./src src/parser.c src/scanner.cc -shared -Os -lstdc++`
|
For neovim, using `nvim-treesitter/nvim-treesitter`, add to your configuration:
|
||||||
|
|
||||||
`cp org.so NEOVIMDIR/parser/`
|
|
||||||
|
|
||||||
For neovim, using `nvim-treesitter/nvim-treesitter`:
|
|
||||||
|
|
||||||
Add to your init.lua (or otherwise source):
|
|
||||||
|
|
||||||
``` lua
|
``` lua
|
||||||
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
|
local parser_config = require "nvim-treesitter.parsers".get_parser_configs()
|
||||||
parser_config.org = {
|
parser_config.org = {
|
||||||
install_info = {
|
install_info = {
|
||||||
url = '<PREFIX>/tree-sitter-org',
|
url = 'https://github.com/milisims/tree-sitter-org',
|
||||||
files = {'src/parser.c', 'src/scanner.cc'},
|
revision = 'main',
|
||||||
|
files = { 'src/parser.c', 'src/scanner.cc' },
|
||||||
},
|
},
|
||||||
filetype = 'org',
|
filetype = 'org',
|
||||||
}
|
}
|
||||||
|
|
@ -105,4 +136,3 @@ To build the parser using npm and run tests:
|
||||||
2. Clone this repository: `git clone https://github.com/milisims/tree-sitter-org` and `cd` into it
|
2. Clone this repository: `git clone https://github.com/milisims/tree-sitter-org` and `cd` into it
|
||||||
3. Install tree-sitter using npm: `npm install`
|
3. Install tree-sitter using npm: `npm install`
|
||||||
4. Run tests: `./node_modules/.bin/tree-sitter generate && ./node_modules/.bin/tree-sitter test`
|
4. Run tests: `./node_modules/.bin/tree-sitter generate && ./node_modules/.bin/tree-sitter test`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "tree-sitter-org",
|
"name": "tree-sitter-org",
|
||||||
"version": "0.0.1",
|
"version": "1.0.0",
|
||||||
"description": "Org grammar for tree-sitter",
|
"description": "Org grammar for tree-sitter",
|
||||||
"main": "bindings/node",
|
"main": "bindings/node",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue