ParSitter.CodeType
struct Code
    code::String
end

Wrapper object around a string that is supposed to contain code.

source
ParSitter.ParseResultType
struct ParseResult
    file::Union{Nothing, String}
    parsed::String
end

Parsing result object. It is returned from parsing ::Code and ::File objects.

source
ParSitter.TreeQueryExprType
TreeQueryExpr{T}(head::T, children::Vector{TreeQueryExpr})

Structure used for the AbstractTrees interface. It allows to use Tuple-based S-expressions as query trees. ::T is the type of value used for the head as well as children. Usually, nodes are ::Strings.

source
ParSitter.TreeQueryNodeType
TreeQueryNode(value::String, type:String)

Structure used for holding values and types for query nodes generated from tree-sitter parsed code.

source
Base.convertMethod

Convert a tree t to a TreeQueryExpr. The node value is returned by nodevalue and children of the node returned by children.

source
Base.parseMethod
parse(code::Code, language::String; escape_chars=false, print_code=false)

Parsing function for ::Code objects. Calls the _parse function for ::Strings. Use escape_chars=true if the code contains explicitly the , and characters. If print_code is true it will print the code.

source
Base.parseMethod
parse(code::Directory, language::String)

Parsing function for ::Directory objects. Reads the contents of the directory and for supported files, calls the parsing method for ::File objects.

source
Base.parseMethod
parse(code::File, language::String)

Parsing function for ::File objects. Reads the content of the file, sends it to tree-sitter for parsing and returns a ParseResult with parse results.

source
ParSitter._parseMethod
_parse(code::String, language::String; escape_chars=false, print_code=false)

The code parsing function for ::String inputs. It is part of the internal API and should not be used. Use escape_chars=true if the code contains explicitly the , and characters. If print_code is true it will print the code.

source
ParSitter.build_tq_treeMethod
build_tq_tree(t::Tuple)

Build a tree query expression tree out of a nested tuple: the assumption is that the first element of each tuple is the head of the expression, the rest are children.

source
ParSitter.build_xml_treeMethod
build_xml_tree(parse_output::ParseResult)

Builds an XML tree out of the parsing results contained in a ::ParseResult object.

source
ParSitter.build_xml_treeMethod
build_xml_tree(tree_sitter_xml_ast::String)

Builds an XML tree out of the XML output from tree-sitter. Internally, calls EzXML.parsexml.

source
ParSitter.get_captureMethod

Function that returns captured values from a query. If the key does not exist nothing is returned.

source
ParSitter.is_capture_nodeMethod
is_capture_node(n; capture_sym=DEFAULT_CAPTURE_SYM)

Function that checks whether a node is a 'capture node' i.e. value of the form "match@capture_key" and returns a NamedTuple with the result and the capture key string

julia> ParSitter.is_capture_node("value@capture_key")
(is_match = true, capture_key = "capture_key")

julia> ParSitter.is_capture_node("value@capture_key", capture_sym="@@")
(is_match = false, capture_key = nothing)
source
ParSitter.match_treeMethod
function match_tree(target_tree,
                    query_tree;
                    match_cache=Dict(),
                    captured_symbols=MultiDict(),
                    match_type=:strict,
                    is_capture_node=is_capture_node,
                    target_tree_nodevalue=AbstractTrees.nodevalue,
                    query_tree_nodevalue=AbstractTrees.nodevalue,
                    capture_function=AbstractTrees.nodevalue,
                    node_comparison_yields_true=(args...)->false,
                    node_equality_function = Base.isequal)

Function that searches a query_tree into a target_tree. It returns a vector of sub-tree matches, where each element is a Tuple that contains: • the result of the match • any captured values • the trees that were compared.

To capture a value, the function is_capture_node must return true for a given query node. One example is using query nodes of the form "nodevalue@capture_variable". In the matching process, the query and target node values are extracted using query_tree_nodevalue and target_tree_nodevalue respectively and compared. If they match, the target_tree node value is captured by applying capture_function to the node and stored as MultiDict("capture_variable"=>captured_target_node_value)).

The match_type argument, for • :strict values will require trees to have the same order and number of leafs/sub-trees as the query tree. • :nonstrict matching allows for additional leaves and sub-trees of the target tree; when matching, all permutations possible of query tree length will be used to match the query. • :speculative matching will stops after the first match for each sub-tree/leaf.

Tree comparisons are also hashed and the result as well as captured symbols are stored in match_cache for quick retrieval.

Specification of the node equality function can be done through the node_equality_function keyword argument; default is Base.isequal.

source
ParSitter.populate!Method

Reads the contents of language_directory and populates the constants: LANGUAGE_MAP, FILE_EXTENSIONS and DEFAULT_TYPE_REPLACEMENTS.

source
ParSitter.print_code_treeMethod
print_code_tree(code::String, language::String; maxdepth=100)

Prints the AST of a gieven piece of code written in a given programming language.

source
ParSitter.prune!Method
prune!(node, value; nodevalue_function = AbstractTrees.nodevalue)

Recursively prunes an AbstractTrees.jl-compatible tree (in-place) rooted at node. Pruning rule (applied at every level): after recursively pruning all child subtrees, remove any direct child whose subtree contains value in any of its nodes (including the child node itself). value is the input parameter (e.g. call as prune!(root, nodevalue(root)) to prune duplicates of the root value). Assumes AbstractTrees.children(node) returns a mutable Vector, standard for most custom Node types. A custom function nodevalue_function can be applied to each node to extract its value for the comparision with value.

source
ParSitter.queryMethod

Query a tree with another tree. This will match the query_tree with all sub-trees of target_tree. Both trees should support the AbstractTrees interface.

source