~repos /plum

#treesitter#compiler#wasm

git clone https://pyrossh.dev/repos/plum.git

A statically typed, imperative programming language inspired by rust, python


fddcfa8d Peter John

2 years ago
Add bindings and queries
Cargo.toml CHANGED
@@ -1,10 +1,10 @@
1
1
  [package]
2
- name = "tree-sitter-pine"
2
+ name = "tree-sitter-palm"
3
- description = "pine grammar for the tree-sitter parsing library"
3
+ description = "palm grammar for the tree-sitter parsing library"
4
- version = "0.0.1"
4
+ version = "0.1.0"
5
- keywords = ["incremental", "parsing", "pine"]
5
+ keywords = ["incremental", "parsing", "palm"]
6
6
  categories = ["parsing", "text-editors"]
7
- repository = "https://github.com/tree-sitter/tree-sitter-pine"
7
+ repository = "https://github.com/pyrossh/tree-sitter-palm"
8
8
  edition = "2018"
9
9
  license = "MIT"
10
10
 
bindings/node/binding.cc CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  using namespace v8;
6
6
 
7
- extern "C" TSLanguage * tree_sitter_pine();
7
+ extern "C" TSLanguage * tree_sitter_palm();
8
8
 
9
9
  namespace {
10
10
 
@@ -17,12 +17,12 @@ void Init(Local<Object> exports, Local<Object> module) {
17
17
 
18
18
  Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19
19
  Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
20
- Nan::SetInternalFieldPointer(instance, 0, tree_sitter_pine());
20
+ Nan::SetInternalFieldPointer(instance, 0, tree_sitter_palm());
21
21
 
22
- Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("pine").ToLocalChecked());
22
+ Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("palm").ToLocalChecked());
23
23
  Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
24
24
  }
25
25
 
26
- NODE_MODULE(tree_sitter_pine_binding, Init)
26
+ NODE_MODULE(tree_sitter_palm_binding, Init)
27
27
 
28
28
  } // namespace
