Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rust binding for scanner.c #6

Merged
merged 6 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
fn main() {
let src_dir = std::path::Path::new("src");

let mut c_config = cc::Build::new();
c_config.include(&src_dir);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);

// If your language uses an external scanner written in C,
// then include this block of code:

/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/

c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());

// If your language uses an external scanner written in C++,
// then include this block of code:

/*
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
c_config.file(&parser_path);
c_config.file(&scanner_path);
c_config.compile("parser-scanner");
}
11 changes: 7 additions & 4 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ pub fn language() -> Language {
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");

// Uncomment these to include any queries that this grammar contains
/// The source of the Rust tree-sitter grammar description.
pub const GRAMMAR: &str = include_str!("../../grammar.js");

// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
// Uncomment these to include any queries that this grammar contains
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
pub const TEXTOBJECTS_QUERY: &'static str = include_str!("../../queries/textobjects.scm");
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");

#[cfg(test)]
Expand Down
81 changes: 31 additions & 50 deletions corpus/declarations.txt
Original file line number Diff line number Diff line change
@@ -1,37 +1,18 @@
================================================================================
Dependencies
Modules
================================================================================

dep english;
mod english;

dep english {}

dep english {
dep greetings {}
dep farewells {}
}

dep bar/baz;
pub mod english;

--------------------------------------------------------------------------------

(source_file
(dep_item
(mod_item
(identifier))
(dep_item
(identifier)
(declaration_list))
(dep_item
(identifier)
(declaration_list
(dep_item
(identifier)
(declaration_list))
(dep_item
(identifier)
(declaration_list))))
(dep_item
(identifier)
(mod_item
(visibility_modifier)
(identifier)))

================================================================================
Expand Down Expand Up @@ -777,6 +758,28 @@ const OWNER_ADDRESS = Address::from(0x8900c5bec4ca97d4febf9ceb4754a60d782abbf3cd
(arguments
(integer_literal)))))

================================================================================
Type aliases
================================================================================

type Inch = u64;
type Name<T> = Vec<T>;

--------------------------------------------------------------------------------

(source_file
(type_item
(type_identifier)
(primitive_type))
(type_item
(type_identifier)
(type_parameters
(type_identifier))
(generic_type
(type_identifier)
(type_arguments
(type_identifier)))))

================================================================================
Empty statements
================================================================================
Expand Down Expand Up @@ -808,7 +811,7 @@ struct Baz;
struct Foo;

#[cfg(target_os = "macos")]
dep macos_only {}
mod macos_only;

#![allow(clippy::useless_transmute)]

Expand Down Expand Up @@ -850,9 +853,8 @@ fn receive_funds() {
arguments: (token_tree
(identifier)
(string_literal))))
(dep_item
name: (identifier)
body: (declaration_list))
(mod_item
name: (identifier))
(inner_attribute_item
(attribute
(identifier)
Expand All @@ -879,27 +881,6 @@ fn receive_funds() {
body: (block
(line_comment))))

================================================================================
Inner attributes
================================================================================

dep macos_only {
#![cfg(target_os = "macos")]
}

--------------------------------------------------------------------------------

(source_file
(dep_item
name: (identifier)
body: (declaration_list
(inner_attribute_item
(attribute
(identifier)
arguments: (token_tree
(identifier)
(string_literal)))))))

================================================================================
Key-Value Attribute Expressions
================================================================================
Expand Down
66 changes: 61 additions & 5 deletions corpus/keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ configurable {
C8: u64 = 0, // Unused - should not show up in the JSON file
}

configurable {
// Only compiles for FVM
#[cfg(target = "fuel")]
CFG_VALUE: u64 = 40,
// Only compiles for EVM
#[cfg(target = "evm")]
CFG_VALUE: () = (),
// Never compiles
#[cfg(target = "fuel")]
#[cfg(target = "evm")]
CFG_VALUE: () = (),
}

--------------------------------------------------------------------------------

(source_file
Expand All @@ -116,7 +129,7 @@ configurable {
(storage_content
(field_declaration
(field_identifier)
(type_identifier))
(primitive_type))
(integer_literal))
(storage_content
(field_declaration
Expand Down Expand Up @@ -173,7 +186,51 @@ configurable {
(field_identifier)
(primitive_type))
(integer_literal))
(line_comment))))
(line_comment)))
(configurable_item
(storage_content_list
(line_comment)
(storage_content
(attribute_item
(attribute
(identifier)
(token_tree
(identifier)
(string_literal))))
(field_declaration
(field_identifier)
(primitive_type))
(integer_literal))
(line_comment)
(storage_content
(attribute_item
(attribute
(identifier)
(token_tree
(identifier)
(string_literal))))
(field_declaration
(field_identifier)
(unit_type))
(unit_expression))
(line_comment)
(storage_content
(attribute_item
(attribute
(identifier)
(token_tree
(identifier)
(string_literal))))
(attribute_item
(attribute
(identifier)
(token_tree
(identifier)
(string_literal))))
(field_declaration
(field_identifier)
(unit_type))
(unit_expression)))))

================================================================================
ABI items
Expand Down Expand Up @@ -615,14 +672,13 @@ script;

predicate;

library my_lib;
library;

--------------------------------------------------------------------------------

(source_file
(program_type)
(program_type)
(program_type)
(program_type
(identifier)))
(program_type))

6 changes: 6 additions & 0 deletions corpus/literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Integer literals
0o70_i16;
0b1111_1111_1001_0000_i32;
1u128;
0x0000000000000000000000000000000000000000000000000000000000000001u256;
0x0000000000000000000000000000000000000000000000000000000000000001b256;

--------------------------------------------------------------------------------

Expand All @@ -37,6 +39,10 @@ Integer literals
(integer_literal))
(expression_statement
(integer_literal))
(expression_statement
(integer_literal))
(expression_statement
(integer_literal))
(expression_statement
(integer_literal)))

Expand Down
18 changes: 9 additions & 9 deletions corpus/types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,28 @@ let b: *const str;
Generic types
================================================================================

let a: B<C>;
let d: E<F, str>;
let j: H<K=L>;
type A = B<C>;
type D = E<F, str>;
type J = H<K=L>;

--------------------------------------------------------------------------------

(source_file
(let_declaration
(identifier)
(type_item
(type_identifier)
(generic_type
(type_identifier)
(type_arguments
(type_identifier))))
(let_declaration
(identifier)
(type_item
(type_identifier)
(generic_type
(type_identifier)
(type_arguments
(type_identifier)
(primitive_type))))
(let_declaration
(identifier)
(type_item
(type_identifier)
(generic_type
(type_identifier)
(type_arguments
Expand Down
Loading
Loading