Skip to content

Commit

Permalink
Merge pull request #190 from aibaars/end-less-methods
Browse files Browse the repository at this point in the history
Endless methods
  • Loading branch information
aibaars authored Oct 9, 2021
2 parents 0c1e470 + 85ce8b4 commit d1171a5
Show file tree
Hide file tree
Showing 4 changed files with 210,798 additions and 166,152 deletions.
41 changes: 32 additions & 9 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,43 @@ module.exports = grammar({
_method_rest: $ => seq(
field('name', $._method_name),
choice(
$._body_expr,
seq(
field('parameters', alias($.parameters, $.method_parameters)),
optional($._terminator)
choice(
seq(optional($._terminator), $._body_statement),
$._body_expr
)

),
seq(
optional(
field('parameters', alias($.bare_parameters, $.method_parameters))
),
$._terminator
$._terminator,
$._body_statement
),
),
$._body_statement
),

rescue_modifier_arg: $ => prec(PREC.RESCUE,
seq(
field('body', $._arg),
'rescue',
field('handler', $._arg)
)
),

_body_expr: $ =>
seq(
'=',
choice(
$._arg,
alias($.rescue_modifier_arg, $.rescue_modifier),
)
),


parameters: $ => seq(
'(',
commaSep($._formal_parameter),
Expand Down Expand Up @@ -748,7 +771,7 @@ module.exports = grammar({
$.class_variable,
$.global_variable
),
setter: $ => seq(field('name', $.identifier), '='),
setter: $ => seq(field('name', $.identifier), token.immediate('=')),

undef: $ => seq('undef', commaSep1($._method_name)),
alias: $ => seq(
Expand Down Expand Up @@ -794,7 +817,7 @@ module.exports = grammar({
character: $ => /\?(\\\S({[0-9A-Fa-f]*}|[0-9A-Fa-f]*|-\S([MC]-\S)?)?|\S)/,

interpolation: $ => seq(
'#{', optional($._statements),'}'
'#{', optional($._statements), '}'
),

string: $ => seq(
Expand Down Expand Up @@ -916,18 +939,18 @@ module.exports = grammar({
}
});

function sep (rule, separator) {
function sep(rule, separator) {
return optional(sep1(rule, separator));
}

function sep1 (rule, separator) {
function sep1(rule, separator) {
return seq(rule, repeat(seq(separator, rule)));
}

function commaSep1 (rule) {
function commaSep1(rule) {
return sep1(rule, ',');
}

function commaSep (rule) {
function commaSep(rule) {
return optional(commaSep1(rule));
}
95 changes: 88 additions & 7 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,10 @@
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_body_expr"
},
{
"type": "SEQ",
"members": [
Expand All @@ -314,11 +318,29 @@
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminator"
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_body_statement"
}
]
},
{
"type": "BLANK"
"type": "SYMBOL",
"name": "_body_expr"
}
]
}
Expand Down Expand Up @@ -351,14 +373,70 @@
{
"type": "SYMBOL",
"name": "_terminator"
},
{
"type": "SYMBOL",
"name": "_body_statement"
}
]
}
]
}
]
},
"rescue_modifier_arg": {
"type": "PREC",
"value": 16,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "body",
"content": {
"type": "SYMBOL",
"name": "_arg"
}
},
{
"type": "STRING",
"value": "rescue"
},
{
"type": "FIELD",
"name": "handler",
"content": {
"type": "SYMBOL",
"name": "_arg"
}
}
]
}
},
"_body_expr": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "_body_statement"
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_arg"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "rescue_modifier_arg"
},
"named": true,
"value": "rescue_modifier"
}
]
}
]
},
Expand Down Expand Up @@ -4968,8 +5046,11 @@
}
},
{
"type": "STRING",
"value": "="
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "="
}
}
]
},
Expand Down
Loading

0 comments on commit d1171a5

Please sign in to comment.