Skip to content

Commit

Permalink
Parse unqualified type imports with 'type Typename' (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-mikedavis authored Oct 29, 2023
1 parent f1fa70c commit e566689
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ module.exports = grammar({
optional(seq("as", field("alias", $.identifier)))
),
seq(
optional("type"),
field("name", $.type_identifier),
optional(seq("as", field("alias", $.type_identifier)))
)
Expand Down
2 changes: 2 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

; Functions
(unqualified_import (identifier) @function)
(unqualified_import "type" (type_identifier) @type)
(unqualified_import (type_identifier) @constructor)
(function
name: (identifier) @function)
(external_function
Expand Down
22 changes: 22 additions & 0 deletions test/corpus/imports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,25 @@ import animal.{}
(import
module: (module)
imports: (unqualified_imports)))

================================================================================
Type imports
================================================================================

import a/b.{type C}
import animal.{type Cat as Kitty}

--------------------------------------------------------------------------------

(source_file
(import
module: (module)
imports: (unqualified_imports
(unqualified_import
name: (type_identifier))))
(import
module: (module)
imports: (unqualified_imports
(unqualified_import
name: (type_identifier)
alias: (type_identifier)))))
5 changes: 5 additions & 0 deletions test/highlight/modules.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import animal/cat as kitty
// ^ module
// ^ module

import animal/cat.{Cat, type Cat}
// ^ constructor
// ^ keyword
// ^ type

pub fn main() {
io.println("hello world")
// <- module
Expand Down

0 comments on commit e566689

Please sign in to comment.