Skip to content

Commit

Permalink
Refactor EPipeEnum, EEnum, CEnum: Update typeName to use QualifiedTyp…
Browse files Browse the repository at this point in the history
…eIdentifier
  • Loading branch information
OceanOak committed Nov 8, 2024
1 parent 3f99e8e commit 061d113
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 52 deletions.
20 changes: 17 additions & 3 deletions backend/testfiles/execution/stdlib/semanticTokenization.dark
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,14 @@ module TokenizeConstantDeclaration =
(TokenType.Symbol,
(0L, 16L),
(0L, 17L))
(TokenType.TypeName,
(TokenType.ModuleName,
(0L, 18L),
(0L, 24L))
(TokenType.ModuleName,
(0L, 25L),
(0L, 31L))
(TokenType.TypeName,
(0L, 32L),
(0L, 38L))
(TokenType.Symbol,
(0L, 38L),
Expand Down Expand Up @@ -1200,8 +1206,14 @@ module TokenizePipeExpression =
(TokenType.Operator,
(0L, 3L),
(0L, 5L))
(TokenType.TypeName,
(TokenType.ModuleName,
(0L, 6L),
(0L, 12L))
(TokenType.ModuleName,
(0L, 13L),
(0L, 19L))
(TokenType.TypeName,
(0L, 20L),
(0L, 26L))
(TokenType.Symbol,
(0L, 26L),
Expand Down Expand Up @@ -1567,7 +1579,9 @@ module TokenizeMatchExpression =

("match Stdlib.Result.Result.Ok(5L) with\n| Ok(5L) -> true\n| Error(e) -> false"
|> tokenize) = [ (TokenType.Keyword, (0L, 0L), (0L, 5L))
(TokenType.TypeName, (0L, 6L), (0L, 26L))
(TokenType.ModuleName, (0L, 6L), (0L, 12L))
(TokenType.ModuleName, (0L, 13L), (0L, 19L))
(TokenType.TypeName, (0L, 20L), (0L, 26L))
(TokenType.Symbol, (0L, 26L), (0L, 27L))
(TokenType.EnumMember, (0L, 27L), (0L, 29L))
(TokenType.Number, (0L, 30L), (0L, 31L))
Expand Down
7 changes: 4 additions & 3 deletions packages/darklang/languageTools/parser/core.dark
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ module Darklang =
(Range * (Range * List<String>) * (Range * String) * List<'a> * Range)
-> 'a)
: Stdlib.Result.Result<'a, WrittenTypes.Unparseable> =
let typeNameNode = findField node "type_name"
let typeNameNode =
findAndParseRequired node "type_name" Identifiers.parseQualifiedType

let symbolDotNode = findField node "symbol_dot"
let caseNameNode = findField node "case_name"

Expand All @@ -315,11 +317,10 @@ module Darklang =

match typeNameNode, symbolDotNode, caseNameNode, enumFieldsNode with
| Ok typeNameNode, Ok symbolDotNode, Ok caseNameNode, Ok enumFieldsNode ->
let typeName = typeNameNode.text |> Stdlib.String.split "."

ctor (
node.range,
(typeNameNode.range, typeName),
typeNameNode,
(caseNameNode.range, caseNameNode.text),
enumFieldsNode,
symbolDotNode.range
Expand Down
15 changes: 3 additions & 12 deletions packages/darklang/languageTools/semanticTokens.dark
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,7 @@ module Darklang =

| EPipeEnum(_, typeName, caseName, fields, symbolDot) ->
// CLEANUP: typeName should be tokenized as a QualifiedTypeIdentifier
let typeName =
match typeName with
| (range, _) -> [ makeToken range TokenType.TypeName ]
| _ -> []
let typeName = QualifiedTypeIdentifier.tokenize typeName

let caseName =
match caseName with
Expand Down Expand Up @@ -890,10 +887,7 @@ module Darklang =

// Option.Option.Some 1L
| EEnum(range, typeName, caseName, fields, symbolDot) ->
let typeName =
match typeName with
| (range, _) -> [ makeToken range TokenType.TypeName ]
| _ -> []
let typeName = QualifiedTypeIdentifier.tokenize typeName

let caseName =
match caseName with
Expand Down Expand Up @@ -1217,10 +1211,7 @@ module Darklang =
|> Stdlib.List.flatten

| CEnum(range, typeName, caseName, fields, symbolDot) ->
let typeName =
match typeName with
| (range, _) -> [ makeToken range TokenType.TypeName ]
| _ -> []
let typeName = QualifiedTypeIdentifier.tokenize typeName

let caseName =
match caseName with
Expand Down
7 changes: 3 additions & 4 deletions packages/darklang/languageTools/writtenTypes.dark
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ module Darklang =

| EEnum of
Range *
typeName: (Range * List<String>) *
typeName: QualifiedTypeIdentifier *
caseName: (Range * String) *
fields: List<Expr> *
/// between the typeName and the caseName
Expand Down Expand Up @@ -345,8 +345,7 @@ module Darklang =
symbolArrow: Range
| EPipeEnum of
Range *
// CLEANUP: this probably should be (Range * List<Range * String>)
typeName: (Range * List<String>) *
typeName: QualifiedTypeIdentifier *
caseName: (Range * String) *
fields: List<Expr> *
/// between the typeName and the caseName
Expand Down Expand Up @@ -400,7 +399,7 @@ module Darklang =
symbolCloseParen: Range
| CEnum of
Range *
typeName: (Range * List<String>) *
typeName: QualifiedTypeIdentifier *
caseName: (Range * String) *
fields: List<Const> *
symbolDot: Range
Expand Down
46 changes: 16 additions & 30 deletions packages/darklang/languageTools/writtenTypesToProgramTypes.dark
Original file line number Diff line number Diff line change
Expand Up @@ -380,19 +380,14 @@ module Darklang =

(ProgramTypes.PipeExpr.EPipeLambda(gid (), pats, body), unresolvedNames)

| EPipeEnum(_, (sr, typeName), (_, caseName), fields, _) ->
let typeName =
NameResolver.TypeName.resolve
| EPipeEnum(_, typeName, (_, caseName), fields, _) ->
let (typeName, typeArgs, typeNameUnresolvedNames) =
Identifiers.QualifiedType.toPT
onMissing
pm
owner
currentModule
(WrittenTypes.Name.Unresolved sr typeName)

let typNameUnresolvedNames =
match typeName with
| Ok _ -> []
| Error e -> [ (sr, e) ]
typeName

let (fields, fieldsUnresolvedNames) =
fields
Expand All @@ -402,7 +397,7 @@ module Darklang =

let unresolvedNames =
Stdlib.List.flatten
[ typNameUnresolvedNames
[ typeNameUnresolvedNames
fieldsUnresolvedNames |> Stdlib.List.flatten ]

(ProgramTypes.PipeExpr.EPipeEnum(gid (), typeName, caseName, fields),
Expand Down Expand Up @@ -574,19 +569,14 @@ module Darklang =
(ProgramTypes.Expr.ERecordUpdate(gid (), record, updates),
unresolvedNames)

| EEnum(_, (sr, typeName), (_, caseName), fields, _) ->
let typeName =
NameResolver.TypeName.resolve
| EEnum(_, typeName, (_, caseName), fields, _) ->
let (typeName, typeArgs, typeNameUnresolvedNames) =
Identifiers.QualifiedType.toPT
onMissing
pm
owner
currentModule
(WrittenTypes.Name.Unresolved sr typeName)

let typNameUnresolvedNames =
match typeName with
| Ok _ -> []
| Error e -> [ (sr, e) ]
typeName

let (fields, fieldsUnresolvedNames) =
fields
Expand All @@ -596,7 +586,7 @@ module Darklang =

let unresolvedNames =
Stdlib.List.flatten
[ typNameUnresolvedNames
[ typeNameUnresolvedNames
fieldsUnresolvedNames |> Stdlib.List.flatten ]

(ProgramTypes.Expr.EEnum(gid (), typeName, caseName, fields),
Expand Down Expand Up @@ -850,19 +840,14 @@ module Darklang =

(ProgramTypes.Const.CTuple(first, second, rest), unresolvedNames)

| CEnum(_, (sr, typeName), (_, caseName), fields, _) ->
let typeName =
NameResolver.TypeName.resolve
| CEnum(_, typeName, (_, caseName), fields, _) ->
let (typeName, typeArgs, typeNameUnresolvedNames) =
Identifiers.QualifiedType.toPT
onMissing
pm
owner
currentModule
(WrittenTypes.Name.Unresolved sr typeName)

let typeNameUnresolvedNames =
match typeName with
| Ok _ -> []
| Error e -> [ (sr, e) ]
typeName

let (fields, fieldsUnresolvedNames) =
fields
Expand Down Expand Up @@ -1408,7 +1393,8 @@ module Darklang =

let unresolvedNames =
Stdlib.List.flatten
[ declarationsUnresolvedNames; exprsToEvalUnresolvedNames ]
[ declarationsUnresolvedNames |> Stdlib.List.flatten
exprsToEvalUnresolvedNames |> Stdlib.List.flatten ]

let sourceFile =
ProgramTypes.SourceFile.SourceFile
Expand Down

0 comments on commit 061d113

Please sign in to comment.