fix type decl scoping

pull/625/head^2
Nikolaj Sidorenco 2024-05-05 16:06:50 +07:00
parent c5fff9dc9d
commit 830d01faa1
No known key found for this signature in database
13 changed files with 295952 additions and 299699 deletions

@ -1 +1,3 @@
do return ctx.Ok x :> int
let x =
for i in ids do
ignore i

@ -1,15 +1,3 @@
namespace Test
do prinfn "hello"
/// <summary>
/// A is used for...
/// and other stuff
/// </summary>
type A =
{
/// <summary> B is used for... </summary>
B: int
/// <summary> C is used for... </summary>
C: int
}
type A() =
inherit ControllerBase()
member ctx.Index() = ()

@ -223,7 +223,9 @@ module.exports = grammar({
)),
_function_or_value_defns: $ =>
seq($._function_or_value_defn_body, repeat(seq('and', $._function_or_value_defn_body))),
prec.right(
seq($._function_or_value_defn_body, repeat(seq('and', $._function_or_value_defn_body))),
),
function_or_value_defn: $ =>
seq(
@ -431,22 +433,12 @@ module.exports = grammar({
$.match_expression,
$.try_expression,
$.literal_expression,
$.call_expression,
// $.call_expression,
$.tuple_expression,
$.application_expression,
// (static-typars : (member-sig) expr)
),
call_expression: $ =>
prec.left(PREC.PAREN_APP + 100,
seq(
$._expression,
token.immediate(prec(10000, '(')),
optional($._expression_block),
')',
),
),
tuple_expression: $ =>
prec.left(PREC.TUPLE_EXPR,
seq(
@ -798,9 +790,12 @@ module.exports = grammar({
prec.left(PREC.APP_EXPR,
seq(
$._expression,
$._expression,
),
),
choice(
prec(PREC.APP_EXPR, $._expression),
prec(PREC.PAREN_APP + 100, seq(token.immediate(prec(10000, '(')), optional($._expression_block), ')'),
)
)
)),
sequential_expression: $ =>
prec.right(PREC.SEQ_EXPR,
@ -1290,7 +1285,11 @@ module.exports = grammar({
$._type_defn_elements,
),
_class_type_body: $ => repeat1($._class_type_body_inner),
_class_type_body: $ =>
seq(
$._class_type_body_inner,
repeat(seq($._newline, $._class_type_body_inner)),
),
_record_type_defn_inner: $ =>
seq(
@ -1395,12 +1394,13 @@ module.exports = grammar({
)),
anon_type_defn: $ =>
seq(
$.type_name,
optional($.primary_constr_args),
'=',
scoped($._class_type_body, $._indent, $._dedent),
),
prec.left(
seq(
$.type_name,
optional($.primary_constr_args),
'=',
scoped($._class_type_body, $._indent, $._dedent),
)),
primary_constr_args: $ =>
field('constructor',
@ -1470,17 +1470,18 @@ module.exports = grammar({
),
member_defn: $ =>
seq(
optional($.attributes),
choice(
seq(optional('static'), optional($.access_modifier), 'member', $.method_or_prop_defn),
seq('abstract', optional($.access_modifier), optional('member'), $.member_signature),
seq('override', optional($.access_modifier), $.method_or_prop_defn),
seq('default', optional($.access_modifier), $.method_or_prop_defn),
seq(optional('static'), 'val', optional('mutable'), optional($.access_modifier), $.identifier, ':', $.type),
$.additional_constr_defn,
),
),
prec(PREC.APP_EXPR + 100000,
seq(
optional($.attributes),
choice(
seq(optional('static'), optional($.access_modifier), 'member', $.method_or_prop_defn),
seq('abstract', optional($.access_modifier), optional('member'), $.member_signature),
seq('override', optional($.access_modifier), $.method_or_prop_defn),
seq('default', optional($.access_modifier), $.method_or_prop_defn),
seq(optional('static'), 'val', optional('mutable'), optional($.access_modifier), $.identifier, ':', $.type),
$.additional_constr_defn,
),
)),
property_or_ident: $ =>
choice(
@ -1550,7 +1551,7 @@ module.exports = grammar({
seq(
'inherit',
$.type,
optional($._expression),
optional($._expression_block),
),
),

@ -87,7 +87,6 @@
method: (identifier) @variable.member)
args: _ @variable.parameter))
(call_expression) @function.method.call
(application_expression) @function.call
(compiler_directive_decl

@ -15,7 +15,7 @@
((rules) @indent.begin
(#set! indent.start_at_same_line))
((call_expression) @indent.align
((application_expression) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))

661
src/grammar.json generated

@ -523,29 +523,33 @@
}
},
"_function_or_value_defns": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_function_or_value_defn_body"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "and"
},
{
"type": "SYMBOL",
"name": "_function_or_value_defn_body"
}
]
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_function_or_value_defn_body"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "and"
},
{
"type": "SYMBOL",
"name": "_function_or_value_defn_body"
}
]
}
}
}
]
]
}
},
"function_or_value_defn": {
"type": "SEQ",
@ -1502,10 +1506,6 @@
"type": "SYMBOL",
"name": "literal_expression"
},
{
"type": "SYMBOL",
"name": "call_expression"
},
{
"type": "SYMBOL",
"name": "tuple_expression"
@ -1516,46 +1516,6 @@
}
]
},
"call_expression": {
"type": "PREC_LEFT",
"value": 121,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": 10000,
"content": {
"type": "STRING",
"value": "("
}
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression_block"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
},
"tuple_expression": {
"type": "PREC_LEFT",
"value": 16,
@ -2963,8 +2923,53 @@
"name": "_expression"
},
{
"type": "SYMBOL",
"name": "_expression"
"type": "CHOICE",
"members": [
{
"type": "PREC",
"value": 16,
"content": {
"type": "SYMBOL",
"name": "_expression"
}
},
{
"type": "PREC",
"value": 121,
"content": {
"type": "SEQ",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": 10000,
"content": {
"type": "STRING",
"value": "("
}
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_expression_block"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": ")"
}
]
}
}
]
}
]
}
@ -4629,11 +4634,29 @@
]
},
"_class_type_body": {
"type": "REPEAT1",
"content": {
"type": "SYMBOL",
"name": "_class_type_body_inner"
}
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_class_type_body_inner"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_newline"
},
{
"type": "SYMBOL",
"name": "_class_type_body_inner"
}
]
}
}
]
},
"_record_type_defn_inner": {
"type": "SEQ",
@ -5124,50 +5147,54 @@
}
},
"anon_type_defn": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "type_name"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "primary_constr_args"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "block",
"content": {
"type": "SEQ",
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "type_name"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_indent"
},
{
"type": "SYMBOL",
"name": "_class_type_body"
"name": "primary_constr_args"
},
{
"type": "SYMBOL",
"name": "_dedent"
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "="
},
{
"type": "FIELD",
"name": "block",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_indent"
},
{
"type": "SYMBOL",
"name": "_class_type_body"
},
{
"type": "SYMBOL",
"name": "_dedent"
}
]
}
}
}
]
]
}
},
"primary_constr_args": {
"type": "FIELD",
@ -5468,211 +5495,215 @@
]
},
"member_defn": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "attributes"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "static"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "member"
},
{
"type": "SYMBOL",
"name": "method_or_prop_defn"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "abstract"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "member"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "member_signature"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "override"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "method_or_prop_defn"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "default"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "method_or_prop_defn"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "static"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "val"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "mutable"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "type"
}
]
},
{
"type": "SYMBOL",
"name": "additional_constr_defn"
}
]
}
]
"type": "PREC",
"value": 100016,
"content": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "attributes"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "static"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "member"
},
{
"type": "SYMBOL",
"name": "method_or_prop_defn"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "abstract"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "member"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "member_signature"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "override"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "method_or_prop_defn"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "default"
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "method_or_prop_defn"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "static"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "val"
},
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "mutable"
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "access_modifier"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "type"
}
]
},
{
"type": "SYMBOL",
"name": "additional_constr_defn"
}
]
}
]
}
},
"property_or_ident": {
"type": "CHOICE",
@ -5937,7 +5968,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_expression"
"name": "_expression_block"
},
{
"type": "BLANK"

19
src/node-types.json generated

@ -23,10 +23,6 @@
"type": "brace_expression",
"named": true
},
{
"type": "call_expression",
"named": true
},
{
"type": "ce_expression",
"named": true
@ -743,21 +739,6 @@
"named": true,
"fields": {}
},
{
"type": "call_expression",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "_expression",
"named": true
}
]
}
},
{
"type": "ce_expression",
"named": true,

594796
src/parser.c generated

File diff suppressed because it is too large Load Diff

@ -1577,7 +1577,7 @@ let test f =
(long_identifier_or_op
(long_identifier
(identifier)))))
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)
@ -1877,7 +1877,7 @@ let a b =
(const_pattern
(bool)))
(infix_expression
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)
@ -1900,9 +1900,9 @@ let a b =
(const_pattern
(bool)))
(infix_expression
(call_expression
(application_expression
(dot_expression
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)
@ -1922,7 +1922,7 @@ let a b =
(rule
(wildcard_pattern)
(infix_expression
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)
@ -2484,3 +2484,15 @@ do
(bool))
(const
(int)))))))))
================================================================================
prefer application expression + record over CE expression
================================================================================
let f x =
let b = 1
return Some { A = 1
B = 2 }
--------------------------------------------------------------------------------

