Skip to content

Commit

Permalink
feat: additional class constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsidorenco committed Apr 21, 2024
1 parent ce21e33 commit 73c25c4
Show file tree
Hide file tree
Showing 6 changed files with 256,264 additions and 255,390 deletions.
6 changes: 4 additions & 2 deletions examples/types.fs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

type A<'T> =
abstract member F : 'T -> unit
type A(x: int, y:int) =
new(x:int) = A(x, x)

member _.P = x + y
35 changes: 16 additions & 19 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -1503,29 +1503,28 @@ module.exports = grammar({

additional_constr_defn: $ =>
seq(
// optional($.attributes),
optional($.access_modifier),
'new',
$._pattern,
$.as_defn,
'=',
// $.additional_constr_expr
),

additional_constr_expr: $ =>
choice(
seq($.additional_constr_expr, ';', $.additional_constr_expr),
seq($.additional_constr_expr, 'then', $._expression),
seq('if', $._expression, 'then', $.additional_constr_expr, 'else', $.additional_constr_expr),
seq('let', $._function_or_value_defn_body, 'in', $.additional_constr_expr), // TODO: "in" is optional?
$.additional_constr_init_expr,
scoped($._expression, $._indent, $._dedent),
),

additional_constr_init_expr: $ =>
choice(
seq('{', $.class_inherits_decl, $.field_initializers, '}'),
seq('new', $.type, $._expression),
),
// additional_constr_expr: $ =>
// prec.left(
// choice(
// // seq($.additional_constr_expr, ';', $.additional_constr_expr),
// // seq($.additional_constr_expr, 'then', $._expression),
// // seq('if', $._expression, 'then', $.additional_constr_expr, 'else', $.additional_constr_expr),
// // seq('let', $._function_or_value_defn_body, 'in', $.additional_constr_expr), // TODO: "in" is optional?
// $.additional_constr_init_expr,
// )),
//
// additional_constr_init_expr: $ =>
// choice(
// // seq('{', $.class_inherits_decl, $.field_initializers, '}'),
// $._expression,
// ),

class_inherits_decl: $ =>
prec.left(
Expand All @@ -1536,8 +1535,6 @@ module.exports = grammar({
),
),

as_defn: $ => seq('as', $.identifier),

field_initializer: $ =>
prec.right(
seq($.long_identifier,
Expand Down
140 changes: 2 additions & 138 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 4 additions & 88 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 73c25c4

Please sign in to comment.