|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
//! Parse code with tree-sitter language implementations.
|
|
|
|
|
//! Load and configure parsers written with tree-sitter.
|
|
|
|
|
|
|
|
|
|
use std::{borrow::Borrow, collections::HashSet, ffi::OsStr};
|
|
|
|
|
|
|
|
|
|
@ -10,21 +10,34 @@ use crate::{
|
|
|
|
|
syntax::{AtomKind, Syntax},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// Configuration for a tree-sitter parser.
|
|
|
|
|
pub struct TreeSitterConfig {
|
|
|
|
|
/// The language name shown to the user.
|
|
|
|
|
pub name: &'static str,
|
|
|
|
|
|
|
|
|
|
/// The tree-sitter language parser.
|
|
|
|
|
pub language: Language,
|
|
|
|
|
// Tree-sitter nodes that we treat as indivisible atoms. This is
|
|
|
|
|
// particularly useful for strings, as some grammars use several
|
|
|
|
|
// nodes for a single string literal. We don't want to say
|
|
|
|
|
// e.g. the closing string delimiter moved, as it's confusing and
|
|
|
|
|
// not well-balanced syntax.
|
|
|
|
|
//
|
|
|
|
|
// This is also useful for when tree-sitter nodes don't include
|
|
|
|
|
// all the children in the source. This is known limitation of
|
|
|
|
|
// tree-sitter, and occurs more often for complex string syntax.
|
|
|
|
|
// https://github.com/tree-sitter/tree-sitter/issues/1156
|
|
|
|
|
|
|
|
|
|
/// Tree-sitter nodes that we treat as indivisible atoms.
|
|
|
|
|
///
|
|
|
|
|
/// This is particularly useful for strings, as some grammars use
|
|
|
|
|
/// several nodes for a single string literal. We don't want to
|
|
|
|
|
/// say e.g. the closing string delimiter moved, as it's confusing
|
|
|
|
|
/// and not well-balanced syntax.
|
|
|
|
|
///
|
|
|
|
|
/// This is also useful for when tree-sitter nodes don't include
|
|
|
|
|
/// all the children in the source. This is known limitation of
|
|
|
|
|
/// tree-sitter, and occurs more often for complex string syntax.
|
|
|
|
|
/// <https://github.com/tree-sitter/tree-sitter/issues/1156>
|
|
|
|
|
atom_nodes: HashSet<&'static str>,
|
|
|
|
|
|
|
|
|
|
/// We want to consider delimiter tokens as part of lists, not
|
|
|
|
|
/// standalone atoms. Tree-sitter includes delimiter tokens, so
|
|
|
|
|
/// mark which token pairs we consider to be delimiters.
|
|
|
|
|
delimiter_tokens: Vec<(&'static str, &'static str)>,
|
|
|
|
|
|
|
|
|
|
/// Tree-sitter queries used for syntax highlighting this
|
|
|
|
|
/// language.
|
|
|
|
|
highlight_queries: &'static str,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|