rescript-lang / tree-sitter-rescript Goto Github PK
View Code? Open in Web Editor NEWReScript parser for Tree-Sitter
License: MIT License
ReScript parser for Tree-Sitter
License: MIT License
It could be great if:
list{...}
is highlightothers
in my screenshot is highlightFor references, the playground highlight list{}
but not the second argument, so not sure if highlight others
it's a great thing.
https://rescript-lang.org/try?code=DYUwLgBAtgngMgSwM6QLwWMsBvAjAGggCZCBmAXwChRIBDAOwHswALEAJ0RQnUxWwAMhAHSjYXMFSA}
let int32 = 42l
(source_file [0, 0] - [1, 0]
(ERROR [0, 0] - [0, 15]
(let_binding [0, 0] - [0, 14]
(value_identifier [0, 4] - [0, 9])
(number [0, 12] - [0, 14]))
(ERROR [0, 14] - [0, 15])))
giving
type t = [ @as("42") #fortyTwo ]
the result is
(source_file [0, 0] - [2, 0]
(type_declaration [0, 0] - [0, 32]
(type_identifier [0, 5] - [0, 6])
(polyvar_type [0, 9] - [0, 32]
(ERROR [0, 11] - [0, 20]
(number [0, 16] - [0, 18]))
(polyvar_declaration [0, 21] - [0, 30]
(polyvar_identifier [0, 21] - [0, 30])))))
For javascript, undefined have it's own color. I think we can have a dedicated color for unit ?
exception Exit = Terminate
(source_file [0, 0] - [1, 0]
(ERROR [0, 0] - [0, 26]
(variant_identifier [0, 10] - [0, 14])
(module_identifier [0, 17] - [0, 26])))
../../test-filetypes/out.res 0 ms (ERROR [0, 0] - [0, 26])
module type IntSum = {
let x: int
let y: int
let add: (int, int) => int
}
(source_file [0, 0] - [6, 0]
(module_declaration [0, 0] - [5, 1]
name: (module_identifier [0, 12] - [0, 18])
definition: (block [0, 21] - [5, 1]
(ERROR [1, 2] - [2, 12]
(let_binding [1, 2] - [1, 12]
(value_identifier [1, 6] - [1, 7])
(type_annotation [1, 7] - [1, 12]
(type_identifier [1, 9] - [1, 12])))
(let_binding [2, 2] - [2, 12]
(value_identifier [2, 6] - [2, 7])
(type_annotation [2, 7] - [2, 12]
(type_identifier [2, 9] - [2, 12]))))
(let_binding [4, 2] - [4, 28]
(value_identifier [4, 6] - [4, 9])
(type_annotation [4, 9] - [4, 28]
(function_type [4, 11] - [4, 28]
(function_type_parameters [4, 11] - [4, 21]
(parameter [4, 12] - [4, 15]
(type_identifier [4, 12] - [4, 15]))
(parameter [4, 17] - [4, 20]
(type_identifier [4, 17] - [4, 20])))
(type_identifier [4, 25] - [4, 28])))))))
../../test-filetypes/out.res 0 ms (ERROR [1, 2] - [2, 12])
for i in startValueInclusive to endValueInclusive {
Js.log(i)
}
ERROR [0, 0] - [0, 49]
value_identifier [0, 0] - [0, 3]
ERROR [0, 4] - [0, 14]
ERROR [0, 29] - [0, 35]
expression_statement [0, 50] - [2, 1]
block [0, 50] - [2, 1]
expression_statement [1, 2] - [1, 11]
call_expression [1, 2] - [1, 11]
function: value_identifier_path [1, 2] - [1, 8]
module_identifier [1, 2] - [1, 4]
value_identifier [1, 5] - [1, 8]
arguments: arguments [1, 8] - [1, 11]
value_identifier [1, 9] - [1, 10]
Hey !
giving
let color = color =>
switch color {
| #...blue => Js.log("blue")
| #...red => Js.log("red")
}
this will output to
let_binding [0, 0] - [4, 3]
value_identifier [0, 4] - [0, 9]
function [0, 12] - [4, 3]
parameter: value_identifier [0, 12] - [0, 17]
body: switch_expression [1, 2] - [4, 3]
value_identifier [1, 9] - [1, 14]
ERROR [2, 2] - [3, 28]
ERROR [2, 4] - [2, 22]
ERROR [2, 8] - [2, 12]
module_identifier [2, 16] - [2, 18]
ERROR [2, 19] - [2, 22]
ERROR [2, 23] - [3, 21]
string [2, 23] - [2, 29]
string_fragment [2, 24] - [2, 28]
ERROR [3, 8] - [3, 11]
ERROR [3, 18] - [3, 21]
string [3, 22] - [3, 27]
string_fragment [3, 23] - [3, 26]
When we want to generate types with GenType, we have to prefix the type
or the variable
with the export
keyword
Snippet:
export value = 5
export type t
Parse result
(source_file [0, 0] - [3, 0]
(mutation_statement [0, 0] - [0, 16]
(identifier [0, 0] - [0, 6])
(ERROR [0, 7] - [0, 12]
(ERROR [0, 7] - [0, 12]))
(number [0, 15] - [0, 16]))
(expression_statement [1, 0] - [1, 6]
(identifier [1, 0] - [1, 6]))
(type_declaration [1, 7] - [1, 13]
(type_identifier [1, 12] - [1, 13])))
The entire file is a comment node.
/**
module Debounce = {
// See: https://davidwalsh.name/javascript-debounce-function
let debounce = (~wait, fn) => {
let timeout = ref(None)
() => {
let unset = () => timeout := None
switch timeout.contents {
| Some(id) => Js.Global.clearTimeout(id)
| None => fn()
}
timeout := Some(Js.Global.setTimeout(unset, wait))
}
}
let debounce3 = (~wait, ~immediate=false, fn) => {
let timeout = ref(None)
(a1, a2, a3) => {
let unset = () => {
timeout := None
immediate ? fn(a1, a2, a3) : ()
}
switch timeout.contents {
| Some(id) => Js.Global.clearTimeout(id)
| None => fn(a1, a2, a3)
}
timeout := Some(Js.Global.setTimeout(unset, wait))
if immediate && timeout.contents === None {
fn(a1, a2, a3)
} else {
()
}
}
}
}
**/
module Unsafe = {
external elementAsString: React.element => string = "%identity"
}
module String = {
let camelCase: string => string = %raw("str => {
return str.replace(/-([a-z])/g, function (g) { return g[1].toUpperCase(); });
}")
let capitalize: string => string = %raw("str => {
return str && str.charAt(0).toUpperCase() + str.substring(1);
}")
}
module Json = {
@val @scope("JSON")
external prettyStringify: (Js.Json.t, @as(json`null`) _, @as(4) _) => string = "stringify"
}
module Url = {
let isAbsolute: string => bool = %raw(`
function(str) {
var r = new RegExp('^(?:[a-z]+:)?//', 'i');
if (r.test(str))
{
return true
}
return false;
}
`) //', 'i');
}
module Date = {
type intl
@new @scope("Intl")
external dateTimeFormat: (string, {"month": string, "day": string, "year": string}) => intl =
"DateTimeFormat"
@send external format: (intl, Js.Date.t) => string = "format"
let toDayMonthYear = (date: Js.Date.t) => {
dateTimeFormat("en-US", {"month": "short", "day": "numeric", "year": "numeric"})->format(date)
}
}
comment [0, 0] - [87, 0]
let a = (z, t) => z
let b = ((z, t)) => z
let c = ([z, t]) => z
z
and t
are not highlight for b and c
Most tree-sitter parsers commit the generated results of tree-sitter generate
as it means it's much easier to bring the parser in as a dependency.
As we discuss here : rescript-lang/vim-rescript#49 (comment)
should we highlight functions ?
Hey,
giving
let message = "Hello " ++ (theCompany :> string)
this returns
ERROR [0, 0] - [0, 48]
value_identifier [0, 4] - [0, 11]
string [0, 14] - [0, 22]
string_fragment [0, 15] - [0, 21]
value_identifier [0, 27] - [0, 37]
ERROR [0, 41] - [0, 47]
Listing some errors I got
mult =
and => x
is a ERROR
module Calc = {
%%private(let mult = (x, y) => x * y) // this line
let double = x => mult(x, 2)
let triple = x => mult(x, 3)
}
This code break the parser:
let person1 = Teacher({name: "Jane", age: 35})
let message = switch person1 {
| Teacher({name: "Mary" | "Joe"}) =>
`Hey, still going to the party on Saturday?`
| Teacher({name}) =>
// this is matched only if `name` isn't "Mary" or "Joe"
`Hello ${name}.`
| Student({name, reportCard: {passing: true, gpa}}) =>
`Congrats ${name}, nice GPA of ${Js.Float.toString(gpa)} you got there!`
| Student({
reportCard: {gpa: 0.0},
status: Vacations(daysLeft) | Sabbatical(daysLeft)
}) =>
`Come back in ${Js.Int.toString(daysLeft)} days!`
| Student({status: Sick}) =>
`How are you feeling?`
| Student({name}) =>
`Good luck next semester ${name}!`
}
Switch block return a ERROR:
type animal = Dog | Cat | Bird
let categoryId = switch (isBig, myAnimal) {
| (true, Dog) => 1
| (true, Cat) => 2
| (true, Bird) => 3
| (false, Dog | Cat) => 4
| (false, Bird) => 5
}
let decode = (~time: float, json: Js.Json.t): t => {
open! Json.Decode
try switch field("type", string, json) {
| "success" => Success(CompileSuccess.decode(~time, json))
| "unexpected_error" => UnexpectedError(field("msg", string, json))
| _ => Fail(CompileFail.decode(json))
} catch {
| DecodeError(errMsg) => Unknown(errMsg, json)
}
}
let_binding [0, 0] - [9, 1]
value_identifier [0, 4] - [0, 10]
function [0, 13] - [9, 1]
parameters: formal_parameters [0, 13] - [0, 44]
labeled_parameter [0, 14] - [0, 26]
value_identifier [0, 15] - [0, 19]
type_annotation [0, 19] - [0, 26]
type_identifier [0, 21] - [0, 26]
value_identifier [0, 28] - [0, 32]
type_annotation [0, 32] - [0, 43]
type_identifier_path [0, 34] - [0, 43]
module_identifier [0, 34] - [0, 36]
module_identifier [0, 37] - [0, 41]
type_identifier [0, 42] - [0, 43]
return_type: type_annotation [0, 44] - [0, 47]
type_identifier [0, 46] - [0, 47]
body: block [0, 51] - [9, 1]
open_statement [1, 2] - [1, 19]
module_identifier_path [1, 8] - [1, 19]
module_identifier [1, 8] - [1, 12]
module_identifier [1, 13] - [1, 19]
ERROR [2, 2] - [6, 9]
switch_expression [2, 6] - [6, 3]
call_expression [2, 13] - [2, 40]
function: value_identifier [2, 13] - [2, 18]
arguments: arguments [2, 18] - [2, 40]
string [2, 19] - [2, 25]
string_fragment [2, 20] - [2, 24]
value_identifier [2, 27] - [2, 33]
value_identifier [2, 35] - [2, 39]
switch_match [3, 2] - [3, 60]
string [3, 4] - [3, 13]
string_fragment [3, 5] - [3, 12]
expression_statement [3, 17] - [3, 60]
variant [3, 17] - [3, 60]
variant_identifier [3, 17] - [3, 24]
arguments [3, 24] - [3, 60]
call_expression [3, 25] - [3, 59]
function: value_identifier_path [3, 25] - [3, 46]
module_identifier [3, 25] - [3, 39]
value_identifier [3, 40] - [3, 46]
arguments: arguments [3, 46] - [3, 59]
labeled_argument [3, 47] - [3, 52]
label: value_identifier [3, 48] - [3, 52]
value_identifier [3, 54] - [3, 58]
switch_match [4, 2] - [4, 69]
string [4, 4] - [4, 22]
string_fragment [4, 5] - [4, 21]
expression_statement [4, 26] - [4, 69]
variant [4, 26] - [4, 69]
variant_identifier [4, 26] - [4, 41]
arguments [4, 41] - [4, 69]
call_expression [4, 42] - [4, 68]
function: value_identifier [4, 42] - [4, 47]
arguments: arguments [4, 47] - [4, 68]
string [4, 48] - [4, 53]
string_fragment [4, 49] - [4, 52]
value_identifier [4, 55] - [4, 61]
value_identifier [4, 63] - [4, 67]
switch_match [5, 2] - [5, 39]
value_identifier [5, 4] - [5, 5]
expression_statement [5, 9] - [5, 39]
variant [5, 9] - [5, 39]
variant_identifier [5, 9] - [5, 13]
arguments [5, 13] - [5, 39]
call_expression [5, 14] - [5, 38]
function: value_identifier_path [5, 14] - [5, 32]
module_identifier [5, 14] - [5, 25]
value_identifier [5, 26] - [5, 32]
arguments: arguments [5, 32] - [5, 38]
value_identifier [5, 33] - [5, 37]
expression_statement [6, 10] - [8, 3]
block [6, 10] - [8, 3]
ERROR [7, 2] - [7, 26]
variant [7, 4] - [7, 23]
variant_identifier [7, 4] - [7, 15]
arguments [7, 15] - [7, 23]
value_identifier [7, 16] - [7, 22]
expression_statement [7, 27] - [7, 48]
variant [7, 27] - [7, 48]
variant_identifier [7, 27] - [7, 34]
arguments [7, 34] - [7, 48]
value_identifier [7, 35] - [7, 41]
value_identifier [7, 43] - [7, 47]
The ERROR
node start at line 73
module Lexer = {
open Location
open Sgr
type token =
| Text({loc: Location.loc, content: string})
| Sgr({loc: Location.loc, raw: string, params: array<Sgr.param>})
| ClearSgr({loc: Location.loc, raw: string})
type state =
| Scan
| ReadSgr({startPos: int, content: string}) // contains collected data
| ReadText({startPos: int, content: string})
// Note: the acc array will be mutated in the process
let rec lex = (~acc: array<token>=[], ~state=Scan, p: Location.t): array<token> =>
if isDone(p) {
acc
} else {
switch state {
| Scan =>
// Checks for the next character and does a state
// transition according to the entity we are reading (SGR / Text)
let c = next(p)
let state = if c === esc {
ReadSgr({startPos: p.pos, content: ""})
} else {
ReadText({startPos: p.pos, content: c})
}
lex(~acc, ~state, p)
| ReadText({startPos, content}) =>
let c = next(p)
let endPos = p.pos - 1
// Determine if we are keep reading text, or start read SGRs
if c === esc {
let token = Text({
loc: {
startPos: startPos,
endPos: endPos,
},
content: content,
})
Js.Array2.push(acc, token)->ignore
lex(~acc, ~state=ReadSgr({startPos: p.pos, content: c}), p)
} else if isDone(p) {
let token = Text({
loc: {
startPos: startPos,
endPos: endPos,
},
content: content,
})
Js.Array2.push(acc, token)->ignore
acc
} else {
let content = content ++ c
lex(~acc, ~state=ReadText({startPos: startPos, content: content}), p)
}
| ReadSgr({startPos, content}) =>
let c = next(p)
// on termination
if c !== "[" && isAscii(c) {
let raw = content ++ c
let loc = {startPos: startPos, endPos: startPos + Js.String.length(raw) - 1}
let token = Js.Re.exec_(%re(`/\\[([0-9;]+)([\\x40-\\x7F])/`), raw)->(
x =>
switch x {
| Some(result) =>
let groups = Js.Re.captures(result)
switch Js.Nullable.toOption(groups[1]) {
| Some(str) =>
switch Js.String2.split(str, ";") {
| ["0"] => ClearSgr({loc: loc, raw: raw})
| other =>
let params = Belt.Array.map(other, s =>
switch s {
| "1" => Bold
| "30" => Fg(Black)
| "31" => Fg(Red)
| "32" => Fg(Green)
| "33" => Fg(Yellow)
| "34" => Fg(Blue)
| "35" => Fg(Magenta)
| "36" => Fg(Cyan)
| "37" => Fg(White)
| "40" => Bg(Black)
| "41" => Bg(Red)
| "42" => Bg(Green)
| "43" => Bg(Yellow)
| "44" => Bg(Blue)
| "45" => Bg(Magenta)
| "46" => Bg(Cyan)
| "47" => Bg(White)
| o => Unknown(o)
}
)
Sgr({loc: loc, raw: raw, params: params})
}
| None => Sgr({loc: loc, raw: raw, params: []})
}
| None => Sgr({loc: loc, raw: raw, params: []})
}
)
Js.Array2.push(acc, token)->ignore
lex(~acc, ~state=Scan, p)
} else {
lex(~acc, ~state=ReadSgr({startPos: startPos, content: content ++ c}), p)
}
}
}
// We hide the original implementation to prevent users
// to pass in their own `acc` array (this array is getting mutated and
// this could cause side-effects for the consumer otherwise)
let lex = (p: Location.t) => lex(p)
}
module_identifier [0, 7] - [0, 12]
open_statement [1, 2] - [1, 15]
module_identifier [1, 7] - [1, 15]
open_statement [2, 2] - [2, 10]
module_identifier [2, 7] - [2, 10]
type_declaration [4, 2] - [7, 48]
type_identifier [4, 7] - [4, 12]
variant_type [5, 4] - [7, 48]
variant_declaration [5, 6] - [5, 48]
variant_identifier [5, 6] - [5, 10]
variant_parameters [5, 10] - [5, 48]
record_type [5, 11] - [5, 47]
record_type_field [5, 12] - [5, 29]
property_identifier [5, 12] - [5, 15]
type_annotation [5, 15] - [5, 29]
type_identifier_path [5, 17] - [5, 29]
module_identifier [5, 17] - [5, 25]
type_identifier [5, 26] - [5, 29]
record_type_field [5, 31] - [5, 46]
property_identifier [5, 31] - [5, 38]
type_annotation [5, 38] - [5, 46]
type_identifier [5, 40] - [5, 46]
variant_declaration [6, 6] - [6, 69]
variant_identifier [6, 6] - [6, 9]
variant_parameters [6, 9] - [6, 69]
record_type [6, 10] - [6, 68]
record_type_field [6, 11] - [6, 28]
property_identifier [6, 11] - [6, 14]
type_annotation [6, 14] - [6, 28]
type_identifier_path [6, 16] - [6, 28]
module_identifier [6, 16] - [6, 24]
type_identifier [6, 25] - [6, 28]
record_type_field [6, 30] - [6, 41]
property_identifier [6, 30] - [6, 33]
type_annotation [6, 33] - [6, 41]
type_identifier [6, 35] - [6, 41]
record_type_field [6, 43] - [6, 67]
property_identifier [6, 43] - [6, 49]
type_annotation [6, 49] - [6, 67]
generic_type [6, 51] - [6, 67]
type_identifier [6, 51] - [6, 56]
type_arguments [6, 56] - [6, 67]
type_identifier_path [6, 57] - [6, 66]
module_identifier [6, 57] - [6, 60]
type_identifier [6, 61] - [6, 66]
variant_declaration [7, 6] - [7, 48]
variant_identifier [7, 6] - [7, 14]
variant_parameters [7, 14] - [7, 48]
record_type [7, 15] - [7, 47]
record_type_field [7, 16] - [7, 33]
property_identifier [7, 16] - [7, 19]
type_annotation [7, 19] - [7, 33]
type_identifier_path [7, 21] - [7, 33]
module_identifier [7, 21] - [7, 29]
type_identifier [7, 30] - [7, 33]
record_type_field [7, 35] - [7, 46]
property_identifier [7, 35] - [7, 38]
type_annotation [7, 38] - [7, 46]
type_identifier [7, 40] - [7, 46]
type_declaration [9, 2] - [12, 48]
type_identifier [9, 7] - [9, 12]
variant_type [10, 4] - [12, 48]
variant_declaration [10, 6] - [10, 10]
variant_identifier [10, 6] - [10, 10]
variant_declaration [11, 6] - [11, 47]
variant_identifier [11, 6] - [11, 13]
variant_parameters [11, 13] - [11, 47]
record_type [11, 14] - [11, 46]
record_type_field [11, 15] - [11, 28]
property_identifier [11, 15] - [11, 23]
type_annotation [11, 23] - [11, 28]
type_identifier [11, 25] - [11, 28]
record_type_field [11, 30] - [11, 45]
property_identifier [11, 30] - [11, 37]
type_annotation [11, 37] - [11, 45]
type_identifier [11, 39] - [11, 45]
comment [11, 48] - [11, 74]
variant_declaration [12, 6] - [12, 48]
variant_identifier [12, 6] - [12, 14]
variant_parameters [12, 14] - [12, 48]
record_type [12, 15] - [12, 47]
record_type_field [12, 16] - [12, 29]
property_identifier [12, 16] - [12, 24]
type_annotation [12, 24] - [12, 29]
type_identifier [12, 26] - [12, 29]
record_type_field [12, 31] - [12, 46]
property_identifier [12, 31] - [12, 38]
type_annotation [12, 38] - [12, 46]
type_identifier [12, 40] - [12, 46]
comment [14, 2] - [15, 2]
value_identifier [15, 10] - [15, 13]
parameters: formal_parameters [15, 16] - [15, 67]
labeled_parameter [15, 17] - [15, 38]
value_identifier [15, 18] - [15, 21]
type_annotation [15, 21] - [15, 35]
generic_type [15, 23] - [15, 35]
type_identifier [15, 23] - [15, 28]
type_arguments [15, 28] - [15, 35]
type_identifier [15, 29] - [15, 34]
default_value: array [15, 36] - [15, 38]
labeled_parameter [15, 40] - [15, 51]
value_identifier [15, 41] - [15, 46]
default_value: variant [15, 47] - [15, 51]
variant_identifier [15, 47] - [15, 51]
value_identifier [15, 53] - [15, 54]
type_annotation [15, 54] - [15, 66]
type_identifier_path [15, 56] - [15, 66]
module_identifier [15, 56] - [15, 64]
type_identifier [15, 65] - [15, 66]
return_type: type_annotation [15, 67] - [15, 81]
generic_type [15, 69] - [15, 81]
type_identifier [15, 69] - [15, 74]
type_arguments [15, 74] - [15, 81]
type_identifier [15, 75] - [15, 80]
call_expression [16, 7] - [16, 16]
function: value_identifier [16, 7] - [16, 13]
arguments: arguments [16, 13] - [16, 16]
value_identifier [16, 14] - [16, 15]
block [16, 17] - [18, 5]
expression_statement [17, 6] - [17, 9]
value_identifier [17, 6] - [17, 9]
value_identifier [19, 13] - [19, 18]
switch_match [20, 6] - [30, 28]
variant_pattern [20, 8] - [20, 12]
variant_identifier [20, 8] - [20, 12]
comment [21, 8] - [21, 57]
comment [22, 8] - [22, 73]
let_binding [23, 8] - [23, 23]
value_identifier [23, 12] - [23, 13]
call_expression [23, 16] - [23, 23]
function: value_identifier [23, 16] - [23, 20]
arguments: arguments [23, 20] - [23, 23]
value_identifier [23, 21] - [23, 22]
let_binding [25, 8] - [29, 9]
value_identifier [25, 12] - [25, 17]
if_expression [25, 20] - [29, 9]
binary_expression [25, 23] - [25, 32]
left: value_identifier [25, 23] - [25, 24]
right: value_identifier [25, 29] - [25, 32]
block [25, 33] - [27, 9]
expression_statement [26, 10] - [26, 49]
variant [26, 10] - [26, 49]
variant_identifier [26, 10] - [26, 17]
arguments [26, 17] - [26, 49]
record [26, 18] - [26, 48]
record_field [26, 19] - [26, 34]
property_identifier [26, 19] - [26, 27]
member_expression [26, 29] - [26, 34]
record: value_identifier [26, 29] - [26, 30]
property: property_identifier [26, 31] - [26, 34]
record_field [26, 36] - [26, 47]
property_identifier [26, 36] - [26, 43]
string [26, 45] - [26, 47]
else_clause [27, 10] - [29, 9]
block [27, 15] - [29, 9]
expression_statement [28, 10] - [28, 49]
variant [28, 10] - [28, 49]
variant_identifier [28, 10] - [28, 18]
arguments [28, 18] - [28, 49]
record [28, 19] - [28, 48]
record_field [28, 20] - [28, 35]
property_identifier [28, 20] - [28, 28]
member_expression [28, 30] - [28, 35]
record: value_identifier [28, 30] - [28, 31]
property: property_identifier [28, 32] - [28, 35]
record_field [28, 37] - [28, 47]
property_identifier [28, 37] - [28, 44]
value_identifier [28, 46] - [28, 47]
expression_statement [30, 8] - [30, 28]
call_expression [30, 8] - [30, 28]
function: value_identifier [30, 8] - [30, 11]
arguments: arguments [30, 11] - [30, 28]
labeled_argument [30, 12] - [30, 16]
label: value_identifier [30, 13] - [30, 16]
labeled_argument [30, 18] - [30, 24]
label: value_identifier [30, 19] - [30, 24]
value_identifier [30, 26] - [30, 27]
switch_match [31, 6] - [60, 9]
variant_pattern [31, 8] - [31, 37]
variant_identifier [31, 8] - [31, 16]
formal_parameters [31, 16] - [31, 37]
record_pattern [31, 17] - [31, 36]
value_identifier [31, 18] - [31, 26]
value_identifier [31, 28] - [31, 35]
let_binding [32, 8] - [32, 23]
value_identifier [32, 12] - [32, 13]
call_expression [32, 16] - [32, 23]
function: value_identifier [32, 16] - [32, 20]
arguments: arguments [32, 20] - [32, 23]
value_identifier [32, 21] - [32, 22]
let_binding [34, 8] - [34, 30]
value_identifier [34, 12] - [34, 18]
binary_expression [34, 21] - [34, 30]
left: member_expression [34, 21] - [34, 26]
record: value_identifier [34, 21] - [34, 22]
property: property_identifier [34, 23] - [34, 26]
right: number [34, 29] - [34, 30]
comment [36, 8] - [37, 8]
expression_statement [37, 8] - [60, 9]
if_expression [37, 8] - [60, 9]
binary_expression [37, 11] - [37, 20]
left: value_identifier [37, 11] - [37, 12]
right: value_identifier [37, 17] - [37, 20]
block [37, 21] - [47, 9]
let_binding [38, 10] - [44, 12]
value_identifier [38, 14] - [38, 19]
variant [38, 22] - [44, 12]
variant_identifier [38, 22] - [38, 26]
arguments [38, 26] - [44, 12]
record [38, 27] - [44, 11]
record_field [39, 12] - [42, 13]
property_identifier [39, 12] - [39, 15]
record [39, 17] - [42, 13]
record_field [40, 14] - [40, 32]
property_identifier [40, 14] - [40, 22]
value_identifier [40, 24] - [40, 32]
record_field [41, 14] - [41, 28]
property_identifier [41, 14] - [41, 20]
value_identifier [41, 22] - [41, 28]
record_field [43, 12] - [43, 28]
property_identifier [43, 12] - [43, 19]
value_identifier [43, 21] - [43, 28]
expression_statement [45, 10] - [45, 44]
pipe_expression [45, 10] - [45, 44]
call_expression [45, 10] - [45, 36]
function: value_identifier_path [45, 10] - [45, 24]
module_identifier [45, 10] - [45, 12]
module_identifier [45, 13] - [45, 19]
value_identifier [45, 20] - [45, 24]
arguments: arguments [45, 24] - [45, 36]
value_identifier [45, 25] - [45, 28]
value_identifier [45, 30] - [45, 35]
value_identifier [45, 38] - [45, 44]
expression_statement [46, 10] - [46, 69]
call_expression [46, 10] - [46, 69]
function: value_identifier [46, 10] - [46, 13]
arguments: arguments [46, 13] - [46, 69]
labeled_argument [46, 14] - [46, 18]
label: value_identifier [46, 15] - [46, 18]
labeled_argument [46, 20] - [46, 65]
label: value_identifier [46, 21] - [46, 26]
value: variant [46, 27] - [46, 65]
variant_identifier [46, 27] - [46, 34]
arguments [46, 34] - [46, 65]
record [46, 35] - [46, 64]
record_field [46, 36] - [46, 51]
property_identifier [46, 36] - [46, 44]
member_expression [46, 46] - [46, 51]
record: value_identifier [46, 46] - [46, 47]
property: property_identifier [46, 48] - [46, 51]
record_field [46, 53] - [46, 63]
property_identifier [46, 53] - [46, 60]
value_identifier [46, 62] - [46, 63]
value_identifier [46, 67] - [46, 68]
else_if_clause [47, 10] - [57, 9]
call_expression [47, 18] - [47, 27]
function: value_identifier [47, 18] - [47, 24]
arguments: arguments [47, 24] - [47, 27]
value_identifier [47, 25] - [47, 26]
block [47, 28] - [57, 9]
let_binding [48, 10] - [54, 12]
value_identifier [48, 14] - [48, 19]
variant [48, 22] - [54, 12]
variant_identifier [48, 22] - [48, 26]
arguments [48, 26] - [54, 12]
record [48, 27] - [54, 11]
record_field [49, 12] - [52, 13]
property_identifier [49, 12] - [49, 15]
record [49, 17] - [52, 13]
record_field [50, 14] - [50, 32]
property_identifier [50, 14] - [50, 22]
value_identifier [50, 24] - [50, 32]
record_field [51, 14] - [51, 28]
property_identifier [51, 14] - [51, 20]
value_identifier [51, 22] - [51, 28]
record_field [53, 12] - [53, 28]
property_identifier [53, 12] - [53, 19]
value_identifier [53, 21] - [53, 28]
expression_statement [55, 10] - [55, 44]
pipe_expression [55, 10] - [55, 44]
call_expression [55, 10] - [55, 36]
function: value_identifier_path [55, 10] - [55, 24]
module_identifier [55, 10] - [55, 12]
module_identifier [55, 13] - [55, 19]
value_identifier [55, 20] - [55, 24]
arguments: arguments [55, 24] - [55, 36]
value_identifier [55, 25] - [55, 28]
value_identifier [55, 30] - [55, 35]
value_identifier [55, 38] - [55, 44]
expression_statement [56, 10] - [56, 13]
value_identifier [56, 10] - [56, 13]
else_clause [57, 10] - [60, 9]
block [57, 15] - [60, 9]
let_binding [58, 10] - [58, 36]
value_identifier [58, 14] - [58, 21]
binary_expression [58, 24] - [58, 36]
left: value_identifier [58, 24] - [58, 31]
right: value_identifier [58, 35] - [58, 36]
expression_statement [59, 10] - [59, 79]
call_expression [59, 10] - [59, 79]
function: value_identifier [59, 10] - [59, 13]
arguments: arguments [59, 13] - [59, 79]
labeled_argument [59, 14] - [59, 18]
label: value_identifier [59, 15] - [59, 18]
labeled_argument [59, 20] - [59, 75]
label: value_identifier [59, 21] - [59, 26]
value: variant [59, 27] - [59, 75]
variant_identifier [59, 27] - [59, 35]
arguments [59, 35] - [59, 75]
record [59, 36] - [59, 74]
record_field [59, 37] - [59, 55]
property_identifier [59, 37] - [59, 45]
value_identifier [59, 47] - [59, 55]
record_field [59, 57] - [59, 73]
property_identifier [59, 57] - [59, 64]
value_identifier [59, 66] - [59, 73]
value_identifier [59, 77] - [59, 78]
switch_match [61, 6] - [123, 0]
variant_pattern [61, 8] - [61, 36]
variant_identifier [61, 8] - [61, 15]
formal_parameters [61, 15] - [61, 36]
record_pattern [61, 16] - [61, 35]
value_identifier [61, 17] - [61, 25]
value_identifier [61, 27] - [61, 34]
let_binding [62, 8] - [62, 23]
value_identifier [62, 12] - [62, 13]
call_expression [62, 16] - [62, 23]
function: value_identifier [62, 16] - [62, 20]
arguments: arguments [62, 20] - [62, 23]
value_identifier [62, 21] - [62, 22]
comment [64, 8] - [65, 8]
expression_statement [65, 8] - [122, 1]
if_expression [65, 8] - [122, 1]
binary_expression [65, 11] - [65, 34]
left: binary_expression [65, 11] - [65, 20]
left: value_identifier [65, 11] - [65, 12]
right: string [65, 17] - [65, 20]
string_fragment [65, 18] - [65, 19]
right: call_expression [65, 24] - [65, 34]
function: value_identifier [65, 24] - [65, 31]
arguments: arguments [65, 31] - [65, 34]
value_identifier [65, 32] - [65, 33]
block [65, 35] - [122, 1]
let_binding [66, 10] - [66, 32]
value_identifier [66, 14] - [66, 17]
binary_expression [66, 20] - [66, 32]
left: value_identifier [66, 20] - [66, 27]
right: value_identifier [66, 31] - [66, 32]
let_binding [68, 10] - [68, 86]
value_identifier [68, 14] - [68, 17]
record [68, 20] - [68, 86]
record_field [68, 21] - [68, 39]
property_identifier [68, 21] - [68, 29]
value_identifier [68, 31] - [68, 39]
record_field [68, 41] - [68, 85]
property_identifier [68, 41] - [68, 47]
binary_expression [68, 49] - [68, 85]
left: binary_expression [68, 49] - [68, 81]
left: value_identifier [68, 49] - [68, 57]
right: call_expression [68, 60] - [68, 81]
function: value_identifier_path [68, 60] - [68, 76]
module_identifier [68, 60] - [68, 62]
module_identifier [68, 63] - [68, 69]
value_identifier [68, 70] - [68, 76]
arguments: arguments [68, 76] - [68, 81]
value_identifier [68, 77] - [68, 80]
right: number [68, 84] - [68, 85]
let_binding [70, 10] - [121, 37]
value_identifier [70, 14] - [70, 19]
call_expression [70, 22] - [121, 37]
function: pipe_expression [70, 22] - [70, 78]
call_expression [70, 22] - [70, 76]
function: value_identifier_path [70, 22] - [70, 33]
module_identifier [70, 22] - [70, 24]
module_identifier [70, 25] - [70, 27]
value_identifier [70, 28] - [70, 33]
arguments: arguments [70, 33] - [70, 76]
extension_expression [70, 34] - [70, 70]
extension_identifier [70, 35] - [70, 37]
expression_statement [70, 38] - [70, 69]
template_string [70, 38] - [70, 69]
escape_sequence [70, 40] - [70, 42]
escape_sequence [70, 54] - [70, 56]
escape_sequence [70, 60] - [70, 62]
value_identifier [70, 72] - [70, 75]
variant_identifier [70, 78] - [70, 78]
arguments: arguments [70, 78] - [121, 37]
call_expression [71, 12] - [74, 51]
function: member_expression [71, 12] - [74, 43]
record: value_identifier [71, 12] - [71, 13]
ERROR [71, 14] - [74, 31]
value_identifier [72, 21] - [72, 22]
variant_pattern [73, 16] - [73, 28]
variant_identifier [73, 16] - [73, 20]
formal_parameters [73, 20] - [73, 28]
value_identifier [73, 21] - [73, 27]
let_binding [74, 16] - [74, 31]
value_identifier [74, 20] - [74, 26]
variant [74, 29] - [74, 31]
variant_identifier [74, 29] - [74, 31]
module: module_identifier [74, 32] - [74, 34]
property: property_identifier [74, 35] - [74, 43]
arguments: arguments [74, 43] - [74, 51]
value_identifier [74, 44] - [74, 50]
ERROR [74, 51] - [121, 37]
ERROR [119, 32] - [119, 37]
mutation_expression [119, 39] - [121, 37]
value_identifier [119, 39] - [119, 43]
ERROR [119, 44] - [119, 72]
ERROR [119, 44] - [119, 57]
ERROR [119, 59] - [119, 68]
comment [120, 2] - [120, 62]
ERROR [121, 2] - [121, 9]
ERROR [121, 6] - [121, 9]
function [121, 12] - [121, 37]
parameters: formal_parameters [121, 12] - [121, 27]
value_identifier [121, 13] - [121, 14]
type_annotation [121, 14] - [121, 26]
type_identifier_path [121, 16] - [121, 26]
module_identifier [121, 16] - [121, 24]
type_identifier [121, 25] - [121, 26]
body: call_expression [121, 31] - [121, 37]
function: value_identifier [121, 31] - [121, 34]
arguments: arguments [121, 34] - [121, 37]
value_identifier [121, 35] - [121, 36]
let a = (. b) => {
()
}
let_binding [0, 0] - [2, 1]
identifier [0, 4] - [0, 8]
ERROR [0, 11] - [0, 21]
member_expression [0, 11] - [0, 17]
record: unit [0, 11] - [0, 12]
property: property_identifier [0, 14] - [0, 17]
block [0, 22] - [2, 1]
expression_statement [1, 2] - [1, 4]
unit [1, 2] - [1, 4]
Thanks!
See Lazy Values
wrapper->{
open DomUtil
setOnMouseOver(evt => {
let target = Event.target(evt)
let id = getId(target)
if isMarkerId(id) {
switch extractRowColFromId(id) {
| Some(rowCol) => Belt.Option.forEach(onMarkerFocus, cb => cb(rowCol))
| None => ()
}
}
})
}
ERROR [0, 0] - [0, 9]
value_identifier [0, 0] - [0, 7]
expression_statement [0, 9] - [13, 3]
block [0, 9] - [13, 3]
open_statement [1, 4] - [1, 16]
module_identifier [1, 9] - [1, 16]
expression_statement [2, 4] - [12, 6]
call_expression [2, 4] - [12, 6]
function: value_identifier [2, 4] - [2, 18]
arguments: arguments [2, 18] - [12, 6]
function [2, 19] - [12, 5]
parameter: value_identifier [2, 19] - [2, 22]
body: block [2, 26] - [12, 5]
let_binding [3, 6] - [3, 36]
value_identifier [3, 10] - [3, 16]
call_expression [3, 19] - [3, 36]
function: value_identifier_path [3, 19] - [3, 31]
module_identifier [3, 19] - [3, 24]
value_identifier [3, 25] - [3, 31]
arguments: arguments [3, 31] - [3, 36]
value_identifier [3, 32] - [3, 35]
let_binding [5, 6] - [5, 28]
value_identifier [5, 10] - [5, 12]
call_expression [5, 15] - [5, 28]
function: value_identifier [5, 15] - [5, 20]
arguments: arguments [5, 20] - [5, 28]
value_identifier [5, 21] - [5, 27]
expression_statement [6, 6] - [11, 7]
if_expression [6, 6] - [11, 7]
call_expression [6, 9] - [6, 23]
function: value_identifier [6, 9] - [6, 19]
arguments: arguments [6, 19] - [6, 23]
value_identifier [6, 20] - [6, 22]
block [6, 24] - [11, 7]
expression_statement [7, 8] - [10, 9]
switch_expression [7, 8] - [10, 9]
call_expression [7, 15] - [7, 38]
function: value_identifier [7, 15] - [7, 34]
arguments: arguments [7, 34] - [7, 38]
value_identifier [7, 35] - [7, 37]
switch_match [8, 8] - [8, 78]
variant_pattern [8, 10] - [8, 22]
variant_identifier [8, 10] - [8, 14]
formal_parameters [8, 14] - [8, 22]
value_identifier [8, 15] - [8, 21]
expression_statement [8, 26] - [8, 78]
call_expression [8, 26] - [8, 78]
function: value_identifier_path [8, 26] - [8, 45]
module_identifier [8, 26] - [8, 30]
module_identifier [8, 31] - [8, 37]
value_identifier [8, 38] - [8, 45]
arguments: arguments [8, 45] - [8, 78]
value_identifier [8, 46] - [8, 59]
function [8, 61] - [8, 77]
parameter: value_identifier [8, 61] - [8, 63]
body: call_expression [8, 67] - [8, 77]
function: value_identifier [8, 67] - [8, 69]
arguments: arguments [8, 69] - [8, 77]
value_identifier [8, 70] - [8, 76]
switch_match [9, 8] - [9, 20]
variant_pattern [9, 10] - [9, 14]
variant_identifier [9, 10] - [9, 14]
expression_statement [9, 18] - [9, 20]
unit [9, 18] - [9, 20]
Hi,
It seems, ()
instead of unit
in type signatures breaks the parser:
type myResult = result<(), string>
This breaks syntax highlighting before and after the line that is the culprit.
Sidenote: In Rust unit
is also called ()
at the type-level, which is how I ended up with the above. Debugging what was going on was pretty difficult.
type empty = {}
) rescript-lang/rescript-compiler#5658<div {...props} />
type sharedProps = {
x: string,
y: string,
}
module A = {
@react.component(:sharedProps)
let make = (~x, ~y) => React.string(x ++ y)
}
module B = {
@react.component(:sharedProps)
let make = (~x, ~y) => React.string(x ++ y)
}
let copyToClipboard: string => bool = %raw(j`
function(str) {
try {
const el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
const selected =
document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
el.select();
document.execCommand('copy');
document.body.removeChild(el);
if (selected) {
document.getSelection().removeAllRanges();
document.getSelection().addRange(selected);
}
return true;
} catch(e) {
return false;
}
}
`)
let_binding [0, 0] - [23, 2]
value_identifier [0, 4] - [0, 19]
type_annotation [0, 19] - [0, 35]
function_type [0, 21] - [0, 35]
function_type_parameters [0, 21] - [0, 27]
type_identifier [0, 21] - [0, 27]
type_identifier [0, 31] - [0, 35]
extension_expression [0, 38] - [23, 2]
extension_identifier [0, 39] - [0, 42]
ERROR [0, 43] - [0, 44]
expression_statement [0, 44] - [23, 1]
template_string [0, 44] - [23, 1]
raw_js [0, 45] - [23, 0]
expression_statement [1, 2] - [22, 3]
function [1, 2] - [22, 3]
parameters: formal_parameters [1, 10] - [1, 15]
identifier [1, 11] - [1, 14]
body: statement_block [1, 16] - [22, 3]
try_statement [2, 4] - [21, 5]
body: statement_block [2, 8] - [19, 5]
lexical_declaration [3, 4] - [3, 50]
variable_declarator [3, 10] - [3, 49]
name: identifier [3, 10] - [3, 12]
value: call_expression [3, 15] - [3, 49]
function: member_expression [3, 15] - [3, 37]
object: identifier [3, 15] - [3, 23]
property: property_identifier [3, 24] - [3, 37]
arguments: arguments [3, 37] - [3, 49]
string [3, 38] - [3, 48]
string_fragment [3, 39] - [3, 47]
expression_statement [4, 4] - [4, 19]
assignment_expression [4, 4] - [4, 18]
left: member_expression [4, 4] - [4, 12]
object: identifier [4, 4] - [4, 6]
property: property_identifier [4, 7] - [4, 12]
right: identifier [4, 15] - [4, 18]
expression_statement [5, 4] - [5, 36]
call_expression [5, 4] - [5, 35]
function: member_expression [5, 4] - [5, 19]
object: identifier [5, 4] - [5, 6]
property: property_identifier [5, 7] - [5, 19]
arguments: arguments [5, 19] - [5, 35]
string [5, 20] - [5, 30]
string_fragment [5, 21] - [5, 29]
string [5, 32] - [5, 34]
expression_statement [6, 4] - [6, 35]
assignment_expression [6, 4] - [6, 34]
left: member_expression [6, 4] - [6, 21]
object: member_expression [6, 4] - [6, 12]
object: identifier [6, 4] - [6, 6]
property: property_identifier [6, 7] - [6, 12]
property: property_identifier [6, 13] - [6, 21]
right: string [6, 24] - [6, 34]
string_fragment [6, 25] - [6, 33]
expression_statement [7, 4] - [7, 30]
assignment_expression [7, 4] - [7, 29]
left: member_expression [7, 4] - [7, 17]
object: member_expression [7, 4] - [7, 12]
object: identifier [7, 4] - [7, 6]
property: property_identifier [7, 7] - [7, 12]
property: property_identifier [7, 13] - [7, 17]
right: string [7, 20] - [7, 29]
string_fragment [7, 21] - [7, 28]
expression_statement [8, 4] - [8, 34]
call_expression [8, 4] - [8, 33]
function: member_expression [8, 4] - [8, 29]
object: member_expression [8, 4] - [8, 17]
object: identifier [8, 4] - [8, 12]
property: property_identifier [8, 13] - [8, 17]
property: property_identifier [8, 18] - [8, 29]
arguments: arguments [8, 29] - [8, 33]
identifier [8, 30] - [8, 32]
lexical_declaration [9, 4] - [10, 93]
variable_declarator [9, 10] - [10, 92]
name: identifier [9, 10] - [9, 18]
value: ternary_expression [10, 6] - [10, 92]
condition: binary_expression [10, 6] - [10, 44]
left: member_expression [10, 6] - [10, 40]
object: call_expression [10, 6] - [10, 29]
function: member_expression [10, 6] - [10, 27]
object: identifier [10, 6] - [10, 14]
property: property_identifier [10, 15] - [10, 27]
arguments: arguments [10, 27] - [10, 29]
property: property_identifier [10, 30] - [10, 40]
right: number [10, 43] - [10, 44]
consequence: call_expression [10, 47] - [10, 84]
function: member_expression [10, 47] - [10, 81]
object: call_expression [10, 47] - [10, 70]
function: member_expression [10, 47] - [10, 68]
object: identifier [10, 47] - [10, 55]
property: property_identifier [10, 56] - [10, 68]
arguments: arguments [10, 68] - [10, 70]
property: property_identifier [10, 71] - [10, 81]
arguments: arguments [10, 81] - [10, 84]
number [10, 82] - [10, 83]
alternative: false [10, 87] - [10, 92]
expression_statement [11, 4] - [11, 16]
call_expression [11, 4] - [11, 15]
function: member_expression [11, 4] - [11, 13]
object: identifier [11, 4] - [11, 6]
property: property_identifier [11, 7] - [11, 13]
arguments: arguments [11, 13] - [11, 15]
expression_statement [12, 4] - [12, 33]
call_expression [12, 4] - [12, 32]
function: member_expression [12, 4] - [12, 24]
object: identifier [12, 4] - [12, 12]
property: property_identifier [12, 13] - [12, 24]
arguments: arguments [12, 24] - [12, 32]
string [12, 25] - [12, 31]
string_fragment [12, 26] - [12, 30]
expression_statement [13, 4] - [13, 34]
call_expression [13, 4] - [13, 33]
function: member_expression [13, 4] - [13, 29]
object: member_expression [13, 4] - [13, 17]
object: identifier [13, 4] - [13, 12]
property: property_identifier [13, 13] - [13, 17]
property: property_identifier [13, 18] - [13, 29]
arguments: arguments [13, 29] - [13, 33]
identifier [13, 30] - [13, 32]
if_statement [14, 4] - [17, 5]
condition: parenthesized_expression [14, 7] - [14, 17]
identifier [14, 8] - [14, 16]
consequence: statement_block [14, 18] - [17, 5]
expression_statement [15, 6] - [15, 48]
call_expression [15, 6] - [15, 47]
function: member_expression [15, 6] - [15, 45]
object: call_expression [15, 6] - [15, 29]
function: member_expression [15, 6] - [15, 27]
object: identifier [15, 6] - [15, 14]
property: property_identifier [15, 15] - [15, 27]
arguments: arguments [15, 27] - [15, 29]
property: property_identifier [15, 30] - [15, 45]
arguments: arguments [15, 45] - [15, 47]
expression_statement [16, 6] - [16, 49]
call_expression [16, 6] - [16, 48]
function: member_expression [16, 6] - [16, 38]
object: call_expression [16, 6] - [16, 29]
function: member_expression [16, 6] - [16, 27]
object: identifier [16, 6] - [16, 14]
property: property_identifier [16, 15] - [16, 27]
arguments: arguments [16, 27] - [16, 29]
property: property_identifier [16, 30] - [16, 38]
arguments: arguments [16, 38] - [16, 48]
identifier [16, 39] - [16, 47]
return_statement [18, 4] - [18, 16]
true [18, 11] - [18, 15]
handler: catch_clause [19, 6] - [21, 5]
parameter: identifier [19, 12] - [19, 13]
body: statement_block [19, 15] - [21, 5]
return_statement [20, 6] - [20, 19]
false [20, 13] - [20, 18]
let a = '\o021'
let b = '\179'
(source_file [0, 0] - [2, 0]
(let_binding [0, 0] - [1, 14]
(value_identifier [0, 4] - [0, 5])
(character [0, 8] - [1, 14]
(escape_sequence [0, 9] - [0, 11])
(ERROR [0, 11] - [1, 13]
(number [1, 10] - [1, 13])))))
let f = (raise) => raise + 1;
let_binding [0, 0] - [0, 28]
value_identifier [0, 4] - [0, 5]
function [0, 8] - [0, 28]
parameters: formal_parameters [0, 8] - [0, 15]
ERROR [0, 9] - [0, 14]
ERROR [0, 19] - [0, 24]
body: unary_expression [0, 25] - [0, 28]
argument: number [0, 27] - [0, 28]
https://rescript-lang.org/try?code=DYUwLgBAZhC8EAoBOBDAlgZxASjgPglUxAgGoIBGAbiA
raise
can be a variable. Remove the rule raise_expression
, since call_expression
can parse raise()
let f = c => switch c {
| 'a' => 0
| 'b' .. 'z' => 100
}
let_binding [0, 0] - [3, 1]
value_identifier [0, 4] - [0, 5]
function [0, 8] - [3, 1]
parameter: value_identifier [0, 8] - [0, 9]
body: switch_expression [0, 13] - [3, 1]
value_identifier [0, 20] - [0, 21]
switch_match [1, 0] - [1, 10]
character [1, 2] - [1, 5]
expression_statement [1, 9] - [1, 10]
number [1, 9] - [1, 10]
switch_match [2, 0] - [2, 19]
ERROR [2, 2] - [2, 8]
character [2, 2] - [2, 5]
character [2, 9] - [2, 12]
expression_statement [2, 16] - [2, 19]
number [2, 16] - [2, 19]
// comment 1
// comment 2
// comment 3
// comment 4
(source_file [0, 0] - [7, 0]
(comment [0, 0] - [0, 12])
(comment [2, 0] - [7, 0]))
Expected to find four comment
node.
I'm editing Playground.res and the parser is generating an error.
When I comment out the Pane
module then the error disappears.
the pipe first operator (->
) is well parse but not the pipe last (|>
)
snippet
foo |> baz
Ouput
(source_file [0, 0] - [2, 0]
(ERROR [0, 0] - [0, 11]
(expression_statement [0, 0] - [0, 5]
(identifier [0, 0] - [0, 5]))
(ERROR [0, 9] - [0, 11])))
let tuple = (1, 2, ())
let (a, b, ()) = tuple
let_binding [0, 0] - [0, 22]
value_identifier [0, 4] - [0, 9]
tuple [0, 12] - [0, 22]
number [0, 13] - [0, 14]
number [0, 16] - [0, 17]
unit [0, 19] - [0, 21]
let_binding [1, 0] - [1, 22]
tuple_pattern [1, 4] - [1, 14]
tuple_item_pattern [1, 5] - [1, 6]
value_identifier [1, 5] - [1, 6]
tuple_item_pattern [1, 8] - [1, 9]
value_identifier [1, 8] - [1, 9]
ERROR [1, 11] - [1, 13]
value_identifier [1, 17] - [1, 22]
https://rescript-lang.org/try?code=DYUwLgBGCuAOoQLwQBQEYA0EBMWUEp8AoUSFAQywCM9Cko5Qg
mutually recursive types
Currently broken:
module rec A: X = {
let x = () => 1
let y = () => B.y() + 1
}
and B: X = {
let x = () => A.x() + 2
let y = () => 2
}
(source_file [0, 0] - [8, 0]
(ERROR [0, 0] - [4, 10]
(module_declaration [0, 0] - [3, 1]
name: (module_identifier [0, 11] - [0, 12])
signature: (module_identifier [0, 14] - [0, 15])
definition: (block [0, 18] - [3, 1]
(let_binding [1, 2] - [1, 17]
(value_identifier [1, 6] - [1, 7])
(function [1, 10] - [1, 17]
parameters: (formal_parameters [1, 10] - [1, 12])
body: (number [1, 16] - [1, 17])))
(let_binding [2, 2] - [2, 25]
(value_identifier [2, 6] - [2, 7])
(function [2, 10] - [2, 25]
parameters: (formal_parameters [2, 10] - [2, 12])
body: (binary_expression [2, 16] - [2, 25]
left: (call_expression [2, 16] - [2, 21]
function: (value_identifier_path [2, 16] - [2, 19]
(module_identifier [2, 16] - [2, 17])
(value_identifier [2, 18] - [2, 19]))
arguments: (arguments [2, 19] - [2, 21]))
right: (number [2, 24] - [2, 25])))))))
(expression_statement [4, 11] - [7, 1]
(block [4, 11] - [7, 1]
(let_binding [5, 2] - [5, 25]
(value_identifier [5, 6] - [5, 7])
(function [5, 10] - [5, 25]
parameters: (formal_parameters [5, 10] - [5, 12])
body: (binary_expression [5, 16] - [5, 25]
left: (call_expression [5, 16] - [5, 21]
function: (value_identifier_path [5, 16] - [5, 19]
(module_identifier [5, 16] - [5, 17])
(value_identifier [5, 18] - [5, 19]))
arguments: (arguments [5, 19] - [5, 21]))
right: (number [5, 24] - [5, 25]))))
(let_binding [6, 2] - [6, 17]
(value_identifier [6, 6] - [6, 7])
(function [6, 10] - [6, 17]
parameters: (formal_parameters [6, 10] - [6, 12])
body: (number [6, 16] - [6, 17]))))))
Minimal example:
@react.component
let hello = () =>
<div>
{
let href = "https://github.com"
<a href> {React.string("Hello")} </a>
}
</div>
let a = `foo`
Tree-sitter output:
(source_file [0, 0] - [10, 0]
(ERROR [0, 0] - [9, 13]
(decorator [0, 0] - [0, 16]
(decorator_identifier [0, 1] - [0, 16]))
(value_identifier [1, 4] - [1, 9])
parameters: (formal_parameters [1, 12] - [1, 14])
(jsx_opening_element [2, 2] - [2, 7]
name: (jsx_identifier [2, 3] - [2, 6]))
(value_identifier [4, 6] - [4, 9])))
/tmp/test.res 0 ms (ERROR [0, 0] - [9, 13])
The real-world source file I was seeing the issue with: https://github.com/ocaml/v3.ocaml.org/tree/master/src/Footer.res
@@warning("-27")
ERROR [0, 0] - [0, 15]
decorator [0, 1] - [0, 15]
decorator_identifier [0, 2] - [0, 9]
decorator_arguments [0, 9] - [0, 15]
string [0, 10] - [0, 14]
string_fragment [0, 11] - [0, 13]
Thanks!
while true {
Js.log("Still running")
}
ERROR [0, 0] - [0, 10]
value_identifier [0, 0] - [0, 5]
true [0, 6] - [0, 10]
expression_statement [0, 11] - [2, 1]
block [0, 11] - [2, 1]
expression_statement [1, 2] - [1, 25]
call_expression [1, 2] - [1, 25]
function: value_identifier_path [1, 2] - [1, 8]
module_identifier [1, 2] - [1, 4]
value_identifier [1, 5] - [1, 8]
arguments: arguments [1, 8] - [1, 25]
string [1, 9] - [1, 24]
string_fragment [1, 10] - [1, 23]
As noted in #143 (comment)
Another simplification that can be made:
There are two rules for extension,
$._raw_js_extension
and$._raw_ggl_extension
. They are used to apply injections highlights but we can do without them.
Example for
%re()
:
(extension_expression
(extension_identifier) @_name
(#eq? @_name "re")
(expression_statement (string ((string_fragment) @regex))))
let classify = (v: t): case =>
if %raw(`function (a) { return a instanceof Array}`)(v) {
Array((Obj.magic(v): array<mdxComponent>))
} else if Js.typeof(v) == "string" {
String((Obj.magic(v): string))
} else if Js.typeof(v) == "object" {
Element((Obj.magic(v): mdxComponent))
} else {
Unknown((Obj.magic(v): unknown))
}
let_binding [0, 0] - [9, 3]
value_identifier [0, 4] - [0, 12]
function [0, 15] - [9, 3]
parameters: formal_parameters [0, 15] - [0, 21]
value_identifier [0, 16] - [0, 17]
type_annotation [0, 17] - [0, 20]
type_identifier [0, 19] - [0, 20]
return_type: type_annotation [0, 21] - [0, 27]
type_identifier [0, 23] - [0, 27]
body: if_expression [1, 2] - [9, 3]
call_expression [1, 5] - [1, 58]
function: extension_expression [1, 5] - [1, 55]
extension_identifier [1, 6] - [1, 9]
expression_statement [1, 10] - [1, 54]
template_string [1, 10] - [1, 54]
raw_js [1, 11] - [1, 53]
arguments: arguments [1, 55] - [1, 58]
value_identifier [1, 56] - [1, 57]
block [1, 59] - [3, 3]
expression_statement [2, 4] - [2, 46]
variant [2, 4] - [2, 46]
variant_identifier [2, 4] - [2, 9]
arguments [2, 9] - [2, 46]
parenthesized_expression [2, 10] - [2, 45]
binary_expression [2, 11] - [2, 44]
left: binary_expression [2, 11] - [2, 43]
left: call_expression [2, 11] - [2, 23]
function: value_identifier_path [2, 11] - [2, 20]
module_identifier [2, 11] - [2, 14]
value_identifier [2, 15] - [2, 20]
arguments: arguments [2, 20] - [2, 23]
value_identifier [2, 21] - [2, 22]
ERROR [2, 23] - [2, 30]
ERROR [2, 25] - [2, 30]
right: value_identifier [2, 31] - [2, 43]
right: variant [2, 44] - [2, 44]
variant_identifier [2, 44] - [2, 44]
else_if_clause [3, 4] - [5, 3]
binary_expression [3, 12] - [3, 36]
left: call_expression [3, 12] - [3, 24]
function: value_identifier_path [3, 12] - [3, 21]
module_identifier [3, 12] - [3, 14]
value_identifier [3, 15] - [3, 21]
arguments: arguments [3, 21] - [3, 24]
value_identifier [3, 22] - [3, 23]
right: string [3, 28] - [3, 36]
string_fragment [3, 29] - [3, 35]
block [3, 37] - [5, 3]
expression_statement [4, 4] - [4, 34]
variant [4, 4] - [4, 34]
variant_identifier [4, 4] - [4, 10]
arguments [4, 10] - [4, 34]
parenthesized_expression [4, 11] - [4, 33]
call_expression [4, 12] - [4, 24]
function: value_identifier_path [4, 12] - [4, 21]
module_identifier [4, 12] - [4, 15]
value_identifier [4, 16] - [4, 21]
arguments: arguments [4, 21] - [4, 24]
value_identifier [4, 22] - [4, 23]
ERROR [4, 24] - [4, 32]
ERROR [4, 26] - [4, 29]
ERROR [4, 31] - [4, 32]
else_if_clause [5, 4] - [7, 3]
binary_expression [5, 12] - [5, 36]
left: call_expression [5, 12] - [5, 24]
function: value_identifier_path [5, 12] - [5, 21]
module_identifier [5, 12] - [5, 14]
value_identifier [5, 15] - [5, 21]
arguments: arguments [5, 21] - [5, 24]
value_identifier [5, 22] - [5, 23]
right: string [5, 28] - [5, 36]
string_fragment [5, 29] - [5, 35]
block [5, 37] - [7, 3]
expression_statement [6, 4] - [6, 41]
variant [6, 4] - [6, 41]
variant_identifier [6, 4] - [6, 11]
arguments [6, 11] - [6, 41]
parenthesized_expression [6, 12] - [6, 40]
call_expression [6, 13] - [6, 25]
function: value_identifier_path [6, 13] - [6, 22]
module_identifier [6, 13] - [6, 16]
value_identifier [6, 17] - [6, 22]
arguments: arguments [6, 22] - [6, 25]
value_identifier [6, 23] - [6, 24]
ERROR [6, 25] - [6, 39]
ERROR [6, 27] - [6, 30]
else_clause [7, 4] - [9, 3]
block [7, 9] - [9, 3]
expression_statement [8, 4] - [8, 36]
variant [8, 4] - [8, 36]
variant_identifier [8, 4] - [8, 11]
arguments [8, 11] - [8, 36]
parenthesized_expression [8, 12] - [8, 35]
call_expression [8, 13] - [8, 25]
function: value_identifier_path [8, 13] - [8, 22]
module_identifier [8, 13] - [8, 16]
value_identifier [8, 17] - [8, 22]
arguments: arguments [8, 22] - [8, 25]
value_identifier [8, 23] - [8, 24]
ERROR [8, 25] - [8, 34]
ERROR [8, 27] - [8, 34]
type userT = User.t = {name: string, age: int}
(source_file [0, 0] - [1, 0]
(type_declaration [0, 0] - [0, 46]
(type_identifier [0, 5] - [0, 10])
(ERROR [0, 13] - [0, 21]
(type_identifier_path [0, 13] - [0, 19]
(module_identifier [0, 13] - [0, 17])
(type_identifier [0, 18] - [0, 19])))
(record_type [0, 22] - [0, 46]
(record_type_field [0, 23] - [0, 35]
(property_identifier [0, 23] - [0, 27])
(type_annotation [0, 27] - [0, 35]
(type_identifier [0, 29] - [0, 35])))
(record_type_field [0, 37] - [0, 45]
(property_identifier [0, 37] - [0, 40])
(type_annotation [0, 40] - [0, 45]
(type_identifier [0, 42] - [0, 45]))))))
let {Next.Router.events: events} = router
ERROR [0, 0] - [0, 41]
let_binding [0, 0] - [0, 31]
ERROR [0, 4] - [0, 17]
module_identifier [0, 5] - [0, 9]
module_identifier [0, 10] - [0, 16]
value_identifier [0, 17] - [0, 23]
type_annotation [0, 23] - [0, 31]
type_identifier [0, 25] - [0, 31]
ERROR [0, 35] - [0, 41
#80 take 2
let {Api.Config.warn_flags: warn_flags} = config
ERROR [0, 0] - [0, 48]
let_binding [0, 0] - [0, 38]
ERROR [0, 4] - [0, 16]
module_identifier [0, 5] - [0, 8]
module_identifier [0, 9] - [0, 15]
value_identifier [0, 16] - [0, 26]
type_annotation [0, 26] - [0, 38]
type_identifier [0, 28] - [0, 38]
ERROR [0, 42] - [0, 48]
More examples:
let {Api.LocMsg.row: row, column, endColumn, endRow, shortMsg} = locMsg
ERROR [0, 0] - [0, 68]
let_binding [0, 0] - [0, 24]
ERROR [0, 4] - [0, 16]
module_identifier [0, 5] - [0, 8]
module_identifier [0, 9] - [0, 15]
value_identifier [0, 16] - [0, 19]
type_annotation [0, 19] - [0, 24]
type_identifier [0, 21] - [0, 24]
ERROR [0, 24] - [0, 61]
ERROR [0, 26] - [0, 32]
ERROR [0, 34] - [0, 37]
ERROR [0, 45] - [0, 48]
ERROR [0, 53] - [0, 58]
ERROR [0, 65] - [0, 68]
expression_statement [0, 68] - [0, 71]
variant [0, 68] - [0, 71]
variant_identifier [0, 68] - [0, 71]
let f = n => switch n {
| 0 => 0
| (1 | 2) => 1
| n => n
}
ERROR [0, 0] - [4, 1]
value_identifier [0, 4] - [0, 5]
value_identifier [0, 8] - [0, 9]
value_identifier [0, 20] - [0, 21]
switch_match [1, 0] - [1, 8]
number [1, 2] - [1, 3]
expression_statement [1, 7] - [1, 8]
number [1, 7] - [1, 8]
ERROR [2, 3] - [2, 12]
number [2, 3] - [2, 4]
number [2, 7] - [2, 8]
number [2, 13] - [2, 14]
value_identifier [3, 2] - [3, 3]
ERROR [3, 7] - [3, 8]
module Belt = {
include (Belt: module type of Belt with module Map := Belt.Map and module Result := Belt.Result)
}
module_declaration [0, 0] - [2, 1]
name: module_identifier [0, 7] - [0, 11]
definition: block [0, 14] - [2, 1]
ERROR [1, 2] - [1, 68]
variant_pattern [1, 11] - [1, 15]
variant_identifier [1, 11] - [1, 15]
type_annotation [1, 15] - [1, 23]
type_identifier [1, 17] - [1, 23]
ERROR [1, 37] - [1, 41]
module_declaration [1, 42] - [1, 52]
name: module_identifier [1, 49] - [1, 52]
module_declaration [1, 69] - [1, 82]
name: module_identifier [1, 76] - [1, 82]
ERROR [1, 83] - [1, 98]
type red = [ | #red | #violet ]
type blue = [ | #blue | #violet ]
type color = [
| red
| blue
]
returns
type_declaration [0, 0] - [0, 31]
type_identifier [0, 5] - [0, 8]
polyvar_type [0, 11] - [0, 31]
polyvar_declaration [0, 15] - [0, 19]
polyvar_identifier [0, 15] - [0, 19]
polyvar_declaration [0, 22] - [0, 29]
polyvar_identifier [0, 22] - [0, 29]
type_declaration [1, 0] - [1, 33]
type_identifier [1, 5] - [1, 9]
polyvar_type [1, 12] - [1, 33]
polyvar_declaration [1, 16] - [1, 21]
polyvar_identifier [1, 16] - [1, 21]
polyvar_declaration [1, 24] - [1, 31]
polyvar_identifier [1, 24] - [1, 31]
type_declaration [3, 0] - [10, 1]
ERROR [3, 7] - [6, 1]
type_identifier [3, 12] - [3, 17]
ERROR [4, 2] - [4, 7]
ERROR [4, 4] - [4, 7]
ERROR [5, 4] - [5, 8]
I unsusccessfully tried to fix it, and I don't have time for now to investigate
more :S
@deriving
type foo = {
bar: string
}
@deriving
and t = {bar: int}
What I tried but without success:
Add repeat($.decorator)
in _type_declaration
_type_declaration: $ => seq(
$.type_identifier,
optional($.type_parameters),
optional(seq(
choice('=', '+='),
optional('private'),
$._type,
optional(seq(
+ repeat($.decorator),
'and',
$._type_declaration
)),
)),
),
yarn tree-sitter generate
yarn tree-sitter parse ../test/file.res
decorated [0, 0] - [3, 1]
decorator [0, 0] - [0, 9]
decorator_identifier [0, 1] - [0, 9]
type_declaration [1, 0] - [3, 1]
type_identifier [1, 5] - [1, 8]
record_type [1, 11] - [3, 1]
record_type_field [2, 2] - [2, 13]
property_identifier [2, 2] - [2, 5]
type_annotation [2, 5] - [2, 13]
type_identifier [2, 7] - [2, 13]
ERROR [4, 0] - [5, 7]
decorator [4, 0] - [4, 9]
decorator_identifier [4, 1] - [4, 9]
ERROR [5, 4] - [5, 5]
expression_statement [5, 8] - [5, 18]
record [5, 8] - [5, 18]
record_field [5, 9] - [5, 17]
property_identifier [5, 9] - [5, 12]
value_identifier [5, 14] - [5, 17]
This works.
@deriving
type foo = {
bar: string
} @deriving
and t = {bar: int}
And that works too:
Note Add a space after }
@deriving
type foo = {
bar: string
+}
@deriving
and t = {bar: int}
Maybe related this?
switch None {
| Some(_: int) => ()
| None => ()
}
expression_statement [0, 0] - [3, 1]
switch_expression [0, 0] - [3, 1]
variant [0, 7] - [0, 11]
variant_identifier [0, 7] - [0, 11]
switch_match [1, 4] - [2, 0]
variant_pattern [1, 6] - [1, 18]
variant_identifier [1, 6] - [1, 10]
formal_parameters [1, 10] - [1, 18]
identifier [1, 11] - [1, 12]
ERROR [1, 12] - [1, 17]
ERROR [1, 14] - [1, 17]
expression_statement [1, 22] - [1, 24]
unit [1, 22] - [1, 24]
switch_match [2, 4] - [3, 0]
variant_pattern [2, 6] - [2, 10]
variant_identifier [2, 6] - [2, 10]
expression_statement [2, 14] - [2, 16]
unit [2, 14] - [2, 16]
Thanks!
Hey there,
I'm trying to use this repo with the Helix editor. The setup is straightforward, but when it attempts to compile the tree-sitter, I get the error:
clang-7: error: no such file or directory: 'src/parser.c'
I don't know much about tree-sitters in general, but after poking around most other tree sitter repos do indeed have a src/parser.c
file. Is this something you could add so this repo could be used with other tools outside nvim
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.