Skip to content

Commit

Permalink
fix: improve jumps and class qualifiers (fwcd#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime authored Nov 8, 2023
1 parent 494fb76 commit 16de60e
Show file tree
Hide file tree
Showing 5 changed files with 523,930 additions and 507,902 deletions.
48 changes: 37 additions & 11 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const PREC = {
const DEC_DIGITS = token(sep1(/[0-9]+/, /_+/));
const HEX_DIGITS = token(sep1(/[0-9a-fA-F]+/, /_+/));
const BIN_DIGITS = token(sep1(/[01]/, /_+/));
const REAL_EXPONENT = token(seq(/[eE]/, optional(/[+-]/), DEC_DIGITS))
const REAL_EXPONENT = token(seq(/[eE]/, optional(/[+-]/), DEC_DIGITS));

module.exports = grammar({
name: "kotlin",
Expand Down Expand Up @@ -812,13 +812,16 @@ module.exports = grammar({
$.class_body
),

this_expression: $ => "this",
this_expression: $ => choice(
"this",
$._this_at
),

super_expression: $ => seq(
super_expression: $ => prec.right(choice(
"super",
// TODO optional(seq("<", $._type, ">")),
// TODO optional(seq("@", $.simple_identifier))
),
seq("super", "<", $._type, ">"),
$._super_at
)),

if_expression: $ => prec.right(seq(
"if",
Expand Down Expand Up @@ -1116,15 +1119,38 @@ module.exports = grammar({
// Keywords
// ==========

_return_at: $ => seq("return@", $._lexical_identifier),
_return_at: $ => seq(
"return@",
alias($._lexical_identifier, $.label)
),

_continue_at: $ => seq("continue@", $._lexical_identifier),
_continue_at: $ => seq(
"continue@",
alias($._lexical_identifier, $.label)
),

_break_at: $ => seq("break@", $._lexical_identifier),
_break_at: $ => seq(
"break@",
alias($._lexical_identifier, $.label)
),

_this_at: $ => seq("this@", $._lexical_identifier),
_this_at: $ => seq(
"this@",
alias($._lexical_identifier, $.type_identifier)
),

_super_at: $ => seq("super@", $._lexical_identifier),
_super_at: $ => choice(
seq(
"super@",
alias($._lexical_identifier, $.type_identifier)
),
seq(
"super",
"<", $._type, ">",
token.immediate("@"),
alias($._lexical_identifier, $.type_identifier)
)
),

// ==========
// Literals
Expand Down
143 changes: 124 additions & 19 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -4169,18 +4169,56 @@
]
},
"this_expression": {
"type": "STRING",
"value": "this"
},
"super_expression": {
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "super"
"value": "this"
},
{
"type": "SYMBOL",
"name": "_this_at"
}
]
},
"super_expression": {
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "super"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "super"
},
{
"type": "STRING",
"value": "<"
},
{
"type": "SYMBOL",
"name": "_type"
},
{
"type": "STRING",
"value": ">"
}
]
},
{
"type": "SYMBOL",
"name": "_super_at"
}
]
}
},
"if_expression": {
"type": "PREC_RIGHT",
"value": 0,
Expand Down Expand Up @@ -5449,8 +5487,13 @@
"value": "return@"
},
{
"type": "SYMBOL",
"name": "_lexical_identifier"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "label"
}
]
},
Expand All @@ -5462,8 +5505,13 @@
"value": "continue@"
},
{
"type": "SYMBOL",
"name": "_lexical_identifier"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "label"
}
]
},
Expand All @@ -5475,8 +5523,13 @@
"value": "break@"
},
{
"type": "SYMBOL",
"name": "_lexical_identifier"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "label"
}
]
},
Expand All @@ -5488,21 +5541,73 @@
"value": "this@"
},
{
"type": "SYMBOL",
"name": "_lexical_identifier"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "type_identifier"
}
]
},
"_super_at": {
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "super@"
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "super@"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "type_identifier"
}
]
},
{
"type": "SYMBOL",
"name": "_lexical_identifier"
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "super"
},
{
"type": "STRING",
"value": "<"
},
{
"type": "SYMBOL",
"name": "_type"
},
{
"type": "STRING",
"value": ">"
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "@"
}
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "type_identifier"
}
]
}
]
},
Expand Down
63 changes: 56 additions & 7 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -4936,7 +4936,7 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"multiple": true,
"required": false,
"types": [
{
Expand Down Expand Up @@ -5023,6 +5023,10 @@
"type": "jump_expression",
"named": true
},
{
"type": "label",
"named": true
},
{
"type": "lambda_literal",
"named": true
Expand Down Expand Up @@ -5098,6 +5102,11 @@
]
}
},
{
"type": "label",
"named": true,
"fields": {}
},
{
"type": "lambda_literal",
"named": true,
Expand Down Expand Up @@ -7822,12 +7831,56 @@
{
"type": "super_expression",
"named": true,
"fields": {}
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "function_type",
"named": true
},
{
"type": "not_nullable_type",
"named": true
},
{
"type": "nullable_type",
"named": true
},
{
"type": "parenthesized_type",
"named": true
},
{
"type": "type_identifier",
"named": true
},
{
"type": "type_modifiers",
"named": true
},
{
"type": "user_type",
"named": true
}
]
}
},
{
"type": "this_expression",
"named": true,
"fields": {}
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "type_identifier",
"named": true
}
]
}
},
{
"type": "try_expression",
Expand Down Expand Up @@ -9371,10 +9424,6 @@
"type": "is",
"named": false
},
{
"type": "label",
"named": true
},
{
"type": "lateinit",
"named": false
Expand Down
Loading

0 comments on commit 16de60e

Please sign in to comment.