Simply import parsing and formatting by using header::KeywordItem

This commit is contained in:
Agus Zubiaga 2023-12-09 17:21:24 -03:00
parent 65ce811587
commit 42e755677c
No known key found for this signature in database
17 changed files with 614 additions and 406 deletions

View file

@ -15,6 +15,7 @@ Defs {
type_defs: [],
value_defs: [
ModuleImport {
before_name: [],
name: @8-12 ImportedModuleName {
package: None,
name: "Json",

View file

@ -1,7 +1,5 @@
import json.Decode
import json.Decode as JD
import json.Decode exposing [
Decoder,
map,

View file

@ -6,44 +6,43 @@ Defs {
Index(2147483651),
],
regions: [
@0-20,
@20-45,
@0-19,
@20-44,
@45-92,
@93-146,
],
space_before: [
Slice(start = 0, length = 0),
Slice(start = 0, length = 0),
Slice(start = 0, length = 0),
Slice(start = 0, length = 1),
Slice(start = 1, length = 1),
Slice(start = 2, length = 1),
],
space_after: [
Slice(start = 0, length = 0),
Slice(start = 0, length = 0),
Slice(start = 0, length = 0),
Slice(start = 1, length = 0),
Slice(start = 2, length = 0),
Slice(start = 3, length = 0),
],
spaces: [
Newline,
Newline,
Newline,
],
type_defs: [],
value_defs: [
ModuleImport {
name: @8-19 SpaceAfter(
ImportedModuleName {
package: Some(
"json",
),
name: "Decode",
},
[
Newline,
],
),
before_name: [],
name: @8-19 ImportedModuleName {
package: Some(
"json",
),
name: "Decode",
},
alias: None,
exposed: None,
},
ModuleImport {
before_name: [],
name: @27-38 ImportedModuleName {
package: Some(
"json",
@ -51,18 +50,21 @@ Defs {
name: "Decode",
},
alias: Some(
@42-44 SpaceAfter(
ImportAlias(
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @42-44 ImportAlias(
"JD",
),
[
Newline,
],
),
},
),
exposed: None,
},
ModuleImport {
before_name: [],
name: @52-63 ImportedModuleName {
package: Some(
"json",
@ -71,9 +73,13 @@ Defs {
},
alias: None,
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@74-81 ExposedName(
"Decoder",
),
@ -86,10 +92,11 @@ Defs {
],
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @100-111 ImportedModuleName {
package: Some(
"json",
@ -97,14 +104,25 @@ Defs {
name: "Decode",
},
alias: Some(
@115-117 ImportAlias(
"JD",
),
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @115-117 ImportAlias(
"JD",
),
},
),
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@128-135 ExposedName(
"Decoder",
),
@ -117,7 +135,7 @@ Defs {
],
),
],
),
},
),
},
],

View file

@ -1,3 +1,2 @@
import JsonEncode as JE
import BytesDecode as BD

View file

@ -4,46 +4,59 @@ Defs {
Index(2147483649),
],
regions: [
@0-24,
@0-23,
@24-49,
],
space_before: [
Slice(start = 0, length = 0),
Slice(start = 0, length = 0),
Slice(start = 0, length = 1),
],
space_after: [
Slice(start = 0, length = 0),
Slice(start = 0, length = 0),
Slice(start = 1, length = 0),
],
spaces: [
Newline,
],
spaces: [],
type_defs: [],
value_defs: [
ModuleImport {
before_name: [],
name: @7-17 ImportedModuleName {
package: None,
name: "JsonEncode",
},
alias: Some(
@21-23 SpaceAfter(
ImportAlias(
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @21-23 ImportAlias(
"JE",
),
[
Newline,
],
),
},
),
exposed: None,
},
ModuleImport {
before_name: [],
name: @31-42 ImportedModuleName {
package: None,
name: "BytesDecode",
},
alias: Some(
@47-49 ImportAlias(
"BD",
),
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @47-49 ImportAlias(
"BD",
),
},
),
exposed: None,
},

View file

@ -6,22 +6,17 @@ import Json
# comment
as J exposing [map]
import Json
as
# comment
J
import Json as
# comment
J
import Json
as
# comment
J
exposing [map]
import Json as
# comment
J exposing [map]
import Json
as
# comment
J
exposing [
import Json as
# comment
J exposing [
map,
map2,
]
@ -37,15 +32,13 @@ import Json as J
# comment
exposing [map]
import Json
exposing
# comment
[map]
import Json exposing
# comment
[map]
import Json as J
exposing
# comment
[map]
import Json as J exposing
# comment
[map]
import Json as J exposing [
# comment
@ -57,12 +50,16 @@ import
Json
# comment 2
as
# comment 3
J
# comment 3
J
# comment 4
exposing
# comment 5
[
# comment 6
map,
]
# comment 5
[
# comment 6
map,
]
import A
# comment between imports
import B

View file

@ -11,11 +11,13 @@ Defs {
Index(2147483656),
Index(2147483657),
Index(2147483658),
Index(2147483659),
Index(2147483660),
],
regions: [
@0-49,
@51-100,
@102-138,
@102-136,
@138-187,
@189-252,
@254-312,
@ -24,12 +26,13 @@ Defs {
@411-460,
@462-513,
@515-672,
@675-683,
@710-718,
],
space_before: [
Slice(start = 0, length = 0),
Slice(start = 0, length = 2),
Slice(start = 2, length = 2),
Slice(start = 4, length = 0),
Slice(start = 4, length = 2),
Slice(start = 6, length = 2),
Slice(start = 8, length = 2),
@ -37,12 +40,14 @@ Defs {
Slice(start = 12, length = 2),
Slice(start = 14, length = 2),
Slice(start = 16, length = 2),
Slice(start = 18, length = 2),
Slice(start = 20, length = 3),
Slice(start = 23, length = 2),
],
space_after: [
Slice(start = 0, length = 0),
Slice(start = 2, length = 0),
Slice(start = 4, length = 0),
Slice(start = 4, length = 0),
Slice(start = 6, length = 0),
Slice(start = 8, length = 0),
Slice(start = 10, length = 0),
@ -50,6 +55,9 @@ Defs {
Slice(start = 14, length = 0),
Slice(start = 16, length = 0),
Slice(start = 18, length = 0),
Slice(start = 20, length = 0),
Slice(start = 23, length = 0),
Slice(start = 25, length = 0),
],
spaces: [
Newline,
@ -70,144 +78,188 @@ Defs {
Newline,
Newline,
Newline,
Newline,
Newline,
Newline,
Newline,
Newline,
Newline,
LineComment(
" comment between imports",
),
],
type_defs: [],
value_defs: [
ModuleImport {
name: @25-29 SpaceBefore(
ImportedModuleName {
package: None,
name: "Json",
},
[
Newline,
LineComment(
" comment",
),
],
),
alias: Some(
@33-34 ImportAlias(
"J",
before_name: [
Newline,
LineComment(
" comment",
),
],
name: @25-29 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @33-34 ImportAlias(
"J",
),
},
),
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@45-48 ExposedName(
"map",
),
],
),
},
),
},
ModuleImport {
name: @58-62 SpaceAfter(
ImportedModuleName {
package: None,
name: "Json",
},
[
Newline,
LineComment(
" comment",
),
],
),
before_name: [],
name: @58-62 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
@84-85 ImportAlias(
"J",
),
KeywordItem {
keyword: Spaces {
before: [
Newline,
LineComment(
" comment",
),
],
item: ImportAsKeyword,
after: [],
},
item: @84-85 ImportAlias(
"J",
),
},
),
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@96-99 ExposedName(
"map",
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @109-113 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
@135-136 SpaceBefore(
SpaceAfter(
ImportAlias(
"J",
),
[
Newline,
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [
Newline,
LineComment(
" comment",
),
],
},
item: @135-136 ImportAlias(
"J",
),
[
Newline,
LineComment(
" comment",
),
],
),
},
),
exposed: None,
},
ModuleImport {
before_name: [],
name: @145-149 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
@171-172 SpaceBefore(
ImportAlias(
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [
Newline,
LineComment(
" comment",
),
],
},
item: @171-172 ImportAlias(
"J",
),
[
Newline,
LineComment(
" comment",
),
],
),
},
),
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@183-186 ExposedName(
"map",
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @196-200 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
@222-223 SpaceBefore(
ImportAlias(
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [
Newline,
LineComment(
" comment",
),
],
},
item: @222-223 ImportAlias(
"J",
),
[
Newline,
LineComment(
" comment",
),
],
),
},
),
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@234-237 ExposedName(
"map",
),
@ -220,27 +272,29 @@ Defs {
],
),
],
),
},
),
},
ModuleImport {
name: @261-265 SpaceAfter(
ImportedModuleName {
package: None,
name: "Json",
},
[
Newline,
LineComment(
" comment",
),
],
),
before_name: [],
name: @261-265 ImportedModuleName {
package: None,
name: "Json",
},
alias: None,
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [
Newline,
LineComment(
" comment",
),
],
item: ImportExposingKeyword,
after: [],
},
item: [
@294-297 ExposedName(
"map",
),
@ -253,100 +307,138 @@ Defs {
],
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @321-325 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
@329-330 SpaceAfter(
ImportAlias(
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @329-330 ImportAlias(
"J",
),
[
Newline,
LineComment(
" comment",
),
],
),
},
),
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [
Newline,
LineComment(
" comment",
),
],
item: ImportExposingKeyword,
after: [],
},
item: [
@359-362 ExposedName(
"map",
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @372-376 ImportedModuleName {
package: None,
name: "Json",
},
alias: None,
exposed: Some(
(
[
Newline,
LineComment(
" comment",
),
],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [
Newline,
LineComment(
" comment",
),
],
},
item: [
@405-408 ExposedName(
"map",
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @418-422 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
@426-427 ImportAlias(
"J",
),
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @426-427 ImportAlias(
"J",
),
},
),
exposed: Some(
(
[
Newline,
LineComment(
" comment",
),
],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [
Newline,
LineComment(
" comment",
),
],
},
item: [
@456-459 ExposedName(
"map",
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @469-473 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
@477-478 ImportAlias(
"J",
),
KeywordItem {
keyword: Spaces {
before: [],
item: ImportAsKeyword,
after: [],
},
item: @477-478 ImportAlias(
"J",
),
},
),
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@508-511 SpaceBefore(
SpaceAfter(
ExposedName(
@ -364,60 +456,60 @@ Defs {
],
),
],
),
},
),
},
ModuleImport {
name: @542-546 SpaceBefore(
SpaceAfter(
ImportedModuleName {
package: None,
name: "Json",
},
[
Newline,
LineComment(
" comment 2",
),
],
before_name: [
Newline,
LineComment(
" comment 1",
),
[
Newline,
LineComment(
" comment 1",
),
],
),
],
name: @542-546 ImportedModuleName {
package: None,
name: "Json",
},
alias: Some(
@590-591 SpaceBefore(
SpaceAfter(
ImportAlias(
"J",
),
[
KeywordItem {
keyword: Spaces {
before: [
Newline,
LineComment(
" comment 2",
),
],
item: ImportAsKeyword,
after: [
Newline,
LineComment(
" comment 3",
),
],
},
item: @590-591 ImportAlias(
"J",
),
},
),
exposed: Some(
KeywordItem {
keyword: Spaces {
before: [
Newline,
LineComment(
" comment 4",
),
],
),
[
Newline,
LineComment(
" comment 3",
),
],
),
),
exposed: Some(
(
[
Newline,
LineComment(
" comment 5",
),
],
[
item: ImportExposingKeyword,
after: [
Newline,
LineComment(
" comment 5",
),
],
},
item: [
@663-666 SpaceBefore(
SpaceAfter(
ExposedName(
@ -435,8 +527,26 @@ Defs {
],
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @682-683 ImportedModuleName {
package: None,
name: "A",
},
alias: None,
exposed: None,
},
ModuleImport {
before_name: [],
name: @717-718 ImportedModuleName {
package: None,
name: "B",
},
alias: None,
exposed: None,
},
],
}

View file

@ -55,3 +55,8 @@ import
# comment 6
map
]
import A
# comment between imports
import B

View file

@ -26,15 +26,20 @@ Defs {
type_defs: [],
value_defs: [
ModuleImport {
before_name: [],
name: @7-11 ImportedModuleName {
package: None,
name: "Json",
},
alias: None,
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@22-25 ExposedName(
"map",
),
@ -42,19 +47,24 @@ Defs {
"Decoder",
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @43-47 ImportedModuleName {
package: None,
name: "Json",
},
alias: None,
exposed: Some(
(
[],
[
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [
@58-61 ExposedName(
"map",
),
@ -67,20 +77,25 @@ Defs {
],
),
],
),
},
),
},
ModuleImport {
before_name: [],
name: @83-87 ImportedModuleName {
package: None,
name: "Json",
},
alias: None,
exposed: Some(
(
[],
[],
),
KeywordItem {
keyword: Spaces {
before: [],
item: ImportExposingKeyword,
after: [],
},
item: [],
},
),
},
],