-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 08d3eca
Showing
6 changed files
with
219 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.DS_Store | ||
Cargo.toml | ||
binding.gyp | ||
node_modules | ||
package-lock.json | ||
grammar.js | ||
src/ | ||
bindings/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
module.exports = grammar! | ||
|
||
name: "imba" | ||
|
||
rules: | ||
|
||
source_file: do | ||
repeat($1._definition) | ||
|
||
_definition: do | ||
choice( | ||
$1.tag | ||
) | ||
|
||
tag: do | ||
seq( | ||
$1.tag_open | ||
$1._tag_content | ||
$1.tag_close | ||
) | ||
|
||
tag_open: do | ||
"<" | ||
|
||
_tag_content: do | ||
seq( | ||
$1.tag_identifier | ||
repeat($1._tag_inline_style) | ||
) | ||
|
||
_tag_inline_style: do | ||
seq( | ||
$1.inline_style_open | ||
repeat($1.inline_style_prop) | ||
$1.inline_style_close | ||
) | ||
|
||
tag_close: do | ||
">" | ||
|
||
tag_identifier: do | ||
token(seq(/[a-z]+/, repeat(optional(seq("-", /[a-z]+/))))) | ||
|
||
inline_style_open: do | ||
"[" | ||
|
||
inline_style_close: do | ||
"]" | ||
|
||
inline_style_prop: do | ||
token(seq(/[a-z,@]+/, /:\s*/, /[a-z,#,0-9]+/)) | ||
|
||
keyword: do | ||
choice('const') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "tree-sitter-imba", | ||
"version": "0.0.1", | ||
"description": "Imba grammar for tree-sitter", | ||
"main": "bindings/node", | ||
"dependencies": { | ||
"nan": "^2.17.0" | ||
}, | ||
"scripts": { | ||
"build": "imbac grammar.imba && tree-sitter generate", | ||
"hi": "npm run build && tree-sitter highlight test/test.imba", | ||
"test": "npm run build && tree-sitter test" | ||
}, | ||
"tree-sitter": [ | ||
{ | ||
"scope": "source.js", | ||
"file-types": [ | ||
"imba" | ||
], | ||
"highlights": [ | ||
"queries/highlights.scm" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
(tag) @tag | ||
(inline_style_prop) @function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
========= | ||
Basic tag | ||
========= | ||
|
||
<foo> | ||
|
||
--- | ||
|
||
(source_file | ||
(tag | ||
(tag_open) | ||
(tag_identifier) | ||
(tag_close) | ||
) | ||
) | ||
|
||
============== | ||
Long name tags | ||
============== | ||
|
||
<foo-bar> | ||
<foo-bar-barf> | ||
|
||
--- | ||
|
||
(source_file | ||
(tag | ||
(tag_open) | ||
(tag_identifier) | ||
(tag_close)) | ||
(tag | ||
(tag_open) | ||
(tag_identifier) | ||
(tag_close) | ||
) | ||
) | ||
|
||
============== | ||
With selectors | ||
============== | ||
|
||
<self [d:flex] [bgc:#000 rd:8px] [c@hover:red4]> | ||
<self[d: flex] [bgc:#000 rd: 8px] [c@hover:red4]> | ||
|
||
--- | ||
|
||
(source_file | ||
(tag | ||
(tag_open) | ||
(tag_identifier) | ||
(inline_style_open) | ||
(inline_style_prop) | ||
(inline_style_close) | ||
(inline_style_open) | ||
(inline_style_prop) | ||
(inline_style_prop) | ||
(inline_style_close) | ||
(inline_style_open) | ||
(inline_style_prop) | ||
(inline_style_close) | ||
(tag_close) | ||
) | ||
(tag | ||
(tag_open) | ||
(tag_identifier) | ||
(inline_style_open) | ||
(inline_style_prop) | ||
(inline_style_close) | ||
(inline_style_open) | ||
(inline_style_prop) | ||
(inline_style_prop) | ||
(inline_style_close) | ||
(inline_style_open) | ||
(inline_style_prop) | ||
(inline_style_close) | ||
(tag_close) | ||
) | ||
) | ||
|
||
=========== | ||
Nested tags | ||
=========== | ||
|
||
<foo-bar> | ||
<div[rd:10px bgc:red] | ||
<p> "Hello" | ||
|
||
=============== | ||
Tag declarations | ||
=============== | ||
|
||
tag Foo | ||
<self> | ||
<p> "Hello" | ||
|
||
export default tag Bar | ||
<self> | ||
<div> | ||
|
||
export tag Baz | ||
<self> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
let one = yes | ||
|
||
const two = yes | ||
|
||
while one > 5 | ||
console.log "test" | ||
|
||
let arr = [1, 2, 3, 4, 5] | ||
|
||
for x in arr | ||
console.log(x) | ||
|
||
global.three = yes | ||
|
||
class Four | ||
|
||
def five | ||
console.log "test!" | ||
|
||
tag Foo | ||
<self> | ||
<p> "Hello" | ||
|
||
export default tag Bar | ||
<self> | ||
<div> | ||
|
||
export tag Baz | ||
<self> |