Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: writtenTypes refactors #5426

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 64 additions & 64 deletions backend/testfiles/execution/stdlib/semanticTokenization.dark
Original file line number Diff line number Diff line change
Expand Up @@ -1586,67 +1586,67 @@ module TokenizeMatchExpression =
(TokenType.Keyword, (2L, 14L), (2L, 19L)) ]


module TokenizeModuleDeclaration =
("module MyModule =\n type ID = Int64" |> tokenize) = [ (TokenType.Keyword,
(0L, 0L),
(0L, 6L))
(TokenType.ModuleName,
(0L, 7L),
(0L, 15L))
(TokenType.Keyword,
(1L, 2L),
(1L, 6L))
(TokenType.TypeName,
(1L, 7L),
(1L, 9L))
(TokenType.Symbol,
(1L, 10L),
(1L, 11L))
(TokenType.TypeName,
(1L, 12L),
(1L, 17L)) ]

("""module MyModule =
type ID = Int64
let myFn (i: Int64): Int64 = 1L
const x = 100L
1L"""
|> tokenize) = [ (TokenType.Keyword, (0L, 0L), (0L, 6L))
(TokenType.ModuleName, (0L, 7L), (0L, 15L))
(TokenType.Keyword, (1L, 2L), (1L, 6L))
(TokenType.TypeName, (1L, 7L), (1L, 9L))
(TokenType.Symbol, (1L, 10L), (1L, 11L))
(TokenType.TypeName, (1L, 12L), (1L, 17L))
(TokenType.Keyword, (2L, 2L), (2L, 5L))
(TokenType.FunctionName, (2L, 6L), (2L, 10L))
(TokenType.Symbol, (2L, 11L), (2L, 12L))
(TokenType.ParameterName, (2L, 12L), (2L, 13L))
(TokenType.Symbol, (2L, 13L), (2L, 14L))
(TokenType.TypeName, (2L, 15L), (2L, 20L))
(TokenType.Symbol, (2L, 20L), (2L, 21L))
(TokenType.Symbol, (2L, 21L), (2L, 22L))
(TokenType.TypeName, (2L, 23L), (2L, 28L))
(TokenType.Symbol, (2L, 29L), (2L, 30L))
(TokenType.Number, (2L, 31L), (2L, 32L))
(TokenType.Symbol, (2L, 32L), (2L, 33L))
(TokenType.Keyword, (3L, 2L), (3L, 7L))
(TokenType.VariableName, (3L, 8L), (3L, 9L))
(TokenType.Symbol, (3L, 10L), (3L, 11L))
(TokenType.Number, (3L, 12L), (3L, 15L))
(TokenType.Symbol, (3L, 15L), (3L, 16L))
(TokenType.Number, (4L, 2L), (4L, 3L))
(TokenType.Symbol, (4L, 3L), (4L, 4L)) ]


("""module MyModule1 =
module MyModule2 =
module MyModule3 =
1L"""
|> tokenize) = [ (TokenType.Keyword, (0L, 0L), (0L, 6L))
(TokenType.ModuleName, (0L, 7L), (0L, 16L))
(TokenType.Keyword, (1L, 2L), (1L, 8L))
(TokenType.ModuleName, (1L, 9L), (1L, 18L))
(TokenType.Keyword, (2L, 4L), (2L, 10L))
(TokenType.ModuleName, (2L, 11L), (2L, 20L))
(TokenType.Number, (3L, 6L), (3L, 7L))
(TokenType.Symbol, (3L, 7L), (3L, 8L)) ]
// module TokenizeModuleDeclaration =
// ("module MyModule =\n type ID = Int64" |> tokenize) = [ (TokenType.Keyword,
// (0L, 0L),
// (0L, 6L))
// (TokenType.ModuleName,
// (0L, 7L),
// (0L, 15L))
// (TokenType.Keyword,
// (1L, 2L),
// (1L, 6L))
// (TokenType.TypeName,
// (1L, 7L),
// (1L, 9L))
// (TokenType.Symbol,
// (1L, 10L),
// (1L, 11L))
// (TokenType.TypeName,
// (1L, 12L),
// (1L, 17L)) ]

