@gram-data/tree-sitter-gram 0.1.10 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -24,4 +24,42 @@ As a subject:
24
24
  })
25
25
  ```
26
26
 
27
- Learn more about `gram` at the [gram-data github org](https://github.com/gram-data) notation.
27
+ Learn more about `gram` at the [gram-data github org](https://github.com/gram-data) notation.
28
+
29
+ ## Editor Support
30
+
31
+ This repository includes editor integrations for syntax highlighting and language support:
32
+
33
+ - **[Zed Editor](editors/zed/)** - Full syntax highlighting and language support
34
+ - More editors coming soon! Contributions welcome.
35
+
36
+ See [editors/README.md](editors/README.md) for installation instructions and available features.
37
+
38
+ ## Language Bindings
39
+
40
+ Tree-sitter bindings are available for multiple languages:
41
+
42
+ - **Node.js**: `npm install @gram-data/tree-sitter-gram`
43
+ - **Rust**: Available via `Cargo.toml`
44
+ - **Python**: Install via `pip install .`
45
+ - **Go**: Import from this repository
46
+ - **Swift**: Available via Swift Package Manager
47
+ - **C**: Build with included Makefile
48
+
49
+ ## Development
50
+
51
+ Generate the parser after grammar changes:
52
+ ```bash
53
+ npx tree-sitter generate
54
+ npx tree-sitter test
55
+ ```
56
+
57
+ Run language binding tests:
58
+ ```bash
59
+ npm test # Node.js bindings
60
+ cargo test # Rust bindings
61
+ python -m pytest # Python bindings
62
+ make test # C bindings
63
+ ```
64
+
65
+ See [DEVELOP.md](DEVELOP.md) for detailed development guidelines.
@@ -0,0 +1,68 @@
1
+ # Editor Integrations
2
+
3
+ This directory contains editor integrations for the Gram tree-sitter grammar.
4
+
5
+ ## Available Integrations
6
+
7
+ ### Zed Editor
8
+
9
+ The Zed integration provides full syntax highlighting and language support for Gram notation files.
10
+
11
+ **Installation:**
12
+
13
+ 1. Copy or symlink the extension to your Zed extensions directory:
14
+ ```bash
15
+ # On macOS/Linux:
16
+ ln -s $(pwd)/editors/zed ~/.config/zed/extensions/gram
17
+
18
+ # On Windows:
19
+ mklink /D "%APPDATA%\Zed\extensions\gram" "path\to\tree-sitter-gram\editors\zed"
20
+ ```
21
+
22
+ 2. Restart Zed
23
+
24
+ 3. Open any `.gram` file to see syntax highlighting in action
25
+
26
+ **Features:**
27
+ - Syntax highlighting for all Gram constructs
28
+ - Bracket matching for `()`, `[]`, and `{}`
29
+ - Automatic file type detection for `.gram` files
30
+ - Proper indentation handling
31
+
32
+ **Development:**
33
+ If you're developing the extension, use Zed's "install dev extension" command:
34
+ 1. Open Zed command palette (`Cmd+Shift+P` / `Ctrl+Shift+P`)
35
+ 2. Run "zed: install dev extension"
36
+ 3. Select the `editors/zed` directory
37
+ 4. Restart Zed
38
+
39
+ ## Contributing New Integrations
40
+
41
+ We welcome contributions for other editors! When adding a new editor integration:
42
+
43
+ 1. Create a subdirectory under `editors/` named after the editor
44
+ 2. Include all necessary configuration files
45
+ 3. Add installation and usage instructions to this README
46
+ 4. Test thoroughly with the examples in `examples/`
47
+
48
+ Popular editors we'd love to see integrations for:
49
+ - VS Code
50
+ - Vim/Neovim
51
+ - Emacs
52
+ - Sublime Text
53
+ - IntelliJ IDEA
54
+ - Atom (if still relevant)
55
+
56
+ ## Grammar Reference
57
+
58
+ All editor integrations should support these Gram language features:
59
+
60
+ - **Subjects**: `[attributes]` and `[:type attributes]`
61
+ - **Nodes**: `(attributes)`
62
+ - **Relationships**: `->`, `--`, `<-`, `<--`, `<->`, `<-->`
63
+ - **Data types**: strings, numbers, booleans, null, arrays, objects
64
+ - **Annotations**: `@key(value)`
65
+ - **Comments**: `//` line comments and `/* */` block comments
66
+ - **Special literals**: measurements (`100km`), hex (`0xFF`), octal (`0755`)
67
+
68
+ See the main [README.md](../README.md) and [examples/](../examples/) for complete syntax documentation.
@@ -0,0 +1,149 @@
1
+ # Gram Language Support for Zed
2
+
3
+ A [Zed](https://zed.dev) extension providing syntax highlighting and language support for [Gram notation](https://gram-data.github.io) - a subject-oriented notation for structured data.
4
+
5
+ ## Features
6
+
7
+ - **Syntax Highlighting**: Full syntax highlighting for all Gram constructs including subjects, nodes, relationships, and data types
8
+ - **Bracket Matching**: Automatic matching for `()`, `[]`, and `{}`
9
+ - **File Type Detection**: Automatic recognition of `.gram` files
10
+ - **Smart Indentation**: Proper indentation handling for nested structures
11
+
12
+ ## Installation
13
+
14
+ ### From Zed Extensions (Coming Soon)
15
+
16
+ Once published, you'll be able to install directly from Zed:
17
+
18
+ 1. Open Zed
19
+ 2. Press `Cmd+Shift+P` (macOS) or `Ctrl+Shift+P` (Linux/Windows)
20
+ 3. Type "extensions" and select "zed: extensions"
21
+ 4. Search for "gram" and install
22
+
23
+ ### Manual Installation
24
+
25
+ For now, install manually by copying the extension:
26
+
27
+ ```bash
28
+ # Clone the repository if you haven't already
29
+ git clone https://github.com/gram-data/tree-sitter-gram.git
30
+
31
+ # Copy or symlink the extension to your Zed extensions directory
32
+ # On macOS/Linux:
33
+ ln -s $(pwd)/tree-sitter-gram/editors/zed ~/.config/zed/extensions/gram
34
+
35
+ # On Windows:
36
+ mklink /D "%APPDATA%\Zed\extensions\gram" "path\to\tree-sitter-gram\editors\zed"
37
+ ```
38
+
39
+ Then restart Zed.
40
+
41
+ ## Usage
42
+
43
+ Once installed, the extension automatically provides syntax highlighting for any file with a `.gram` extension.
44
+
45
+ ### Example Gram Syntax
46
+
47
+ ```gram
48
+ // Simple subject with properties
49
+ (:Person {
50
+ name: "Andreas",
51
+ age: 35,
52
+ roles: ["author", "developer"]
53
+ })
54
+
55
+ // Relationships between nodes
56
+ (alice:Person {name: "Alice"})->(bob:Person {name: "Bob"})
57
+
58
+ // Complex subject with annotations
59
+ @type("Employee")
60
+ [:Person {
61
+ id: 12345,
62
+ name: "John Doe",
63
+ department: "Engineering",
64
+ salary: 75000.50,
65
+ active: true,
66
+ skills: ["JavaScript", "Rust", "Python"]
67
+ }]
68
+
69
+ // Measurements and special values
70
+ (:Measurement {
71
+ distance: 100km,
72
+ weight: 5.5kg,
73
+ temperature: -10.5celsius,
74
+ count: 0x1A,
75
+ nullable: null
76
+ })
77
+ ```
78
+
79
+ ## Syntax Highlighting
80
+
81
+ The extension provides highlighting for:
82
+
83
+ - **Subjects**: `[...]` and `[:type ...]` brackets
84
+ - **Nodes**: `(...)` parentheses
85
+ - **Relationships**: `->`, `--`, `<-`, `<-->`, etc.
86
+ - **Strings**: Single, double, and backtick quoted strings
87
+ - **Numbers**: Integers, decimals, hex, octal, and measurements
88
+ - **Booleans**: `true` and `false`
89
+ - **Null**: `null` literal
90
+ - **Comments**: `//` and `/* */`
91
+ - **Operators**: `:`, `::`, `@`
92
+ - **Properties**: Object keys and annotation keys
93
+ - **Errors**: Invalid syntax
94
+
95
+ ## Development
96
+
97
+ To work on this extension:
98
+
99
+ 1. Clone the main repository:
100
+ ```bash
101
+ git clone https://github.com/gram-data/tree-sitter-gram.git
102
+ cd tree-sitter-gram
103
+ ```
104
+
105
+ 2. Install as a dev extension in Zed:
106
+ - Open Zed command palette (`Cmd+Shift+P` / `Ctrl+Shift+P`)
107
+ - Run "zed: install dev extension"
108
+ - Select the `editors/zed` directory
109
+ - Restart Zed
110
+
111
+ 3. Make changes to the extension files
112
+ 4. Restart Zed to see changes
113
+
114
+ ### Extension Structure
115
+
116
+ ```
117
+ editors/zed/
118
+ ├── extension.toml # Extension metadata
119
+ ├── grammars/
120
+ │ └── tree-sitter-gram/ # Grammar files
121
+ │ ├── grammar.js # Tree-sitter grammar definition
122
+ │ └── src/ # Generated parser source
123
+ ├── languages/
124
+ │ └── gram/
125
+ │ ├── config.toml # Language configuration
126
+ │ └── queries/ # Syntax highlighting queries
127
+ │ └── highlights.scm
128
+ └── example.gram # Example file for testing
129
+ ```
130
+
131
+ ## Contributing
132
+
133
+ Contributions are welcome! Please see the main [repository](https://github.com/gram-data/tree-sitter-gram) for contribution guidelines.
134
+
135
+ To improve syntax highlighting:
136
+ 1. Edit `languages/gram/queries/highlights.scm`
137
+ 2. Test with various Gram files
138
+ 3. Submit a pull request
139
+
140
+ ## License
141
+
142
+ This extension is part of the tree-sitter-gram project and is licensed under the ISC License. See the main repository's [LICENSE](../../LICENSE) file for details.
143
+
144
+ ## Learn More
145
+
146
+ - [Gram Data GitHub Organization](https://github.com/gram-data)
147
+ - [Gram Notation Documentation](https://gram-data.github.io)
148
+ - [Tree-sitter Grammar Repository](https://github.com/gram-data/tree-sitter-gram)
149
+ - [Zed Editor](https://zed.dev)
@@ -0,0 +1,89 @@
1
+ (:Person {
2
+ name: "Andreas Kollegger",
3
+ age: 42,
4
+ active: true,
5
+ roles: ["author", "developer", "architect"]
6
+ })
7
+
8
+ (alice:Person {name: "Alice", department: "Engineering"})
9
+ -[:WORKS_WITH]->
10
+ (bob:Person {name: "Bob", role: "Designer"})
11
+
12
+ @version("1.0")
13
+ @created("2024-01-15")
14
+ [:Employee {
15
+ id: 12345,
16
+ name: "John Doe",
17
+ email: "john.doe@company.com",
18
+ department: "Engineering",
19
+ salary: 125000.75,
20
+ active: true,
21
+ started: "2023-01-15",
22
+ skills: ["JavaScript", "Rust", "Python", "Go"],
23
+ manager: 67890
24
+ }]
25
+
26
+ (client:Company {name: "ACME Corp"})
27
+ <-[:CONTRACTS]->
28
+ (vendor:Company {name: "Tech Solutions Inc"})
29
+
30
+ (user:Person {name: "Charlie"})-[:OWNS]->(car:Vehicle {
31
+ make: "Tesla",
32
+ model: "Model 3",
33
+ year: 2023
34
+ }),
35
+ (user)-[:LIVES_IN]->(city:Location {
36
+ name: "San Francisco",
37
+ state: "CA",
38
+ country: "USA"
39
+ }),
40
+ (user)-[:WORKS_FOR]->(company:Company {name: "Startup Inc"})
41
+
42
+ (:DataTypes {
43
+ integer: 42,
44
+ negative: -17,
45
+ decimal: 3.14159,
46
+ scientific: 1.23e-4,
47
+ hexadecimal: 0xFF00,
48
+ octal: 0755,
49
+ binary: 0b1010,
50
+ distance: 100km,
51
+ weight: 5.5kg,
52
+ temperature: -10.5celsius,
53
+ time: 30min,
54
+ single_quoted: 'Hello World',
55
+ double_quoted: "Hello \"quoted\" World",
56
+ backtick: `Template string with ${variable}`,
57
+ is_active: true,
58
+ is_deleted: false,
59
+ optional_field: null
60
+ })
61
+
62
+ [
63
+ "The Pragmatic Programmer",
64
+ "Clean Code",
65
+ "Design Patterns"
66
+ ]
67
+
68
+ (:Project {
69
+ name: "Gram Parser",
70
+ version: "0.1.11",
71
+ description: "A tree-sitter grammar for Gram notation",
72
+ repository: {
73
+ type: "git",
74
+ url: "https://github.com/gram-data/tree-sitter-gram"
75
+ },
76
+ dependencies: { tree-sitter: "^0.25.0", node-gyp-build: "^4.8.4" },
77
+ contributors: { Andreas: "maintainer", Community: "contributor" }
78
+ })
79
+
80
+ (:EdgeCases {
81
+ sample_array: ["example"],
82
+ sample_map: { a: 1 },
83
+ unicode: "Hello 世界 🌍",
84
+ escaped_chars: "Line 1\nLine 2\tTabbed",
85
+ special_symbols: "@#$%^&*()_+-=[]{}|;:,.<>?",
86
+ very_long_string: "This is a very long string that spans multiple conceptual lines to test how the syntax highlighter handles long content without breaking the highlighting engine or causing performance issues in the editor"
87
+ })
88
+
89
+ (::Double::Trouble)
@@ -0,0 +1,11 @@
1
+ id = "gram"
2
+ name = "Gram Language Support"
3
+ version = "0.2.0"
4
+ schema_version = 1
5
+ authors = ["Gram Data Contributors"]
6
+ description = "Support for Gram notation - a subject-oriented notation for structured data"
7
+
8
+ # path = "grammars/tree-sitter-gram"
9
+ [grammars.gram]
10
+ repository = "https://github.com/gram-data/tree-sitter-gram"
11
+ rev = "e419dbe99e299517f615f79616c836de4cb2550d"
@@ -0,0 +1,16 @@
1
+ name = "Gram"
2
+ grammar = "gram"
3
+ path_suffixes = ["gram"]
4
+ autoclose_before = ")]}'\":.,;>"
5
+ brackets = [
6
+ { start = "{", end = "}", close = true, newline = true },
7
+ { start = "[", end = "]", close = true, newline = true },
8
+ { start = "(", end = ")", close = true, newline = true },
9
+ ]
10
+ word_characters = ["_"]
11
+
12
+ [prettier]
13
+ allowed = false
14
+
15
+ # [language_servers]
16
+ # Add language server configuration here if you develop one for Gram
@@ -0,0 +1,79 @@
1
+ ; Strings
2
+ (string_literal) @string
3
+ (string_content) @string
4
+
5
+ ; Numbers
6
+ (integer) @number
7
+ (decimal) @number
8
+ (hexadecimal) @number
9
+ (octal) @number
10
+ (measurement) @number
11
+
12
+ ; Boolean literals
13
+ (boolean_literal) @boolean
14
+
15
+ ; Symbols and identifiers
16
+ (symbol) @variable
17
+
18
+ ; Keywords and operators
19
+ [
20
+ "@"
21
+ "|"
22
+ ":"
23
+ "::"
24
+ ] @operator
25
+
26
+ ; Brackets and delimiters
27
+ [
28
+ "["
29
+ "]"
30
+ "("
31
+ ")"
32
+ "{"
33
+ "}"
34
+ ] @punctuation.bracket
35
+
36
+ ; Comma separator
37
+ [
38
+ ","
39
+ ] @punctuation.delimiter
40
+
41
+ ; Field names in records and maps
42
+ (property key: (symbol) @property)
43
+ (property key: (string_literal) @property)
44
+ (property key: (integer) @property)
45
+ (mapping key: (symbol) @property)
46
+ (mapping key: (string_literal) @property)
47
+ (mapping key: (integer) @property)
48
+
49
+ ; Annotation keys
50
+ (annotation key: (symbol) @attribute)
51
+
52
+ ; Annotations inside nodes
53
+ (node annotations: (annotations) @attribute)
54
+
55
+ ; Annotations inside relationship arrows
56
+ [
57
+ (right_arrow annotations: (annotations) @attribute)
58
+ (left_arrow annotations: (annotations) @attribute)
59
+ (undirected_arrow annotations: (annotations) @attribute)
60
+ (bidirectional_arrow annotations: (annotations) @attribute)
61
+ ]
62
+
63
+ ; Subject brackets (special highlighting)
64
+ (subject) @type
65
+
66
+ ; Node with labels
67
+ (node (labels (symbol) @type))
68
+
69
+ ; Relationship arrows (special highlighting for graph syntax)
70
+ (relationship) @keyword
71
+
72
+ ; Arrow operators in relationships
73
+ (right_arrow) @operator
74
+ (left_arrow) @operator
75
+ (undirected_arrow) @operator
76
+ (bidirectional_arrow) @operator
77
+
78
+ ; Error highlighting
79
+ (ERROR) @error
@@ -0,0 +1,8 @@
1
+ // Test Gram file for syntax highlighting
2
+ (:Person {
3
+ name: "Test User",
4
+ age: 30,
5
+ active: true
6
+ })
7
+
8
+ (user:Person)-[:KNOWS]->(friend:Person {name: "Friend"})