Skip to content

Commit

Permalink
fix: improve jumps and class qualifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime committed Oct 15, 2023
1 parent 5baa0fe commit 0bd3cab
Show file tree
Hide file tree
Showing 5 changed files with 518,626 additions and 502,683 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 @@ -1114,15 +1117,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 @@ -5441,8 +5479,13 @@
"value": "return@"
},
{
"type": "SYMBOL",
"name": "_lexical_identifier"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "label"
}
]
},
Expand All @@ -5454,8 +5497,13 @@
"value": "continue@"
},
{
"type": "SYMBOL",
"name": "_lexical_identifier"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "label"
}
]
},
Expand All @@ -5467,8 +5515,13 @@
"value": "break@"
},
{
"type": "SYMBOL",
"name": "_lexical_identifier"
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_lexical_identifier"
},
"named": true,
"value": "label"
}
]
},
Expand All @@ -5480,21 +5533,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
Loading

0 comments on commit 0bd3cab

Please sign in to comment.