// ("""module MyModule =
// type ID = Int64
// let myFn (i: Int64): Int64 = 1L
// const x = 100L
// 1L"""
// |> tokenize) = [ (TokenType.Keyword, (0L, 0L), (0L, 6L))
// (TokenType.ModuleName, (0L, 7L), (0L, 15L))
// (TokenType.Keyword, (1L, 2L), (1L, 6L))
// (TokenType.TypeName, (1L, 7L), (1L, 9L))
// (TokenType.Symbol, (1L, 10L), (1L, 11L))
// (TokenType.TypeName, (1L, 12L), (1L, 17L))
// (TokenType.Keyword, (2L, 2L), (2L, 5L))
// (TokenType.FunctionName, (2L, 6L), (2L, 10L))
// (TokenType.Symbol, (2L, 11L), (2L, 12L))
// (TokenType.ParameterName, (2L, 12L), (2L, 13L))
// (TokenType.Symbol, (2L, 13L), (2L, 14L))
// (TokenType.TypeName, (2L, 15L), (2L, 20L))
// (TokenType.Symbol, (2L, 20L), (2L, 21L))
// (TokenType.Symbol, (2L, 21L), (2L, 22L))
// (TokenType.TypeName, (2L, 23L), (2L, 28L))
// (TokenType.Symbol, (2L, 29L), (2L, 30L))
// (TokenType.Number, (2L, 31L), (2L, 32L))
// (TokenType.Symbol, (2L, 32L), (2L, 33L))
// (TokenType.Keyword, (3L, 2L), (3L, 7L))
// (TokenType.VariableName, (3L, 8L), (3L, 9L))
// (TokenType.Symbol, (3L, 10L), (3L, 11L))
// (TokenType.Number, (3L, 12L), (3L, 15L))
// (TokenType.Symbol, (3L, 15L), (3L, 16L))
// (TokenType.Number, (4L, 2L), (4L, 3L))
// (TokenType.Symbol, (4L, 3L), (4L, 4L)) ]


// ("""module MyModule1 =
// module MyModule2 =
// module MyModule3 =
// 1L"""
// |> tokenize) = [ (TokenType.Keyword, (0L, 0L), (0L, 6L))
// (TokenType.ModuleName, (0L, 7L), (0L, 16L))
// (TokenType.Keyword, (1L, 2L), (1L, 8L))
// (TokenType.ModuleName, (1L, 9L), (1L, 18L))
// (TokenType.Keyword, (2L, 4L), (2L, 10L))
// (TokenType.ModuleName, (2L, 11L), (2L, 20L))
// (TokenType.Number, (3L, 6L), (3L, 7L))
// (TokenType.Symbol, (3L, 7L), (3L, 8L)) ]
41 changes: 28 additions & 13 deletions backend/tests/Tests/NewParser.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,26 +1656,40 @@ let moduleDeclarations =
t
"module with types, fns, and consts"
"""module MyModule =
type ID = Int64
type MyString = String
let myFn (i: Int64): Int64 = 1L
const x = 100L"""
type ID = Int64
type MyString = String
let myFn (i: Int64): Int64 = 1L
const x = 100L"""
"module MyModule =\n type ID =\n Int64\n\n type MyString =\n String\n\n let myFn (i: Int64): Int64 =\n 1L\n\n const x = 100L"
[]
[]
[]
false

t
"module with types, fns, consts, and exprs"
"""module MyModule =
type ID = Int64
type MyString = String
let myFn (i: Int64): Int64 = 1L
const x = 100L
1L"""
"module MyModule =\n type ID =\n Int64\n\n type MyString =\n String\n\n let myFn (i: Int64): Int64 =\n 1L\n\n const x = 100L\n\n 1L"
[]
[]
[]
false

t
"module with types, fns, conts, and newlines"
"""module MyModule =
type ID = Int64
type ID = Int64

