1-
2- //! This crate provides FSharp language support for the [tree-sitter][] parsing
3- //! library. There are separate languages for implementation, (`.fs`),
4- //! signature (`.fsi`).
1+ //! This crate provides Fsharp language support for the [tree-sitter][] parsing library.
52//!
6- //! Typically, you will use the [language_fsharp][language func] function to add
7- //! this language to a tree-sitter [Parser][], and then use the parser to parse
8- //! some code:
3+ //! Typically, you will use the [language][language func] function to add this language to a
4+ //! tree-sitter [Parser][], and then use the parser to parse some code:
95//!
106//! ```
117//! let code = r#"
12- //! module M =
13- //! let x = 0
148//! "#;
159//! let mut parser = tree_sitter::Parser::new();
10+ //! let language = tree_sitter_fsharp::LANGUAGE_FSHARP;
1611//! parser
17- //! .set_language(&tree_sitter_fsharp::language_fsharp ())
18- //! .expect("Error loading FSharp grammar ");
12+ //! .set_language(&language.into ())
13+ //! .expect("Error loading Fsharp parser ");
1914//! let tree = parser.parse(code, None).unwrap();
2015//! assert!(!tree.root_node().has_error());
2116//! ```
2217//!
2318//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
24- //! [language func]: fn.language_fsharp .html
19+ //! [language func]: fn.language .html
2520//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
2621//! [tree-sitter]: https://tree-sitter.github.io/
2722
28- use tree_sitter :: Language ;
23+ use tree_sitter_language :: LanguageFn ;
2924
3025extern "C" {
31- fn tree_sitter_fsharp ( ) -> Language ;
32- fn tree_sitter_fsharp_signature ( ) -> Language ;
33- }
34-
35- /// Get the tree-sitter [Language][] for FSharp.
36- ///
37- /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
38- pub fn language_fsharp ( ) -> Language {
39- unsafe { tree_sitter_fsharp ( ) }
26+ fn tree_sitter_fsharp ( ) -> * const ( ) ;
27+ fn tree_sitter_fsharp_signature ( ) -> * const ( ) ;
4028}
4129
42- /// Get the tree-sitter [Language][] for FSharp signature.
43- ///
44- /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
45- pub fn language_fsharp_signature ( ) -> Language {
46- unsafe { tree_sitter_fsharp_signature ( ) }
47- }
30+ /// The tree-sitter [`LanguageFn`] for this grammar.
31+ pub const LANGUAGE_FSHARP : LanguageFn = unsafe { LanguageFn :: from_raw ( tree_sitter_fsharp) } ;
32+ pub const LANGUAGE_SIGNATURE : LanguageFn = unsafe { LanguageFn :: from_raw ( tree_sitter_fsharp_signature) } ;
4833
49- /// The content of the [`node-types.json`][] file for FSharp .
34+ /// The content of the [`node-types.json`][] file for this grammar .
5035///
5136/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
52- pub const FSHARP_NODE_TYPES : & ' static str = include_str ! ( "../../fsharp/src/node-types.json" ) ;
37+ pub const FSHARP_NODE_TYPES : & str = include_str ! ( "../../fsharp/src/node-types.json" ) ;
38+ pub const SIGNATURE_NODE_TYPES : & str = include_str ! ( "../../fsharp_signature/src/node-types.json" ) ;
5339
54- /// The content of the [`node-types.json`][] file for FSharp signature.
55- ///
56- /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
57- pub const SIGNATURE_NODE_TYPES : & ' static str = include_str ! ( "../../fsharp_signature/src/node-types.json" ) ;
58-
59- /// The syntax highlighting query for FSharp.
60- pub const HIGHLIGHTS_QUERY : & ' static str = include_str ! ( "../../queries/highlights.scm" ) ;
40+ // NOTE: uncomment these to include any queries that this grammar contains:
6141
62- /// The local-variable syntax highlighting query for FSharp.
63- pub const LOCALS_QUERY : & ' static str = include_str ! ( "../../queries/locals.scm" ) ;
64-
65- /// The symbol tagging query for FSharp.
66- pub const TAGGING_QUERY : & ' static str = include_str ! ( "../../queries/tags.scm" ) ;
42+ pub const HIGHLIGHTS_QUERY : & str = include_str ! ( "../../queries/highlights.scm" ) ;
43+ pub const INJECTIONS_QUERY : & str = include_str ! ( "../../queries/injections.scm" ) ;
44+ pub const LOCALS_QUERY : & str = include_str ! ( "../../queries/locals.scm" ) ;
45+ pub const TAGS_QUERY : & str = include_str ! ( "../../queries/tags.scm" ) ;
6746
6847#[ cfg( test) ]
6948mod tests {
7049 #[ test]
7150 fn test_fsharp ( ) {
7251 let mut parser = tree_sitter:: Parser :: new ( ) ;
7352 parser
74- . set_language ( & super :: language_fsharp ( ) )
75- . expect ( "Error loading FSharp grammar " ) ;
53+ . set_language ( & super :: LANGUAGE_FSHARP . into ( ) )
54+ . expect ( "Error loading Fsharp parser " ) ;
7655
7756 let code = r#"
7857 module M =
@@ -88,8 +67,8 @@ mod tests {
8867 fn test_fsharp_signature ( ) {
8968 let mut parser = tree_sitter:: Parser :: new ( ) ;
9069 parser
91- . set_language ( & super :: language_fsharp_signature ( ) )
92- . expect ( "Error loading FSharp signature grammar " ) ;
70+ . set_language ( & super :: LANGUAGE_SIGNATURE . into ( ) )
71+ . expect ( "Error loading Fsharp parser " ) ;
9372
9473 let code = r#"
9574 module M =
@@ -101,4 +80,3 @@ mod tests {
10180 assert ! ( !root. has_error( ) ) ;
10281 }
10382}
104-
0 commit comments