Skip to content

Commit 981ce9a

Browse files
committed
little refactoring
1 parent 3a6dc5d commit 981ce9a

File tree

17 files changed

+104
-104
lines changed

17 files changed

+104
-104
lines changed

.github/workflows/examples.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
os:
4040
- ubuntu-latest
4141
nim_version:
42-
- '2.0.0'
42+
- '2.0.4'
4343
env:
4444
TIMEOUT_EXIT_STATUS: 124
4545
steps:

.github/workflows/gh-pages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
runs-on: windows-latest
3131
needs: before
3232
env:
33-
nim_version: '2.0.0'
33+
nim_version: '2.0.4'
3434
node_version: '20'
3535
steps:
3636
- uses: actions/checkout@v4

.github/workflows/language_bindings.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
os:
2828
- ubuntu-latest
2929
nim_version:
30-
- '2.0.0'
30+
- '2.0.4'
3131
env:
3232
TIMEOUT_EXIT_STATUS: 124
3333
steps:
@@ -109,7 +109,7 @@ jobs:
109109
os:
110110
- ubuntu-latest
111111
nim_version:
112-
- '2.0.0'
112+
- '2.0.4'
113113
java_version:
114114
- '16'
115115
gradle_version:

.github/workflows/tests.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ jobs:
4141
- ubuntu-latest
4242
nim_version:
4343
- '2.0.0'
44+
- '2.0.4'
4445
env:
4546
TIMEOUT_EXIT_STATUS: 124
4647
steps:
@@ -94,8 +95,6 @@ jobs:
9495
matrix:
9596
os:
9697
- ubuntu-latest
97-
nim_version:
98-
- '2.0.0'
9998
env:
10099
TIMEOUT_EXIT_STATUS: 124
101100
steps:
@@ -122,8 +121,6 @@ jobs:
122121
matrix:
123122
os:
124123
- ubuntu-latest
125-
nim_version:
126-
- '2.0.0'
127124
env:
128125
TIMEOUT_EXIT_STATUS: 124
129126
steps:
@@ -150,8 +147,6 @@ jobs:
150147
matrix:
151148
os:
152149
- ubuntu-latest
153-
nim_version:
154-
- '2.0.0'
155150
env:
156151
TIMEOUT_EXIT_STATUS: 124
157152
steps:
@@ -178,8 +173,6 @@ jobs:
178173
matrix:
179174
os:
180175
- ubuntu-latest
181-
nim_version:
182-
- '2.0.0'
183176
env:
184177
TIMEOUT_EXIT_STATUS: 124
185178
steps:

src/happyx/core/constants.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const
9696
nim_2_0_0* = (NimMajor, NimMinor, NimPatch) >= (2, 0, 0)
9797
# Framework version
9898
HpxMajor* = 3
99-
HpxMinor* = 9
99+
HpxMinor* = 10
100100
HpxPatch* = 0
101101
HpxVersion* = $HpxMajor & "." & $HpxMinor & "." & $HpxPatch
102102

