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

Make the DSL interpret sym nodes as ident nodes #671

Merged
merged 1 commit into from
Nov 10, 2024
Merged
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
17 changes: 13 additions & 4 deletions src/arraymancer/nn/nn_dsl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import
macros

const IdentLike = {nnkIdent, nnkSym, nnkOpenSymChoice}

type
SectionInfo = object
Expand Down Expand Up @@ -63,17 +64,25 @@ proc createLayerInfo(sectionInfo: SectionInfo): seq[LayerInfo] =

if layer.kind != nnkCall or
layer.len != 2 or
layer[0].kind != nnkIdent or
layer[0].kind notin IdentLike or
layer[1].kind != nnkStmtList or
layer[1].len != 1 or
layer[1][0].kind != nnkCall or
layer[1][0].len < 1 or
layer[1][0][0].kind != nnkIdent:
layer[1][0][0].kind notin IdentLike:
error("Unknown configuration of layer section: \"" & $toStrLit(layer) & "\"", layer)

let
nameNode = layer[0]
typeNameNode = layer[1][0][0]

result.add LayerInfo(
name: layer[0],
typeName: layer[1][0][0]
name:
if nameNode.kind != nnkOpenSymChoice: nameNode
else: nameNode.repr.ident(),
typeName:
if typeNameNode.kind != nnkOpenSymChoice: typeNameNode
else: typeNameNode.repr.ident(),
)
if layer[1][0].len >= 2:
result[^1].arguments = layer[1][0][1..^1]
Expand Down
Loading