case/let and some cleanup of the cst

This commit is contained in:
2026-03-08 10:06:53 -07:00
parent eaf020bb91
commit 1a9e76b3e9
9 changed files with 31995 additions and 22415 deletions

View File

@@ -2,6 +2,8 @@ root = true
[*] [*]
charset = utf-8 charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{json,toml,yml,gyp}] [*.{json,toml,yml,gyp}]
indent_style = space indent_style = space

View File

@@ -41,40 +41,57 @@ module.exports = grammar({
seq("/-", /([^-]|-+[^/])-/, "/"), seq("/-", /([^-]|-+[^/])-/, "/"),
), ),
), ),
_arr: ($) => choice("->", "→"), _arr: _ => choice("->", "→"),
number: $ => /\d+/, number: $ => /\d+/,
lamExpr: $ => seq( lamExpr: $ => seq(
choice("\\", "λ"), choice("\\", "λ"),
repeat1($.identifier), repeat1($.identifier),
"=>", "=>",
$.typeExpr $._typeExpr
), ),
// hole, parenTypeExpression, record update // hole, parenTypeExpression, record update
_atom: $ => choice($.identifier, $.string, $.character, $.number, $.recUpdate, seq("(", $.typeExpr, ")")), _atom: $ => choice($.identifier, $.string, $.character, $.number, $.recUpdate, seq("(", $._typeExpr, ")")),
_parg: $ => choice(seq("{{", $.typeExpr, "}}"), seq("{", $.typeExpr, "}"), $._atom), _parg: $ => choice(seq("{{", $._typeExpr, "}}"), seq("{", $._typeExpr, "}"), $._atom),
recUpdate: $ => seq("[", sep(";", seq($.identifier, choice(":=", "$="), $.term)), "]"), recUpdate: $ => seq("[", sep(";", seq($.identifier, choice(":=", "$="), $.term)), "]"),
_appExpr: $ => (seq($._atom, repeat($._parg))), _appExpr: $ => (seq($._atom, repeat($._parg))),
qname: ($) => sep1(".", $.identifier), qname: ($) => sep1(".", $.identifier),
string: $ => /"[^"]*"/, string: _ => /"[^"]*"/,
character: $ => /'(\\)?.'/, character: _ => /'(\\)?.'/,
doCaseLet: $ => seq("let", "(", $.term, ")", "=", $.typeExpr, repeat($.orAlt)), doLet: $ => seq("let", $.identifier, "=", $._typeExpr),
doCaseLet: $ => seq("let", "(", $.term, ")", "=", $._typeExpr, repeat($.orAlt)),
caseAlt: $ => seq($.term, "=>", $.term), caseAlt: $ => seq($.term, "=>", $.term),
orAlt: $ => seq("|", $.caseAlt), orAlt: $ => seq("|", $.caseAlt),
// layout was causing trouble here. I kinda wanted to ditch it, but there // layout was causing trouble here. I kinda wanted to ditch it, but there
// could be a shift/reduce thing in the real parser // could be a shift/reduce thing in the real parser
_doArrow: $ => seq("<-", $.typeExpr, repeat($.orAlt)), _doArrow: $ => seq("<-", $._typeExpr, repeat($.orAlt)),
doArrow: $ => seq($.term, optional($._doArrow)), doArrow: $ => seq($.term, optional($._doArrow)),
doLet: $ => seq("let", $.identifier, "=", $.term),
_doExpr: $ => choice( _doExpr: $ => choice(
$.doCaseLet, $.doCaseLet,
$.doLet, $.doLet,
$.doArrow), $.doArrow),
doBlock: $ => seq("do", layout($, $._doExpr)), doBlock: $ => seq("do", layout($, $._doExpr)),
ifThen: ($) => seq("if", $.term, "then", $.term, "else", $.term), ifThen: ($) => seq("if", $.term, "then", $.term, "else", $.term),
caseExpr: $ => seq(
"case",
$._typeExpr,
"of",
layout($,$.caseAlt)
),
caseLet: $ => seq(
// what do we do with "in" - it makes an end without a start...
"let", "(", $._typeExpr,")","=",repeat($.orAlt),"in"
),
letAssign: $ => seq($.identifier, "=", $._typeExpr),
letStmt: $ => seq(
"let",
layout($,$.letAssign),
"in",
$._typeExpr),
_term2: ($) => _term2: ($) =>
choice( choice(
// caseExpr $.caseExpr,
// caseLet $.caseLet,
$.letStmt,
// caseLamExpr // caseLamExpr
$.lamExpr, $.lamExpr,
$.doBlock, $.doBlock,
@@ -91,14 +108,14 @@ module.exports = grammar({
binder: ($) => binder: ($) =>
choice( choice(
// repeat($.identifier) has a conflict // repeat($.identifier) has a conflict
seq("(", alias(optional("0"), "quantity"), $.identifier, ":", $.typeExpr, ")"), seq("(", alias(optional("0"), "quantity"), $.identifier, ":", $._typeExpr, ")"),
seq("{{", $.typeExpr, "}}"), seq("{{", $._typeExpr, "}}"),
seq("{", alias(optional("0"), "quantity"), repeat1($.identifier), ":", $.typeExpr, "}"), seq("{", alias(optional("0"), "quantity"), repeat1($.identifier), ":", $._typeExpr, "}"),
), ),
forall: ($) => seq("", repeat1($.identifier), ".", $.typeExpr), forall: ($) => seq(choice("", "forall"), repeat1($.identifier), ".", $._typeExpr),
binders: ($) => seq(choice(repeat1($.binder)), $._arr, $.typeExpr), binders: ($) => seq(choice(repeat1($.binder)), $._arr, $._typeExpr),
typeExpr: ($) => prec.right(choice($.forall, $.binders, seq($.term, optional(seq($._arr, $.typeExpr))))), _typeExpr: ($) => prec.right(choice($.forall, $.binders, seq($.term, optional(seq($._arr, $._typeExpr))))),
// pitype: ($) => // pitype: ($) =>
// seq( // seq(
@@ -106,9 +123,9 @@ module.exports = grammar({
// repeat(seq(repeat1(choice($.identifier, $.binder)), $._arr)), // repeat(seq(repeat1(choice($.identifier, $.binder)), $._arr)),
// $.identifier, // $.identifier,
// ), // ),
sigDecl: ($) => seq($.identifier, ":", $.typeExpr), sigDecl: ($) => seq($.identifier, ":", $._typeExpr),
whereClause: $ => seq("where", layout($, choice($.sigDecl, $.defDecl))), whereClause: $ => seq("where", layout($, choice($.sigDecl, $.defDecl))),
defDecl: ($) => seq(alias($._appExpr, $.lhs), "=", $.typeExpr, optional($.whereClause)), defDecl: ($) => seq(alias($._appExpr, $.lhs), "=", $._typeExpr, optional($.whereClause)),
shortDataDecl: $ => seq( shortDataDecl: $ => seq(
"data", "data",
alias($.identifier, "typeName"), alias($.identifier, "typeName"),
@@ -121,7 +138,7 @@ module.exports = grammar({
"data", "data",
alias($.identifier, "typeName"), alias($.identifier, "typeName"),
":", ":",
$.typeExpr, $._typeExpr,
// the layout here can be empty (so no start tag) // the layout here can be empty (so no start tag)
// optional doesn't seem to help, so we have an error at void // optional doesn't seem to help, so we have an error at void
optional(seq("where", optional(layout($, $.sigDecl)))), optional(seq("where", optional(layout($, $.sigDecl)))),
@@ -133,14 +150,14 @@ module.exports = grammar({
alias($.identifier, "name"), alias($.identifier, "name"),
optional(seq("uses", "(", repeat1($.identifier), ")")), optional(seq("uses", "(", repeat1($.identifier), ")")),
":", ":",
$.typeExpr, $._typeExpr,
":=", ":=",
$.jsLitString $.jsLitString
), ),
ptypeDecl: $ => seq( ptypeDecl: $ => seq(
"ptype", "ptype",
alias($.identifier, $.name), alias($.identifier, $.name),
optional(seq(":", $.typeExpr)) optional(seq(":", $._typeExpr))
), ),
importDef: ($) => seq("import", $.qname), importDef: ($) => seq("import", $.qname),
mixfixDecl: $ => seq( mixfixDecl: $ => seq(
@@ -165,7 +182,7 @@ module.exports = grammar({
), ),
instanceDecl: $ => seq( instanceDecl: $ => seq(
"instance", "instance",
$.typeExpr, $._typeExpr,
"where", "where",
layout($, choice($.sigDecl, $.defDecl)) layout($, choice($.sigDecl, $.defDecl))
), ),

View File

@@ -2,14 +2,14 @@
"let" "let"
; "in" ; "in"
"where" "where"
; "case" "of" "case" "of"
"data" "data"
;"U" ;"U"
"do" "do"
"ptype" "pfunc" "ptype" "pfunc"
"module" "module"
; "infixl" "infixr" "infix" ; "infixl" "infixr" "infix"
"∀" ; "forall" "∀" "forall"
"import" "import"
"uses" "derive" "uses" "derive"
"class" "instance" "record" "constructor" "class" "instance" "record" "constructor"

3
queries/injections.scm Normal file
View File

@@ -0,0 +1,3 @@
(jsLitString (jsStringFragment) @injection.content
(#set! injection.language "javascript"))

246
src/grammar.json generated
View File

@@ -91,7 +91,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
} }
] ]
}, },
@@ -127,7 +127,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -149,7 +149,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -166,7 +166,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -319,6 +319,27 @@
"type": "PATTERN", "type": "PATTERN",
"value": "'(\\\\)?.'" "value": "'(\\\\)?.'"
}, },
"doLet": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "let"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "_typeExpr"
}
]
},
"doCaseLet": { "doCaseLet": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@@ -344,7 +365,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@@ -394,7 +415,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@@ -426,27 +447,6 @@
} }
] ]
}, },
"doLet": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "let"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "term"
}
]
},
"_doExpr": { "_doExpr": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@@ -531,9 +531,166 @@
} }
] ]
}, },
"caseExpr": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "case"
},
{
"type": "SYMBOL",
"name": "_typeExpr"
},
{
"type": "STRING",
"value": "of"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "start"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "semi"
},
{
"type": "SYMBOL",
"name": "caseAlt"
}
]
}
},
{
"type": "SYMBOL",
"name": "end"
}
]
}
]
},
"caseLet": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "let"
},
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_typeExpr"
},
{
"type": "STRING",
"value": ")"
},
{
"type": "STRING",
"value": "="
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "orAlt"
}
},
{
"type": "STRING",
"value": "in"
}
]
},
"letAssign": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "_typeExpr"
}
]
},
"letStmt": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "let"
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "start"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "semi"
},
{
"type": "SYMBOL",
"name": "letAssign"
}
]
}
},
{
"type": "SYMBOL",
"name": "end"
}
]
},
{
"type": "STRING",
"value": "in"
},
{
"type": "SYMBOL",
"name": "_typeExpr"
}
]
},
"_term2": { "_term2": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SYMBOL",
"name": "caseExpr"
},
{
"type": "SYMBOL",
"name": "caseLet"
},
{
"type": "SYMBOL",
"name": "letStmt"
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "lamExpr" "name": "lamExpr"
@@ -627,7 +784,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -644,7 +801,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -689,7 +846,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -701,11 +858,20 @@
}, },
"forall": { "forall": {
"type": "SEQ", "type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [ "members": [
{ {
"type": "STRING", "type": "STRING",
"value": "∀" "value": "∀"
}, },
{
"type": "STRING",
"value": "forall"
}
]
},
{ {
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
@@ -719,7 +885,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
} }
] ]
}, },
@@ -744,11 +910,11 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
} }
] ]
}, },
"typeExpr": { "_typeExpr": {
"type": "PREC_RIGHT", "type": "PREC_RIGHT",
"value": 0, "value": 0,
"content": { "content": {
@@ -781,7 +947,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
} }
] ]
}, },
@@ -808,7 +974,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
} }
] ]
}, },
@@ -877,7 +1043,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@@ -1003,7 +1169,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "CHOICE", "type": "CHOICE",
@@ -1153,7 +1319,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "STRING", "type": "STRING",
@@ -1193,7 +1359,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
} }
] ]
}, },
@@ -1427,7 +1593,7 @@
}, },
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "typeExpr" "name": "_typeExpr"
}, },
{ {
"type": "STRING", "type": "STRING",

347
src/node-types.json generated
View File

@@ -7,12 +7,20 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -31,7 +39,15 @@
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{
"type": "term",
"named": true "named": true
} }
] ]
@@ -52,6 +68,72 @@
] ]
} }
}, },
{
"type": "caseExpr",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "binders",
"named": true
},
{
"type": "caseAlt",
"named": true
},
{
"type": "end",
"named": true
},
{
"type": "forall",
"named": true
},
{
"type": "semi",
"named": true
},
{
"type": "start",
"named": true
},
{
"type": "term",
"named": true
}
]
}
},
{
"type": "caseLet",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{
"type": "orAlt",
"named": true
},
{
"type": "term",
"named": true
}
]
}
},
{ {
"type": "classDecl", "type": "classDecl",
"named": true, "named": true,
@@ -99,10 +181,18 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{ {
"type": "end", "type": "end",
"named": true "named": true
}, },
{
"type": "forall",
"named": true
},
{ {
"type": "semi", "type": "semi",
"named": true "named": true
@@ -116,7 +206,7 @@
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -130,12 +220,20 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "lhs", "type": "lhs",
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
}, },
{ {
@@ -168,6 +266,14 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "orAlt", "type": "orAlt",
"named": true "named": true
@@ -175,10 +281,6 @@
{ {
"type": "term", "type": "term",
"named": true "named": true
},
{
"type": "typeExpr",
"named": true
} }
] ]
} }
@@ -226,6 +328,14 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "orAlt", "type": "orAlt",
"named": true "named": true
@@ -233,10 +343,6 @@
{ {
"type": "term", "type": "term",
"named": true "named": true
},
{
"type": "typeExpr",
"named": true
} }
] ]
} }
@@ -249,6 +355,14 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@@ -283,12 +397,20 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -332,6 +454,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{ {
"type": "defDecl", "type": "defDecl",
"named": true "named": true
@@ -340,6 +466,10 @@
"type": "end", "type": "end",
"named": true "named": true
}, },
{
"type": "forall",
"named": true
},
{ {
"type": "semi", "type": "semi",
"named": true "named": true
@@ -353,7 +483,7 @@
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -382,12 +512,86 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true
}
]
}
},
{
"type": "letAssign",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "term",
"named": true
}
]
}
},
{
"type": "letStmt",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "binders",
"named": true
},
{
"type": "end",
"named": true
},
{
"type": "forall",
"named": true
},
{
"type": "letAssign",
"named": true
},
{
"type": "semi",
"named": true
},
{
"type": "start",
"named": true
},
{
"type": "term",
"named": true "named": true
} }
] ]
@@ -401,10 +605,18 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{ {
"type": "character", "type": "character",
"named": true "named": true
}, },
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@@ -422,7 +634,7 @@
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -537,6 +749,14 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@@ -546,7 +766,7 @@
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -560,12 +780,20 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "name", "type": "name",
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -652,10 +880,18 @@
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{ {
"type": "character", "type": "character",
"named": true "named": true
}, },
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@@ -673,7 +909,7 @@
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -687,12 +923,20 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
}, },
{ {
"type": "typeExpr", "type": "term",
"named": true "named": true
} }
] ]
@@ -722,6 +966,18 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "binders",
"named": true
},
{
"type": "caseExpr",
"named": true
},
{
"type": "caseLet",
"named": true
},
{ {
"type": "character", "type": "character",
"named": true "named": true
@@ -734,6 +990,10 @@
"type": "dollar", "type": "dollar",
"named": true "named": true
}, },
{
"type": "forall",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@@ -746,6 +1006,10 @@
"type": "lamExpr", "type": "lamExpr",
"named": true "named": true
}, },
{
"type": "letStmt",
"named": true
},
{ {
"type": "number", "type": "number",
"named": true "named": true
@@ -758,36 +1022,9 @@
"type": "string", "type": "string",
"named": true "named": true
}, },
{
"type": "typeExpr",
"named": true
}
]
}
},
{
"type": "typeExpr",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "binders",
"named": true
},
{
"type": "forall",
"named": true
},
{ {
"type": "term", "type": "term",
"named": true "named": true
},
{
"type": "typeExpr",
"named": true
} }
] ]
} }
@@ -887,6 +1124,10 @@
"type": "`", "type": "`",
"named": false "named": false
}, },
{
"type": "case",
"named": false
},
{ {
"type": "character", "type": "character",
"named": true "named": true
@@ -932,6 +1173,10 @@
"type": "end", "type": "end",
"named": true "named": true
}, },
{
"type": "forall",
"named": false
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@@ -944,6 +1189,10 @@
"type": "import", "type": "import",
"named": false "named": false
}, },
{
"type": "in",
"named": false
},
{ {
"type": "infixl", "type": "infixl",
"named": false "named": false
@@ -980,6 +1229,10 @@
"type": "number", "type": "number",
"named": true "named": true
}, },
{
"type": "of",
"named": false
},
{ {
"type": "pfunc", "type": "pfunc",
"named": false "named": false

53694
src/parser.c generated

File diff suppressed because it is too large Load Diff

View File

@@ -53,6 +53,13 @@ static int32_t peek(State *state) {
#define PEEK lexer->lookahead #define PEEK lexer->lookahead
#define PEEK_WS (PEEK == ' ' || PEEK == '\n' || PEEK == '\t') #define PEEK_WS (PEEK == ' ' || PEEK == '\n' || PEEK == '\t')
static bool isAtIn(TSLexer *lexer) {
if (PEEK != 'i') return false;
lexer->mark_end(lexer);
lexer->advance(lexer, false);
return PEEK == 'n';
}
/** /**
* The custom scanner is responsible for the virtual indent, outdent, and semi tokens. * The custom scanner is responsible for the virtual indent, outdent, and semi tokens.
* Additionally it handles whitespace. This allows us to give the virtual tokens priority over * Additionally it handles whitespace. This allows us to give the virtual tokens priority over
@@ -95,16 +102,13 @@ bool tree_sitter_newt_external_scanner_scan(State *state, TSLexer *lexer,
// even if it's not expected (I think this is important) // even if it's not expected (I think this is important)
// on the editor side there is a `then` expected vs outdented `then`, but // on the editor side there is a `then` expected vs outdented `then`, but
// maybe GLR can detect a "stray" END token? // maybe GLR can detect a "stray" END token?
if (syms[VIRT_END] || true) { if (ws && (col < cur || PEEK == '|' || isAtIn(lexer))) {
if (col < cur) {
fprintf(stderr, "end [%d %d %d %d] %d %d\n", syms[0], syms[1], syms[2], fprintf(stderr, "end [%d %d %d %d] %d %d\n", syms[0], syms[1], syms[2],
syms[3], col, cur); syms[3], col, cur);
pop(state); pop(state);
lexer->result_symbol = VIRT_END; lexer->result_symbol = VIRT_END;
return true; return true;
} }
}
// but we can't do that for semi? // but we can't do that for semi?
if (syms[VIRT_SEMI]) { if (syms[VIRT_SEMI]) {
// FIXME - not eof, but we are requiring one at end of file at the moment. // FIXME - not eof, but we are requiring one at end of file at the moment.

View File

@@ -13,6 +13,7 @@
"class-name": "TreeSitterNewt" "class-name": "TreeSitterNewt"
} }
], ],
"highlights": "queries/highlights.scm",
"metadata": { "metadata": {
"version": "0.1.0", "version": "0.1.0",
"license": "MIT", "license": "MIT",