src/happyx/core/queries.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ macro `?`*(strTable: StringTableRef | TableRef[string, seq[string]], key: untype
6565
## echo query?myParam
6666
##
6767
let
68-
keyStr = newStrLitNode($key)
68+
keyStr = newLit($key)
6969
newCall("getOrDefault", strTable, keyStr)

src/happyx/private/macro_utils.nim

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ proc useComponent*(statement: NimNode, inCycle, inComponent: bool,
304304
newCall(
305305
"addArgIter",
306306
ident(componentData),
307-
newCall("&", newStrLitNode"data-", newDotExpr(ident(componentName), ident(UniqueComponentId)))
307+
newCall("&", newLit"data-", newDotExpr(ident(componentName), ident(UniqueComponentId)))
308308
)
309309
else:
310310
newEmptyNode(),
@@ -313,15 +313,15 @@ proc useComponent*(statement: NimNode, inCycle, inComponent: bool,
313313
newStmtList(
314314
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
315315
ident"emit",
316-
newStrLitNode(fmt"window.addEventListener('beforeunload', `{componentData}`.`exited`);")
316+
newLit(fmt"window.addEventListener('beforeunload', `{componentData}`.`exited`);")
317317
)),
318318
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
319319
ident"emit",
320-
newStrLitNode(fmt"window.addEventListener('pagehide', `{componentData}`.`pageHide`);")
320+
newLit(fmt"window.addEventListener('pagehide', `{componentData}`.`pageHide`);")
321321
)),
322322
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
323323
ident"emit",
324-
newStrLitNode(fmt"window.addEventListener('pageshow', `{componentData}`.`pageShow`);")
324+
newLit(fmt"window.addEventListener('pageshow', `{componentData}`.`pageShow`);")
325325
)),
326326
)
327327
else:
@@ -421,7 +421,7 @@ proc attribute*(attr: NimNode, inComponent: bool = false): NimNode =
421421
else:
422422
attr[1]
423423
newColonExpr(
424-
newStrLitNode(k),
424+
newLit(k),
425425
formatNode(v)
426426
)
427427

@@ -446,13 +446,13 @@ proc addAttribute*(node, key, value: NimNode, inComponent: bool = false) =
446446
value
447447
if node.len == 2:
448448
node.add(newCall("newStringTable", newNimNode(nnkTableConstr).add(
449-
newColonExpr(newStrLitNode(k), v)
449+
newColonExpr(newLit(k), v)
450450
)))
451451
elif node[2].kind == nnkCall and node[2][0] == ident"newStringTable":
452-
node[2][1].add(newColonExpr(newStrLitNode(k), v))
452+
node[2][1].add(newColonExpr(newLit(k), v))
453453
else:
454454
node.insert(2, newCall("newStringTable", newNimNode(nnkTableConstr).add(
455-
newColonExpr(newStrLitNode(k), v)
455+
newColonExpr(newLit(k), v)
456456
)))
457457

458458

@@ -572,7 +572,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
572572
# Real Nim code
573573
result.add(newStmtList(
574574
statement[1],
575-
newCall("initTag", newStrLitNode"div", newCall("@", newNimNode(nnkBracket)), newLit(true))
575+
newCall("initTag", newLit"div", newCall("@", newNimNode(nnkBracket)), newLit(true))
576576
))
577577

