-
Notifications
You must be signed in to change notification settings - Fork 20
/
grammar.js
76 lines (65 loc) · 1.74 KB
/
grammar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/**
* @file FSharp signature grammar for tree-sitter
* @author Nikolaj Sidorenco
* @license MIT
* @see {@link https://fsharp.org/specs/language-spec/4.1/FSharpSpec-4.1-latest.pdf f# grammar}
*/
/* eslint-disable arrow-parens */
/* eslint-disable camelcase */
/* eslint-disable-next-line spaced-comment */
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar(require("../fsharp/grammar"), {
name: "fsharp_signature",
conflicts: ($) => [
[$.long_identifier, $._identifier_or_op],
[$.type_argument, $.simple_type],
[$.rules],
],
supertypes: ($) => [$._module_signature_elements],
rules: {
file: ($, _original) =>
choice($.namespace, $.module, repeat($._module_signature_elements)),
namespace: ($, _original) =>
seq("namespace", $.long_identifier, repeat($._module_signature_elements)),
module: ($, _original) =>
seq(
"module",
$.long_identifier,
"=",
scoped(repeat($._module_signature_elements), $._indent, $._dedent),
),
_module_signature_elements: ($, _original) =>
choice(
// $.value_signature,
$.value_definition,
),
// value_signature: ($, _original) =>
// seq("val", optional("mutable"), $.curried_spec),
value_definition: ($, _original) =>
prec.left(
4,
seq(
optional($.attributes),
"val",
$.value_declaration_left,
":",
$._type,
optional(seq("=", field("body", $._expression_block))),
),
),
},
});
/**
*
* @param {Rule} rule
*
* @param {Rule} indent
*
* @param {Rule} dedent
*
* @return {Rule}
*/
function scoped(rule, indent, dedent) {
return field("block", seq(indent, rule, dedent));
}