-
Notifications
You must be signed in to change notification settings - Fork 0
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 3e3740b
Showing
10 changed files
with
461 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,15 @@ | ||
/node_modules | ||
|
||
# Generated files | ||
/bindings | ||
/target | ||
/src | ||
/Cargo.toml | ||
/Cargo.lock | ||
/binding.gyp | ||
*.lib | ||
*.exp | ||
*.obj | ||
*.so | ||
*.wasm | ||
|
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 @@ | ||
# Ecsact Tree-sitter Parser | ||
|
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,50 @@ | ||
package example; | ||
|
||
import other.package; | ||
import cool; | ||
|
||
enum DamageType { | ||
FIRE = 0; | ||
ROCK = 1; | ||
} | ||
|
||
component Health { | ||
f32 value; | ||
} | ||
|
||
component Attacking { | ||
DamageType damage; | ||
entity target; | ||
} | ||
|
||
component Poisoned { | ||
f32 potency; | ||
} | ||
|
||
system PoisonDamage { | ||
readwrite Health; | ||
readonly Poisoned; | ||
} | ||
|
||
system AttackerDamageShortSyntax { | ||
readonly Attacking with target { | ||
readwrite Health; | ||
} | ||
} | ||
|
||
system AttackerDamageLongSyntax { | ||
readonly Attacking { | ||
with target { | ||
readwrite Health; | ||
} | ||
} | ||
} | ||
|
||
component Attacker; | ||
|
||
action Attack { | ||
entity target; | ||
include Attacker; | ||
adds Attacking; | ||
} | ||
|
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,199 @@ | ||
module.exports = grammar({ | ||
name : 'ecsact', | ||
rules: { | ||
source_file: $ => seq( | ||
// TODO(zaucy): Package statements are not optional in an Ecsact file | ||
optional($.package_statement), | ||
repeat($.import_statement), | ||
repeat($._declaration_statement), | ||
), | ||
|
||
package_statement: $ => seq( | ||
'package', | ||
field('name', $.package_identifier), | ||
choice(';', seq('{', '}')), | ||
), | ||
|
||
import_statement: $ => seq( | ||
'import', | ||
$.package_identifier, | ||
choice(';', seq('{', '}')), | ||
), | ||
|
||
_declaration_statement: $ => choice( | ||
$.component_statement, | ||
$.transient_statement, | ||
$.enum_statement, | ||
$.system_statement, | ||
$.action_statement, | ||
), | ||
|
||
component_statement: $ => seq( | ||
'component', | ||
field('name', $.declaration_identifier), | ||
choice( | ||
';', | ||
seq( | ||
'{', | ||
repeat($.field_statement), | ||
'}', | ||
), | ||
), | ||
), | ||
|
||
transient_statement: $ => seq( | ||
'transient', | ||
field('name', $.declaration_identifier), | ||
choice( | ||
';', | ||
seq( | ||
'{', | ||
repeat($.field_statement), | ||
'}', | ||
), | ||
), | ||
), | ||
|
||
enum_statement: $ => seq( | ||
'enum', | ||
field('name', $.declaration_identifier), | ||
choice( | ||
';', | ||
seq( | ||
'{', | ||
repeat( | ||
$.enum_value_statement | ||
), | ||
'}', | ||
), | ||
), | ||
), | ||
|
||
system_statement: $ => seq( | ||
'system', | ||
field('name', $.declaration_identifier), | ||
choice( | ||
';', | ||
seq( | ||
'{', | ||
repeat($.system_capability_statement), | ||
'}', | ||
), | ||
), | ||
), | ||
|
||
action_statement: $ => seq( | ||
'action', | ||
field('name', $.declaration_identifier), | ||
choice( | ||
';', | ||
seq( | ||
'{', | ||
repeat(choice( | ||
$.system_capability_statement, | ||
$.field_statement, | ||
)), | ||
'}', | ||
), | ||
), | ||
), | ||
|
||
with_statement: $ => seq( | ||
'with', | ||
field('field_name', $.declaration_identifier), | ||
choice( | ||
';', | ||
seq( | ||
'{', | ||
repeat($.system_capability_statement), | ||
'}', | ||
), | ||
), | ||
), | ||
|
||
system_capability: $ => choice( | ||
'readwrite', | ||
'readonly', | ||
'writeonly', | ||
'adds', | ||
'removes', | ||
'exclude', | ||
'incldue', | ||
), | ||
|
||
_system_capability_statement_with_shorthand: $ => seq( | ||
$.system_capability, | ||
field('component_name', $.declaration_identifier), | ||
$.with_statement, | ||
), | ||
|
||
_system_capability_statement: $ => seq( | ||
$.system_capability, | ||
field('component_name', $.declaration_identifier), | ||
choice( | ||
';', | ||
seq( | ||
'{', | ||
repeat($.with_statement), | ||
'}', | ||
), | ||
), | ||
), | ||
|
||
system_capability_statement: $ => seq( | ||
choice( | ||
$._system_capability_statement_with_shorthand, | ||
$._system_capability_statement, | ||
), | ||
), | ||
|
||
number: () => /\d+/, | ||
|
||
enum_value_statement: $ => seq( | ||
field('name', $.declaration_identifier), | ||
'=', | ||
field('value', $.number), | ||
';', | ||
), | ||
|
||
builtin_field_type: () => choice( | ||
'i32', | ||
'u32', | ||
'f32', | ||
'i16', | ||
'u16', | ||
'i8', | ||
'u8', | ||
'entity', | ||
), | ||
|
||
user_field_type: $ => $.declaration_identifier, | ||
|
||
_field_type: $ => seq( | ||
field( | ||
'field_type', | ||
choice( | ||
$.builtin_field_type, | ||
$.user_field_type, | ||
), | ||
), | ||
optional( | ||
seq( | ||
'[', | ||
field('length', $.number), | ||
']', | ||
), | ||
), | ||
), | ||
|
||
field_statement: $ => seq( | ||
$._field_type, | ||
field('field_name', $.declaration_identifier), | ||
choice(';', seq('{', '}')), | ||
), | ||
|
||
package_identifier: () => /[a-z][a-z.]+[a-z]/, | ||
declaration_identifier: () => /[a-zA-Z][a-zA-Z0-9_]*/, | ||
}, | ||
}); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,35 @@ | ||
{ | ||
"name": "tree-sitter-ecsact", | ||
"version": "0.1.0", | ||
"description": "", | ||
"main": "bindings/node", | ||
"scripts": { | ||
"test": "tree-sitter test", | ||
"generate": "tree-sitter generate", | ||
"highlight": "tree-sitter highlight examples/example.ecsact" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ecsact-dev/tree-sitter-ecsact.git" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/ecsact-dev/tree-sitter-ecsact/issues" | ||
}, | ||
"homepage": "https://github.com/ecsact-dev/tree-sitter-ecsact#readme", | ||
"dependencies": { | ||
"nan": "^2.17.0" | ||
}, | ||
"devDependencies": { | ||
"tree-sitter-cli": "^0.20.7" | ||
}, | ||
"tree-sitter": [ | ||
{ | ||
"scope": "source.ecsact", | ||
"file-types": [ | ||
"ecsact" | ||
] | ||
} | ||
] | ||
} |
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,36 @@ | ||
";" @punctuation | ||
"[" @punctuation.bracket | ||
"]" @punctuation.bracket | ||
"{" @punctuation.bracket | ||
"}" @punctuation.bracket | ||
"=" @operator | ||
|
||
(package_identifier) @module | ||
|
||
(builtin_field_type) @type.builtin | ||
(user_field_type) @type | ||
(number) @number | ||
|
||
(enum_statement name: (declaration_identifier) @type) | ||
(component_statement name: (declaration_identifier) @type) | ||
(transient_statement name: (declaration_identifier) @type) | ||
(system_statement name: (declaration_identifier) @type) | ||
(action_statement name: (declaration_identifier) @type) | ||
(system_capability_statement component_name: (declaration_identifier) @type) | ||
(with_statement field_name: (declaration_identifier) @property) | ||
|
||
(enum_value_statement name: (declaration_identifier) @property) | ||
(field_statement field_name: (declaration_identifier) @property) | ||
|
||
(system_capability) @function | ||
|
||
"with" @function | ||
"package" @keyword | ||
"import" @keyword | ||
"enum" @keyword | ||
"component" @keyword | ||
"transient" @keyword | ||
"action" @keyword | ||
"system" @keyword | ||
|
||
|
Oops, something went wrong.