578578
elif statement.kind == nnkCall and statement[0] == ident"rawHtml":
@@ -689,21 +689,21 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
689689
newCall(
690690
"addArgIter",
691691
ident(componentData),
692-
newCall("&", newStrLitNode"data-", newDotExpr(compName, ident(UniqueComponentId)))
692+
newCall("&", newLit"data-", newDotExpr(compName, ident(UniqueComponentId)))
693693
),
694694
when defined(js):
695695
newStmtList(
696696
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
697697
ident"emit",
698-
newStrLitNode(fmt"window.addEventListener('beforeunload', `{componentData}`.`exited`);")
698+
newLit(fmt"window.addEventListener('beforeunload', `{componentData}`.`exited`);")
699699
)),
700700
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
701701
ident"emit",
702-
newStrLitNode(fmt"window.addEventListener('pagehide', `{componentData}`.`pageHide`);")
702+
newLit(fmt"window.addEventListener('pagehide', `{componentData}`.`pageHide`);")
703703
)),
704704
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
705705
ident"emit",
706-
newStrLitNode(fmt"window.addEventListener('pageshow', `{componentData}`.`pageShow`);")
706+
newLit(fmt"window.addEventListener('pageshow', `{componentData}`.`pageShow`);")
707707
)),
708708
)
709709
else:
@@ -741,21 +741,21 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
741741
newCall(
742742
"addArgIter",
743743
ident(componentData),
744-
newCall("&", newStrLitNode"data-", newDotExpr(statement[1], ident(UniqueComponentId)))
744+
newCall("&", newLit"data-", newDotExpr(statement[1], ident(UniqueComponentId)))
745745
),
746746
when defined(js):
747747
newStmtList(
748748
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
749749
ident"emit",
750-
newStrLitNode(fmt"window.addEventListener('beforeunload', `{componentData}`.`exited`);")
750+
newLit(fmt"window.addEventListener('beforeunload', `{componentData}`.`exited`);")
751751
)),
752752
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
753753
ident"emit",
754-
newStrLitNode(fmt"window.addEventListener('pagehide', `{componentData}`.`pageHide`);")
754+
newLit(fmt"window.addEventListener('pagehide', `{componentData}`.`pageHide`);")
755755
)),
756756
newNimNode(nnkPragma).add(newNimNode(nnkExprColonExpr).add(
757757
ident"emit",
758-
newStrLitNode(fmt"window.addEventListener('pageshow', `{componentData}`.`pageShow`);")
758+
newLit(fmt"window.addEventListener('pageshow', `{componentData}`.`pageShow`);")
759759
)),
760760
)
761761
else:
@@ -874,7 +874,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
874874
newLit(evname),
875875
newCall(
876876
"fmt",
877-
newStrLitNode(
877+
newLit(
878878
"callComponentEventHandler('{self." & UniqueComponentId & "}', {-(" &
879879
fmt"{uniqueId.value}" & cycleVar & ", event)"
880880
)
@@ -886,7 +886,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
886886
newCall(
887887
"[]=",
888888
ident"componentEventHandlers",
889-
newCall("-", newCall("+", newIntLitNode(uniqueId.value), ident(cycleTmpVar))),
889+
newCall("-", newCall("+", newLit(uniqueId.value), ident(cycleTmpVar))),
890890
callRegister
891891
),
892892
newCall("inc", ident(cycleTmpVar)),
@@ -906,10 +906,10 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
906906
)
907907
result.add(newStmtList(
908908
newCall("once",
909-
newCall("[]=", ident"componentEventHandlers", newIntLitNode(uniqueId.value), procedure)
909+
newCall("[]=", ident"componentEventHandlers", newLit(uniqueId.value), procedure)
910910
), newCall("initTag", newLit"div", newCall("@", newNimNode(nnkBracket)), newLit(true))
911911
))
912-
procedure.body.insert(0, newAssignment(ident"currentComponent", newCall("fmt", newStrLitNode"{self.uniqCompId}")))
912+
procedure.body.insert(0, newAssignment(ident"currentComponent", newCall("fmt", newLit"{self.uniqCompId}")))
913913
procedure.body.add(newAssignment(ident"currentComponent", newLit""))
914914
else:
915915
procedure.body = statement[^1]
@@ -924,7 +924,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
924924
procParams.add(newIdentDefs(i, ident"any"))
925925
callRegister.add(i)
926926
result.addAttribute(
927-
newStrLitNode(evname),
927+
newLit(evname),
928928
newCall(
929929
"fmt",
930930
newLit("callEventHandler({-(" & fmt"{uniqueId.value}" & cycleVar & ", event)")
@@ -951,7 +951,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
951951
)
952952
result.add(newStmtList(
953953
newCall("once",
954-
newCall("[]=", ident"eventHandlers", newIntLitNode(uniqueId.value), procedure)
954+
newCall("[]=", ident"eventHandlers", newLit(uniqueId.value), procedure)
955955
), newCall("initTag", newLit"div", newCall("@", newNimNode(nnkBracket)), newLit(true))
956956
))
957957
inc uniqueId

src/happyx/routing/mounting.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ proc findAndReplaceMount*(body: NimNode) =
5959
# Replace routes
6060
if statement.kind in [nnkCall, nnkCommand]:
6161
if statement[0].kind in [nnkStrLit, nnkTripleStrLit]:
62-
statement[0] = newStrLitNode($route & $statement[0])
62+
statement[0] = newLit($route & $statement[0])
6363
elif statement[1].kind in [nnkStrLit, nnkTripleStrLit]:
64-
statement[1] = newStrLitNode($route & $statement[1])
64+
statement[1] = newLit($route & $statement[1])
6565
# Add mount routes
6666
if (statement.kind in [nnkCall, nnkCommand] and $statement[0] != "mount") or
6767
(statement.kind == nnkPrefix and $statement[0] == "@"):

src/happyx/routing/routing.nim

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ when exportPython:
7070
if re2"^[a-zA-Z][a-zA-Z0-9_]*$" notin name:
7171
raise newException(
7272
ValueError,
73-
fmt"route param type name should be identifier (a-zA-Z0-0_), but got '{name}'"
73+
fmt"route param type name should be identifier (a-zA-Z0-9_), but got '{name}'"
7474
)
7575
registeredRouteParamTypes[name] = RouteParamType(
7676
pattern: pattern, name: name, creator: creator
@@ -104,7 +104,7 @@ elif defined(napibuild):
104104
if re2"^[a-zA-Z][a-zA-Z0-9_]*$" notin name:
105105
raise newException(
106106
ValueError,
107-
fmt"route param type name should be identifier (a-zA-Z0-0_), but got '{name}'"
107+
fmt"route param type name should be identifier (a-zA-Z0-9_), but got '{name}'"
108108
)
109109
registeredRouteParamTypes[name] = RouteParamType(
110110
pattern: pattern, name: name, creator: creator
@@ -125,7 +125,7 @@ elif exportJvm:
125125
if re2"^[a-zA-Z][a-zA-Z0-9_]*$" notin name:
126126
raise newException(
127127
ValueError,
128-
fmt"route param type name should be identifier (a-zA-Z0-0_), but got '{name}'"
128+
fmt"route param type name should be identifier (a-zA-Z0-9_), but got '{name}'"
129129
)
130130
registeredRouteParamTypes[name] = RouteParamType(
131131
pattern: pattern, name: name, creator: creator
@@ -137,7 +137,7 @@ else:
137137
if re2"^[a-zA-Z][a-zA-Z0-9_]*$" notin $name:
138138
raise newException(
139139
ValueError,
140-
fmt"route param type name should be identifier (a-zA-Z0-0_), but got '{name}'"
140+
fmt"route param type name should be identifier (a-zA-Z0-9_), but got '{name}'"
141141
)
142142
registeredRouteParamTypes[$name] = newStmtList(name, pattern, creator)
143143
@@ -152,22 +152,29 @@ proc newRequestModelObj*(name, typeName, target: string, mutable: bool): Request
152152
153153
proc handleRoute*(route: string): RouteDataObj =
154154
## Handles route and receive route data object.
155+
##
156+
## ## Examples
157+
##
158+
## dollar full: `$argument?:word[m]=hello`
159+
## curvy full: `{argument?:word[m]=hello}`
160+
## model full: `[argument:ModelName:json]`
161+
##
155162
result = RouteDataObj(path: "", purePath: "", pathParams: @[], requestModels: @[])
156163
let
157-
dollarToCurve = re2"\$([^:\/\{\}]+)(:enum\(\w+\)|:\w+|:\/[^\/]+\/)?(\[m\])?(=[^\/\{\}]+)?(m)?"
164+
dollarToCurvy = re2"\$([^:\/\{\}]+)(:enum\(\w+\)|:\w+|:\/[^\/]+\/)?(\[m\])?(=[^\/\{\}]+)?(m)?"
158165
defaultWithoutQuestion = re2"\{([^:\/\{\}\?]+)(:enum\(\w+\)|:\w+|:\/[^\/]+\/)?(\[m\])?(=[^\}]+)\}"
159-
160166
var path = route
161167
var m: RegexMatch2
162-
if path.find(dollarToCurve, m):
168+
if path.find(dollarToCurvy, m):
163169
if path[m.group(1)] == ":path":
164170
raise newException(ValueError, "path params doesn't support aliases")
165171
elif path[m.group(1)].startsWith(":/"):
166172
raise newException(ValueError, "regex params doesn't support aliases")
167-
path = path.replace(dollarToCurve, "{$1$2$3$4}")
173+
path = path.replace(dollarToCurvy, "{$1$2$3$4}")
168174
path = path.replace(defaultWithoutQuestion, "{$1?$2$3$4}")
169175
result.path = path
170176
var routePathStr = path
177+
# Here we replace TYPENAME to regex pattern
171178
# boolean param
172179
routePathStr = routePathStr.replace(re2"\{[a-zA-Z][a-zA-Z0-9_]*(\??):bool(\[m\])?(=\S+?)?\}", "(n|y|no|yes|true|false|1|0|on|off)$1")
173180
# integer param
@@ -224,7 +231,7 @@ proc handleRoute*(route: string): RouteDataObj =
224231
path.findAll(
225232
re2"\[([a-zA-Z][a-zA-Z0-9_]*):([a-zA-Z][a-zA-Z0-9_]*)(\[m\])?(:[a-zA-Z\\-]+)?\]"
226233
)
227-
234+
228235
result.purePath = routePathStr
229236

230237
for pathParam in foundPathParams:
@@ -298,7 +305,7 @@ proc exportRouteArgs*(urlPath, routePath, body: NimNode): NimNode =
298305
hasChildren = false
299306
let
300307
elifBranch = newNimNode(nnkElifBranch)
301-
regExp = newCall("re2", newStrLitNode("^" & routeData.purePath & "$"))
308+
regExp = newCall("re2", newLit("^" & routeData.purePath & "$"))
302309
elifBranch.add(newCall("contains", urlPath, newStmtList(
303310
newLetStmt(ident"__regExp", regExp),
304311
ident"__regExp"
@@ -338,9 +345,9 @@ proc exportRouteArgs*(urlPath, routePath, body: NimNode): NimNode =
338345
foundGroup = newCall("decodeUrl", newNimNode(nnkBracketExpr).add(urlPath, group))
339346
foundGroupForce = newCall("decodeUrl", newNimNode(nnkBracketExpr).add(urlPath, groupForce))
340347
# _groupLen < 1
341-
conditionOptional = newCall("<", newCall("len", group), newIntLitNode(1))
348+
conditionOptional = newCall("<", newCall("len", group), newLit(1))
342349
# _foundGroupLen == 0
343-
conditionSecondOptional = newCall("==", newCall("len", foundGroup), newIntLitNode(0))
350+
conditionSecondOptional = newCall("==", newCall("len", foundGroup), newLit(0))
344351

345352
if i.optional:
346353
case i.paramType:
@@ -510,7 +517,7 @@ proc exportRouteArgs*(urlPath, routePath, body: NimNode): NimNode =
510517
ident"JsonParsingError",
511518
newStmtList(
512519
when enableDebug:
513-
newCall("echo", newCall("fmt", newStrLitNode"json parse error: {getCurrentExceptionMsg()}"))
520+
newCall("echo", newCall("fmt", newLit"json parse error: {getCurrentExceptionMsg()}"))
514521
else:
515522
newEmptyNode(),
516523
newCall(
@@ -526,7 +533,7 @@ proc exportRouteArgs*(urlPath, routePath, body: NimNode): NimNode =
526533
ident"JsonKindError",
527534
newStmtList(
528535
when enableDebug:
529-
newCall("echo", newCall("fmt", newStrLitNode"json kind error: {getCurrentExceptionMsg()}"))
536+
newCall("echo", newCall("fmt", newLit"json kind error: {getCurrentExceptionMsg()}"))
530537
else:
531538
newEmptyNode(),
532539
newCall(

0 commit comments

Comments
 (0)