tree-sitter-xquery
Version:
XQuery tree-sitter
299 lines (289 loc) • 12.2 kB
HTML
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta charset="utf-8" />
<title>Playground for tree-sitter XQuery</title>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/codemirror.min.css"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.css"
/>
<link
rel="stylesheet"
href="playground.css"
/>
<link
rel="icon"
type="image/png"
href="https://tree-sitter.github.io/tree-sitter/assets/images/favicon-32x32.png"
sizes="32x32"
/>
<link
rel="icon"
type="image/png"
href="https://tree-sitter.github.io/tree-sitter/assets/images/favicon-16x16.png"
sizes="16x16"
/>
</head>
<body>
<div id="playground-container" style="visibility: visible">
<header>
<div class="header-item">
<bold>XQuery Tree-sitter Playground</bold>
</div>
<div class="header-item">
<label for="logging-checkbox">log</label>
<input id="logging-checkbox" type="checkbox" />
</div>
<div class="header-item">
<label for="query-checkbox">query</label>
<input id="query-checkbox" type="checkbox" checked="checked" />
</div>
<div class="header-item">
<label for="update-time">parse time: </label>
<span id="update-time"></span>
</div>
<select id="language-select" style="display: none">
<option value="xquery" selected="selected">Parser</option>
</select>
</header>
<main>
<div id="input-pane">
<div id="code-container">
<textarea id="code-input" style="display: none">
"Hello, tree-sitter! ",
``[ time: `{current-time()}` ]``,
my:three-argument-function(1,2,3),
local:two-argument-function((1,2),3),
map {"A":1,"B":2},
for $v in $doc//video return $v,
doc("books.xml")/bookstore/book[price<30],
element date { current-date() }
</textarea>
</div>
<div id="query-container" style="">
<textarea id="query-input" style="display: none">
(type_declaration "as" ) .declaration
(parenthesized_item_type . "(" ")" ) .parenthesized_item
(sequence_type "empty-sequence" "(" ")" ) .empty_sequence
(atomic_or_union_type) .atomic_or_union
(name_test) .name_test
kind_test: (_) .kind_test
(any_item) .any_test
func_test: (_) .func_test
(occurrence_indicator) .occurrence_indicator
(wildcard) .wildcard
; 3.1 Primary Expressions
; 3.1.1 Literals
(string_literal [ "'" "\""] .bracket.string )
[(char_data) (string_constructor_chars) ]
[ (escape_quote) (escape_apos) (escape_enclosed) (char_ref) (predefined_entity_ref) ] .special
; numbers
[(integer_literal) (decimal_literal) (double_literal)]
; 3.1.2 Variable References
(var_ref) .reference
;3.1.3 Parenthesized Expressions
(parenthesized_expr [ "(" ")" ] .bracket.paren_expr)
;3.1.4 Context Item Expression
(context_item_expr) .context
;3.1.5 Static Function Calls
; A.3 Reserved Function Names
(function_call .
[
ncname: (identifier) .call (#not-any-of? .call "array" "attribute" "comment" "document-node" "element" "empty-sequence" "function" "if" "item" "map" "namespace-node" "node" "processing-instruction" "schema-attribute" "schema-element" "switch" "text" "typeswitch")
prefixed: (identifier)
(uri_qualified_name) .call.URIQualifiedName
]
( ":" .delimiter.QName .
local: (identifier) .call
)*
(arg_list) .call
)
(arg_list arg: (placeholder) .placeholder)
; 3.2.2 Dynamic Function Calls
; 3.1.6 Named Function References
(named_function_ref "#" .delimiter . (integer_literal) ) .named_function_ref
; 3.1.7 Inline Function Expressions
(inline_function_expr
((annotation) .annotation)?
"function"
"(" .bracket.params
(param_list)*
")" .bracket.params
) .inline
; 3.1.8 Enclosed Expressions
(enclosed_expr [ "{" "}" ] .bracket.enclosed_expr)
; 3.2 Postfix Expressions
(arg_list [ "(" ")" ] .bracket.arg_list )
(predicate [ "[" "]" ] .bracket.predicate)
; 3.11.3.2 Postfix Lookup
(postfix_lookup "?" .postfix_lookup key: (_) .key_specifier)
; 3.3 Path Expressions
[ "/" "//" ] .path
axis: (_) .axis_step
; 3.4 Sequence Expressions
; 3.4.1 Constructing Sequences
; parenthesized_expr
(range_expr [ "to" ] .range)
;3.4.2 Combining Node Sequences
(union_expr [ "union" "|" ] .union );
(intersect_except_expr [ "intersect" "except"] .intersect_except)
;3.5 Arithmetic Expressions
(additive_expr [ "-" "+"] .additive)
(multiplicative_expr [ "*" "div" "idiv" "mod"] .multiplicative )
(unary_expr [ "-" "+"] )
;3.6 String Concatenation Expressions
(string_concat_expr ["||"] .concat )
;3.7 Comparison Expressions
(comparison_expr [ "eq" "ne" "lt" "le" "gt" "ge" "is" "=" "!=" "<" "<=" ">" ">=" "<<" ">>" ] .comparison)
; 3.8 Logical Expressions
(and_expr [ "and" ] .and)
(or_expr [ "or" ] .or)
;3.9.1 Direct Element Constructors: tag tag.attribute tag.delimiter
(start_tag . "<" .delimiter ">" .delimiter ) .start
(end_tag . "</" .delimiter ">" .delimiter) .end
(empty_tag . "<" .delimiter "/>" .delimiter) .empty
(direct_attribute "=" .assignment.attr) .attribute
(attribute_value ["'" "\"" ] .bracket)
; 3.9.3 Computed Constructors
computed_constructor: (_ .
[ "element" "attribute" "document" "text" "processing-instruction"
"comment" "namespace" ] .computed_constructor ) .node
; 3.10 String Constructors
(string_constructor . "``[" "]``" ) .string
(interpolation . "`{" "}`" ) .interpolation
; 3.11 Maps and Arrays
(map_constructor "map" "{" "}" ) .constructor.map
(map_entry ":" .delimiter.map )
(square_array_constructor "[" "]" ) .constructor.array
(curly_array_constructor "array" (enclosed_expr)) .constructor.array
; 3.11.3 The Lookup Operator ("?") for Maps and Arrays
; Unary lookup is used in predicates (e.g. $map[?name='Mike'] or with the simple map operator
;3.11.3.1 Unary Lookup
(unary_lookup "?" .lookup.unary key: (_) .key_specifier)
; 3.12 FLWOR Expressions TODO
(for_clause . "for") .for_clause
(for_binding (["allowing" "empty" "at" "in" ] .for_binding)*) .for_binding
(let_clause . "let" ) .let_clause
(let_binding) .let_binding
[ (count_clause "count") (where_clause "where")
(order_by_clause [ "stable" "order" "by" "ascending" "collation" "descending" "empty" "greatest" "least" "collation"] )
(group_by_clause "group" "by") (grouping_spec)
] .flwor.intermediate
(return_clause "return" .return.flwor)
; 3.13 Ordered and Unordered Expressions
(unordered_expr "unordered") .unordered_expr
(ordered_expr "ordered") .ordered_expr
; 3.14 Conditional Expressions
(if_expr "if" "then" "else") .if_expr
;3.15 Switch Expression
(switch_expr "switch" "default" "return") .switch_expr
(switch_clause "case" "return" ) .switch_clause
;3.16 Quantified Expressions
(quantified_expr ["some" "every"] "in") .quantified_expr
;3.17 Try/Catch Expressions
(try_catch_expr (try_clause "try") (catch_clause "catch")) .try_catch_expr
;3.18 Expressions on SequenceTypes
;3.18.1 Instance Of
(instance_of_expr) .instance_of;
;3.18.2 Typeswitch
(typeswitch_expr "typeswitch" "default" "return" ) .block.typeswitch
(typeswitch_case_clause "case" "return" ) .case.typeswitch
;3.18.3 Cast
(cast_expr "cast" "as" ) .block.cast
;3.18.4 Castable
(castable_expr "castable" "as") .block.castable
;3.18.6 Treat
(treat_expr "treat" "as" ) .block.treat_as
;3.19 Simple map operator (!)
(bang_expr "!" .bang )
; 3.20 Arrow operator (=>)
(arrow_expr "=>" .arrow )
(arrow_function)
; 3.21 Validate Expressions TODO?
; 3.22 Extension Expressions TODO?
;4 Modules and Prologs
;4.1 Version Declaration
(version_declaration ["version" "encoding"] .version ) .version
; 4.2 Module Declaration
(module_declaration) .module
; 4.3 Boundary-space Declaration
(boundary_space_declaration "boundary-space" [ "preserve" "strip"] ) .boundary_space
; 4.4 Default Collation Declaratiodefault_collation_declarationn
(default_collation_declaration "default" "collation" ) .default_collation
; 4.5 Base URI Declaration
(base_uri_declaration "base-uri" ) .base_uri
; 4.6 Construction Declaration
(construction_declaration "construction" . ["strip" "preserve" ] ) .construction
; 4.7 Ordering Mode Declaration
(ordering_mode_declaration "ordering" . ["ordered" "unordered"] ) .ordering_mode
; 4.8 Empty Order Declaration
(empty_order_declaration "default" . "order" . "empty" . ["greatest" "least" ] ) .empty_order
; 4.9 Copy-Namespaces Declaration
(copy_namespaces_declaration "copy-namespaces" . ["preserve" "no-preserve"] . ["inherit" "no-inherit"] ) .copy_namespaces
; 4.10 Decimal Format Declaration
(decimal_format_declaration "decimal-format" .decimal_format) .decimal_format
(df_property_define _ .df_property "=" .df_property)
; 4.11 Schema Import
(schema_import "schema" .schema_import ) .schema_import
(schema_prefix "default" "element" "namespace" ) .schema_prefix
; 4.12 Module Import
(module_import "module" ) .module_import.
; 4.13 Namespace Declaration
(namespace_declaration) .namespace_declaration
;4.14 Default Namespace Declaration
(default_namespace_declaration "default" [ "element" "function" ] "namespace" ) .default_namespace
; 4.15 Annotations
;4.16 Variable Declaration
(variable_declaration ((annotation) .annotation)? "variable" ) .variable
; 4.17 Context Item Declaration
(context_item_declaration "context" "item" ) .context_item
; 4.18 Function Declaration
(function_declaration ((annotation) .annotation)? "function"
"(" .bracket ")" .bracket) .function
; 33 ref by: FunctionDecl InlineFunctionExpr
(param_list) .param_list
; defaults in EQNames
":" .delimiter.QName
prefixed: (identifier) .QName.prefixed
; assigning values token: ContextItemDecl VarDecl GroupingSpec LetBinding
":=" .assignment
; ref ContextItemDecl VarDecl FunctionDecl
"external" .external
; namespace define pattern in declarations
(_ "namespace" (identifier) "=" .namespace_assignment)
; end of declaration delimiter
(_ ";" .delimiter.declaration_separator .)
;4.2 Module Declaration
"," .delimiter
(comment)
(ERROR)
</textarea>
</div>
</div>
<div id="output-container-scroll">
<pre
id="output-container"
class="highlight"
tabindex="0"
style="counter-increment: clusterize-counter 0"
></pre>
</div>
</main>
</div>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
crossorigin="anonymous"
></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/codemirror.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.js"></script>
<script>
LANGUAGE_BASE_URL = "";
</script>
<script src="tree-sitter.js"></script>
<script src="playground.js"></script>
</body>
</html>