-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathgrammar.js
101 lines (92 loc) · 2.55 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const
class_ = require('./grammar/class.js'),
conflicts = require('./grammar/conflicts.js'),
context = require('./grammar/context.js'),
data = require('./grammar/data.js'),
decl = require('./grammar/decl.js'),
exp = require('./grammar/exp.js'),
externals = require('./grammar/externals.js'),
general = require('./grammar/general.js'),
id = require('./grammar/id.js'),
inline = require('./grammar/inline.js'),
lexeme = require('./grammar/lexeme.js'),
literal = require('./grammar/literal.js'),
module_ = require('./grammar/module.js'),
operator = require('./grammar/operator.js'),
pat = require('./grammar/pat.js'),
patsyn = require('./grammar/patsyn.js'),
precedences = require('./grammar/precedences.js'),
th = require('./grammar/th.js'),
type = require('./grammar/type.js')
module.exports = grammar({
name: 'haskell',
rules: {
haskell: $ => seq(
optional($.header),
optional($._body),
),
...general,
...type,
...context,
...exp,
...pat,
...module_,
...data,
...class_,
...decl,
...patsyn,
...th,
...literal,
...id,
...operator,
...lexeme,
},
...externals,
...precedences,
...inline,
...conflicts,
/**
* These rules may occur anywhere in the grammar and don't have to be specified in productions.
*/
extras: $ => [
/\p{Zs}/,
/\n/,
/\r/,
$.cpp,
$.comment,
$.haddock,
$.pragma,
],
/**
* Rules with leading underscore are generally omitted from the AST, and can therefore not be used in queries.
* The rules listed in this attribute are omitted from the AST, but their names can be used in queries in place of
* their children; as well as in combination with them, using the syntax `expression/variable`.
* This is most useful for choice rules that represent syntactic categories, like expressions, patterns, and types in
* Haskell.
*
* See the readme for a detailed explanation.
*/
supertypes: $ => [
$.expression,
$.pattern,
$.type,
$.quantified_type,
$.constraint,
$.constraints,
$.type_param,
$.declaration,
$.decl,
$.class_decl,
$.instance_decl,
$.statement,
$.qualifier,
$.guard,
],
/**
* This rule is used to detect that a reserved keyword is a prefix of an identifier.
*
* For example, if the identifier `ifM` occurs in a position where the keyword `if` is valid (so most expressions),
* the fact that `ifM` matches `variable` prevents tree-sitter from lexing `if` followed by `M` as a `name`.
*/
word: $ => $.variable,
})