type MyString = String
type MyString = String

let myFn (i: Int64): Int64 = 1L
let myFn (i: Int64): Int64 = 1L

const x = 100L"""
const x = 100L"""
"module MyModule =\n type ID =\n Int64\n\n type MyString =\n String\n\n let myFn (i: Int64): Int64 =\n 1L\n\n const x = 100L"
[]
[]
Expand All @@ -1685,11 +1699,11 @@ let moduleDeclarations =
t
"nested module declaration"
"""module MyModule1 =
type ID = Int64
type ID1 = Int64
module MyModule2 =
type ID = Int64
type ID2 = Int64
module MyModule3 =
type ID = Int64
type ID3 = Int64
const x = 100L
1L"""
"module MyModule1 =\n type ID =\n Int64\n\n module MyModule2 =\n type ID =\n Int64\n\n module MyModule3 =\n type ID =\n Int64\n\n const x = 100L\n\n 1L"
Expand Down Expand Up @@ -1741,5 +1755,6 @@ let tests =
constantDeclarations
exprs
functionDeclarations
moduleDeclarations
sourceFiles ]
// moduleDeclarations
// sourceFiles
]
16 changes: 12 additions & 4 deletions packages/darklang/languageTools/parser/moduleDeclaration.dark
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ module Darklang =
| "type_decl" ->
(TypeDeclaration.parse node)
|> Stdlib.Result.map (fun x ->
WrittenTypes.ModuleDeclaration.Declaration.Type x)
WrittenTypes.ModuleDeclaration.Declaration.SourceFileDeclaration(
WrittenTypes.SourceFile.SourceFileDeclaration.Type x
))
| "fn_decl" ->
(FunctionDeclaration.parse node)
|> Stdlib.Result.map (fun x ->
WrittenTypes.ModuleDeclaration.Declaration.Function x)
WrittenTypes.ModuleDeclaration.Declaration.SourceFileDeclaration(
WrittenTypes.SourceFile.SourceFileDeclaration.Function x
))
| "const_decl" ->
(ConstantDeclaration.parse node)
|> Stdlib.Result.map (fun x ->
WrittenTypes.ModuleDeclaration.Declaration.Constant x)
WrittenTypes.ModuleDeclaration.Declaration.SourceFileDeclaration(
WrittenTypes.SourceFile.SourceFileDeclaration.Constant x
))
| "module_decl" ->
(ModuleDeclaration.parse node)
|> Stdlib.Result.map (fun x ->
WrittenTypes.ModuleDeclaration.Declaration.SubModule x)
WrittenTypes.ModuleDeclaration.Declaration.SourceFileDeclaration(
WrittenTypes.SourceFile.SourceFileDeclaration.Module x
))
| "expression" ->
(Expr.parse node)
|> Stdlib.Result.map (fun x ->
Expand Down
9 changes: 5 additions & 4 deletions packages/darklang/languageTools/writtenTypes.dark
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,12 @@ module Darklang =
// Module declarations
module ModuleDeclaration =
type Declaration =
| Type of TypeDeclaration.TypeDeclaration
| Function of FnDeclaration.FnDeclaration
| Constant of ConstantDeclaration.ConstantDeclaration
| SubModule of ModuleDeclaration.ModuleDeclaration
// | Type of TypeDeclaration.TypeDeclaration
// | Function of FnDeclaration.FnDeclaration
// | Constant of ConstantDeclaration.ConstantDeclaration
// | SubModule of ModuleDeclaration.ModuleDeclaration
// TODO: handle http handler and db
| SourceFileDeclaration of SourceFile.SourceFileDeclaration
| Expr of Expr

type ModuleDeclaration =
Expand Down
Loading