bindings/node/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  try {
2
- module.exports = require("../../build/Release/tree_sitter_pine_binding");
2
+ module.exports = require("../../build/Release/tree_sitter_palm_binding");
3
3
  } catch (error1) {
4
4
  if (error1.code !== 'MODULE_NOT_FOUND') {
5
5
  throw error1;
6
6
  }
7
7
  try {
8
- module.exports = require("../../build/Debug/tree_sitter_pine_binding");
8
+ module.exports = require("../../build/Debug/tree_sitter_palm_binding");
9
9
  } catch (error2) {
10
10
  if (error2.code !== 'MODULE_NOT_FOUND') {
11
11
  throw error2;
bindings/rust/build.rs CHANGED
@@ -1,28 +1,35 @@
1
- use std::path::Path;
2
- extern crate cc;
3
-
4
1
  fn main() {
5
- let src_dir = Path::new("src");
2
+ let src_dir = std::path::Path::new("src");
3
+
4
+ let mut c_config = cc::Build::new();
5
+ c_config.include(&src_dir);
6
+ c_config
7
+ .flag_if_supported("-Wno-unused-parameter")
8
+ .flag_if_supported("-Wno-unused-but-set-variable")
9
+ .flag_if_supported("-Wno-trigraphs");
10
+ let parser_path = src_dir.join("parser.c");
11
+ c_config.file(&parser_path);
12
+
13
+ let scanner_path = src_dir.join("scanner.c");
14
+ c_config.file(&scanner_path);
15
+ println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
16
+
17
+ c_config.compile("parser");
18
+ println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
6
19
 
7
- let mut c_config = cc::Build::new();
8
- c_config.include(&src_dir);
9
- c_config
10
- .flag_if_supported("-Wno-unused-parameter")
11
- .flag_if_supported("-Wno-unused-but-set-variable")
20
+ // If your language uses an external scanner written in C++,
12
- .flag_if_supported("-Wno-trigraphs");
13
- let parser_path = src_dir.join("parser.c");
21
+ // then include this block of code:
14
- c_config.file(&parser_path);
15
- println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
16
- c_config.compile("parser");
17
22
 
23
+ /*
18
- let mut cpp_config = cc::Build::new();
24
+ let mut cpp_config = cc::Build::new();
19
- cpp_config.cpp(true);
25
+ cpp_config.cpp(true);
20
- cpp_config.include(&src_dir);
26
+ cpp_config.include(&src_dir);
21
- cpp_config
27
+ cpp_config
22
- .flag_if_supported("-Wno-unused-parameter")
28
+ .flag_if_supported("-Wno-unused-parameter")
23
- .flag_if_supported("-Wno-unused-but-set-variable");
29
+ .flag_if_supported("-Wno-unused-but-set-variable");
24
- let scanner_path = src_dir.join("scanner.cc");
30
+ let scanner_path = src_dir.join("scanner.cc");
25
- cpp_config.file(&scanner_path);
31
+ cpp_config.file(&scanner_path);
32
+ cpp_config.compile("scanner");
26
- println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
33
+ println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
27
- cpp_config.compile("scanner");
34
+ */
28
- }
35
+ }
bindings/rust/lib.rs CHANGED
@@ -1,27 +1,13 @@
1
- // -*- coding: utf-8 -*-
2
- // ------------------------------------------------------------------------------------------------
3
- // Copyright © 2020, tree-sitter-python authors.
4
- // See the LICENSE file in this repo for license details.
5
- // ------------------------------------------------------------------------------------------------
6
-
7
- //! This crate provides a Python grammar for the [tree-sitter][] parsing library.
1
+ //! This crate provides palm language support for the [tree-sitter][] parsing library.
8
2
  //!
9
- //! Typically, you will use the [language][language func] function to add this grammar to a
3
+ //! Typically, you will use the [language][language func] function to add this language to a
10
4
  //! tree-sitter [Parser][], and then use the parser to parse some code:
11
5
  //!
12
6
  //! ```
13
- //! use tree_sitter::Parser;
14
- //!
15
- //! let code = r#"
7
+ //! let code = "";
16
- //! def double(x):
17
- //! return x * 2
18
- //! "#;
19
- //! let mut parser = Parser::new();
8
+ //! let mut parser = tree_sitter::Parser::new();
20
- //! parser.set_language(tree_sitter_python::language()).expect("Error loading Python grammar");
9
+ //! parser.set_language(tree_sitter_palm::language()).expect("Error loading palm grammar");
21
- //! let parsed = parser.parse(code, None);
10
+ //! let tree = parser.parse(code, None).unwrap();
22
- //! # let parsed = parsed.unwrap();
23
- //! # let root = parsed.root_node();
24
- //! # assert!(!root.has_error());
25
11
  //! ```
26
12
  //!
27
13
  //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
@@ -32,17 +18,17 @@
32
18
  use tree_sitter::Language;
33
19
 
34
20
  extern "C" {
35
- fn tree_sitter_python() -> Language;
21
+ fn tree_sitter_palm() -> Language;
36
22
  }
37
23
 
38
24
  /// Returns the tree-sitter [Language][] for this grammar.
39
25
  ///
40
26
  /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
41
27
  pub fn language() -> Language {
42
- unsafe { tree_sitter_python() }
28
+ unsafe { tree_sitter_palm() }
43
29
  }
44
30
 
45
- /// The source of the Python tree-sitter grammar description.
31
+ /// The source of the palm tree-sitter grammar description.
46
32
  pub const GRAMMAR: &'static str = include_str!("../../grammar.js");
47
33
 
48
34
  /// The syntax highlighting query for this language.
@@ -63,6 +49,6 @@ mod tests {
63
49
  let mut parser = tree_sitter::Parser::new();
64
50
  parser
65
51
  .set_language(super::language())
66
- .expect("Error loading Python grammar");
52
+ .expect("Error loading palm grammar");
67
53
  }
68
54
  }
queries/highlights.scm ADDED
@@ -0,0 +1,102 @@
1
+ ; Comments
2
+ (module_comment) @comment
3
+ (statement_comment) @comment
4
+ (comment) @comment
5
+
6
+ ; Constants
7
+ (constant
8
+ name: (identifier) @constant)
9
+
10
+ ; Modules
11
+ (module) @module
12
+ (import alias: (identifier) @module)
13
+ (remote_type_identifier
14
+ module: (identifier) @module)
15
+ (remote_constructor_name
16
+ module: (identifier) @module)
17
+ ((field_access
18
+ record: (identifier) @module
19
+ field: (label) @function)
20
+ (#is-not? local))
21
+
22
+ ; Functions
23
+ (unqualified_import (identifier) @function)
24
+ (function
25
+ name: (identifier) @function)
26
+ (external_function
27
+ name: (identifier) @function)
28
+ (function_parameter
29
+ name: (identifier) @variable.parameter)
30
+ ((function_call
31
+ function: (identifier) @function)
32
+ (#is-not? local))
33
+ ((binary_expression
34
+ operator: "|>"
35
+ right: (identifier) @function)
36
+ (#is-not? local))
37
+
38
+ ; "Properties"
39
+ ; Assumed to be intended to refer to a name for a field; something that comes
40
+ ; before ":" or after "."
41
+ ; e.g. record field names, tuple indices, names for named arguments, etc
42
+ (label) @property
43
+ (tuple_access
44
+ index: (integer) @property)
45
+
46
+ ; Type names
47
+ (remote_type_identifier) @type
48
+ (type_identifier) @type
49
+
50
+ ; Data constructors
51
+ (constructor_name) @constructor
52
+
53
+ ; Literals
54
+ (string) @string
55
+ (bit_string_segment_option) @function.builtin
56
+ (integer) @number
57
+ (float) @number
58
+
59
+ ; Variables
60
+ (identifier) @variable
61
+ (discard) @comment.unused
62
+
63
+ ; Operators
64
+ (binary_expression
65
+ operator: _ @operator)
66
+ "!" @operator
67
+
68
+ ; Keywords
69
+ [
70
+ "as"
71
+ "assert"
72
+ "case"
73
+ "const"
74
+ "extern"
75
+ "fn"
76
+ "import"
77
+ "let"
78
+ "panic"
79
+ "todo"
80
+ "type"
81
+ ] @keyword
82
+
83
+ ; Punctuation
84
+ [
85
+ "("
86
+ ")"
87
+ "["
88
+ "]"
89
+ "{"
90
+ "}"
91
+ ] @punctuation.bracket
92
+ [
93
+ "."
94
+ ","
95
+ ":"
96
+ "#"
97
+ "="
98
+ "->"
99
+ ".."
100
+ "-"
101
+ "<-"
102
+ ] @punctuation.delimiter
queries/locals.scm ADDED
@@ -0,0 +1,15 @@
1
+ ; Scopes
2
+ (function) @local.scope
3
+
4
+ (case_clause) @local.scope
5
+
6
+ ; Definitions
7
+ (let pattern: (identifier) @local.definition)
8
+ (function_parameter name: (identifier) @local.definition)
9
+ (list_pattern (identifier) @local.definition)
10
+ (list_pattern assign: (identifier) @local.definition)
11
+ (tuple_pattern (identifier) @local.definition)
12
+ (record_pattern_argument pattern: (identifier) @local.definition)
13
+
14
+ ; References
15
+ (identifier) @local.reference
queries/tags.scm ADDED
@@ -0,0 +1,41 @@
1
+ ; Modules
2
+ (module) @name @reference.module
3
+ (import alias: (identifier) @name) @reference.module
4
+ (remote_type_identifier
5
+ module: (identifier) @name) @reference.module
6
+ ((field_access
7
+ record: (identifier) @name)
8
+ (#is-not? local)) @reference.module
9
+
10
+ ; Functions
11
+ (function
12
+ name: (identifier) @name) @definition.function
13
+ (external_function
14
+ name: (identifier) @name) @definition.function
15
+ (unqualified_import (identifier) @name) @reference.function
16
+ ((function_call
17
+ function: (identifier) @name) @reference.function
18
+ (#is-not? local))
19
+ ((field_access
20
+ record: (identifier) @ignore
21
+ field: (label) @name)
22
+ (#is-not? local)) @reference.function
23
+ ((binary_expression
24
+ operator: "|>"
25
+ right: (identifier) @name)
26
+ (#is-not? local)) @reference.function
27
+
28
+ ; Types
29
+ (type_definition
30
+ (type_name
31
+ name: (type_identifier) @name)) @definition.type
32
+ (type_definition
33
+ (data_constructors
34
+ (data_constructor
35
+ name: (constructor_name) @name))) @definition.constructor
36
+ (external_type
37
+ (type_name
38
+ name: (type_identifier) @name)) @definition.type
39
+
40
+ (type_identifier) @name @reference.type
41
+ (constructor_name) @name @reference.constructor