Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
familyfriendlymikey committed Jan 14, 2023
0 parents commit 08d3eca
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
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/
54 changes: 54 additions & 0 deletions grammar.imba
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')
25 changes: 25 additions & 0 deletions package.json
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"
]
}
]
}
2 changes: 2 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(tag) @tag
(inline_style_prop) @function
101 changes: 101 additions & 0 deletions test/corpus/tags.txt
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>
29 changes: 29 additions & 0 deletions test/test.imba
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>

0 comments on commit 08d3eca

Please sign in to comment.