Skip to content

Add Go package aliased import (#182)#197

Merged
pointlander merged 1 commit into
pointlander:mainfrom
dolmen-go:add-import-with-alias
May 21, 2026
Merged

Add Go package aliased import (#182)#197
pointlander merged 1 commit into
pointlander:mainfrom
dolmen-go:add-import-with-alias

Conversation

@dolmen
Copy link
Copy Markdown
Contributor

@dolmen dolmen commented May 21, 2026

Add aliased import of Go packages in PEG files, like in full Go:

import myfmt "fmt"

import (
    foo "foobar"
)

The implementation is a hack:

  • during parsing an import alias is stored as a fake import with an '=' prefix
  • during compile, the alias is merged with the following import as <import-path>=<alias>
  • during Go code generation (tree/peg.go.tmpl), the string is split using a function imported in the template

So import aliases are not properly represented as specific nodes in the AST tree.Tree, but that representation fits the purpose.

Closes #182.

@dolmen dolmen force-pushed the add-import-with-alias branch from 668d698 to d269519 Compare May 21, 2026 15:17
Add aliased import of Go packages, like in full Go:
    import myfmt "fmt"

The implementation is a hack:
- during parsing an import alias is stored as a fake import with an '=' prefix
- during compile, the alias is merged with the following import as <import-path>=<alias>
- during Go code generation (tree/peg.go.tmpl), the string is split

So import aliases are not properly represented in tree.Tree.

Closes pointlander#182.
@dolmen dolmen force-pushed the add-import-with-alias branch from d269519 to 371b841 Compare May 21, 2026 15:23
@pointlander pointlander merged commit dafcce5 into pointlander:main May 21, 2026
1 check passed
@dolmen dolmen deleted the add-import-with-alias branch May 22, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support named imports

2 participants