From 4c3cb92b4bad6716394eea398f1ce5ee3f4a2d00 Mon Sep 17 00:00:00 2001 From: Eugene Yokota Date: Sat, 14 Jan 2023 15:37:55 -0500 Subject: [PATCH] Singleton type Problem ------- Currently singleton types are treated as `stable_type_identifier`. Solution -------- This adds `singleton_type`. --- corpus/types.txt | 17 +++++++++++++++++ grammar.js | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/corpus/types.txt b/corpus/types.txt index 82494f67a..f9ccd4d4d 100644 --- a/corpus/types.txt +++ b/corpus/types.txt @@ -293,6 +293,23 @@ class Test(d: "hello", b: 25) (literal_type (integer_literal)))))) +================================== +Singleton Types +================================== + +class A: + def foobar: this.type = this + type X = A.B.type + +--- + +(compilation_unit + (class_definition + (identifier) + (template_body + (function_definition (identifier) (singleton_type (identifier)) (identifier)) + (type_definition (type_identifier) (singleton_type (stable_identifier (identifier) (identifier))))))) + ================================== Opaque type aliases (Scala 3) ================================== diff --git a/grammar.js b/grammar.js index d1520c86c..9b2ed8604 100644 --- a/grammar.js +++ b/grammar.js @@ -682,6 +682,7 @@ module.exports = grammar({ $.generic_type, $.projected_type, $.tuple_type, + $.singleton_type, $.stable_type_identifier, $._type_identifier, $.wildcard, @@ -705,6 +706,12 @@ module.exports = grammar({ ')', ), + singleton_type: $ => prec.left(PREC.stable_type_id, seq( + choice($._identifier, $.stable_identifier), + '.', + 'type', + )), + stable_type_identifier: $ => prec.left(PREC.stable_type_id, seq( choice($._identifier, $.stable_identifier), '.',