@ -172,7 +172,7 @@ let inline double<^a when ^a:(member Double: unit -> ^a)> (x: ^a) = x.Double()
(type
(type_argument
(identifier))))))
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)
@ -216,7 +216,7 @@ let inline double<'a when 'a:(member Double: unit -> 'a)> (x: 'a) = x.Double()
(type
(type_argument
(identifier))))))
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)

@ -236,3 +236,18 @@ module B =
(identifier))))
(const
(unit))))))
================================================================================
top-level expression in module
================================================================================
module A =
()
--------------------------------------------------------------------------------
(file
(module_defn
(identifier)
(const
(unit))))

@ -90,7 +90,7 @@ do
(file
(value_declaration
(do
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))

@ -412,12 +412,9 @@ type A() =
(type
(long_identifier
(identifier)))
(sequential_expression
(const
(unit))
(do_expression
(const
(unit))))))))
(const (unit)))
(const (unit)))))
================================================================================
class inherit and member method definition
@ -439,22 +436,17 @@ type A() =
(type
(long_identifier
(identifier)))
(sequential_expression
(const
(const
(unit)))
(member_defn
(method_or_prop_defn
(property_or_ident
(identifier)
(identifier))
(const_pattern
(unit))
(infix_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))
(call_expression
(long_identifier_or_op
(long_identifier
(identifier)
(identifier)))))
(infix_op)
(const
(unit))))))))
(const
(unit)))))))
================================================================================
class member then interface impl. test
@ -818,7 +810,7 @@ type A(x:int, y:int) =
(type
(long_identifier
(identifier)))))
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier)))
@ -950,7 +942,7 @@ type A(x: int, y:int) =
(type
(type_argument
(identifier))))))
(call_expression
(application_expression
(long_identifier_or_op
(long_identifier
(identifier))))))))))