소스 검색

$(..) -> @..

Ethosa 5 년 전
부모
커밋
442fdc4be3
5개의 변경된 파일32개의 추가작업 그리고 46개의 파일을 삭제
  1. 1 1
      README.md
  2. 1 1
      akane.nimble
  3. 26 40
      akane/akane.nim
  4. 2 2
      tests/test4/templates/index.html
  5. 2 2
      tests/test6/templates/index.html

+ 1 - 1
README.md

@@ -5,7 +5,7 @@
 [![Nim language-plastic](https://github.com/Ethosa/yukiko/blob/master/nim-lang.svg)](https://github.com/Ethosa/yukiko/blob/master/nim-lang.svg)
 [![License](https://img.shields.io/github/license/Ethosa/akane)](https://github.com/Ethosa/akane/blob/master/LICENSE)
 
-<h4>Latest version - 0.0.7</h4>
+<h4>Latest version - 0.0.8</h4>
 <h4>Stable version - ?</h4>
 </div>
 

+ 1 - 1
akane.nimble

@@ -1,7 +1,7 @@
 [Package]
 name = "akane"
 author = "Ethosa"
-version = "0.0.7"
+version = "0.0.8"
 description = "The Nim asynchronous web framework."
 license = "MIT"
 srcDir = "akane"

+ 26 - 40
akane/akane.nim

@@ -80,14 +80,14 @@ proc loadtemplate*(name: string, json: JsonNode = %*{}): Future[string] {.async,
     # ---- regex patterns ---- #
     let
       # variable statement, e.g.: $(variable)
-      variable_stmt = re("(\\$\\s*\\(" & key & "\\))")
+      variable_stmt = re("(@" & key & ")")
       # if statement, e.g.: if $(variable) {......}
-      if_stmt = re("if\\s*(\\$\\s*\\(" & key & "\\))\\s*\\{\\s*([\\s\\S]+?)\\s*\\}")
+      if_stmt = re("if\\s*(@" & key & ")\\s*\\{\\s*([\\s\\S]+?)\\s*\\}")
       # if not statement, e.g.: if not $(variable) {......}
-      if_notstmt = re("if\\s*not\\s*(\\$\\s*\\(" & key & "\\))\\s*\\{\\s*([\\s\\S]+?)\\s*\\}")
+      if_notstmt = re("if\\s*not\\s*(@" & key & ")\\s*\\{\\s*([\\s\\S]+?)\\s*\\}")
       # for statement, e.g.: for i in 0..$(variable) {hello, $variable[i]}
       forstmt = re(
-        "for\\s*([\\S]+)\\s*in\\s*(\\d+)\\.\\.(\\$\\s*\\(" & key & "\\))\\s*\\{\\s*([\\s\\S]+?)\\s*\\}")
+        "for\\s*([\\S]+)\\s*in\\s*(\\d+)\\.\\.(@" & key & ")\\s*\\{\\s*([\\s\\S]+?)\\s*\\}")
     var
       matches: array[20, string]
       now = 0
@@ -129,7 +129,7 @@ proc loadtemplate*(name: string, json: JsonNode = %*{}): Future[string] {.async,
     while readed.contains(forstmt):
       let
         (start, stop) = readed.findBounds(forstmt, matches, now)
-        elem = re("(\\$" & key & "\\[" & matches[0] & "\\])")
+        elem = re("(" & key & "\\[" & matches[0] & "\\])")
       var output = ""
       for i in parseInt(matches[1])..<value.len:
         output &= matches[3].replacef(elem, await value[i].toStr)
@@ -223,10 +223,7 @@ macro pages*(server: ServerRef, body: untyped): untyped =
         ident("JsonNode"),
         newCall(
           "await",
-          newCall(
-            "parseQuery",
-            ident("request")
-          )
+          newCall("parseQuery", ident("request"))
         )
       ),
       newNimNode(nnkIdentDefs).add(  # let decode_url: string = decodeUrl(request.url.path)
@@ -257,18 +254,18 @@ macro pages*(server: ServerRef, body: untyped): untyped =
         slist.kind == nnkStmtList):
       if current == "equals":
         slist.insert(0,  # let url: string = `path`
-            newNimNode(nnkLetSection).add(
-              newNimNode(nnkIdentDefs).add(
-                ident("url"),
-                ident("string"),
-                path
-              )
+          newNimNode(nnkLetSection).add(
+            newNimNode(nnkIdentDefs).add(
+              ident("url"), ident("string"), path
             )
           )
+        )
         ifstmtlist.add(  # decoded_url == `path`
           newNimNode(nnkElifBranch).add(
             newCall("==", path, ident("decoded_url")),
-            slist))
+            slist
+          )
+        )
       elif current == "startswith":
         slist.insert(0,  # let url = decoded_url[`path`.len..^1]
           newNimNode(nnkLetSection).add(
@@ -278,21 +275,17 @@ macro pages*(server: ServerRef, body: untyped): untyped =
               newCall(
                 "[]",
                 ident("decoded_url"),
-                newCall(
-                  "..^",
-                  newCall("len", path),
-                  newLit(1))
+                newCall("..^", newCall("len", path), newLit(1))
               )
             )
           )
         )
         ifstmtlist.add(  # decode_url.startsWith(`path`)
           newNimNode(nnkElifBranch).add(
-            newCall(
-              "startsWith",
-              ident("decoded_url"),
-              path),
-            slist))
+            newCall("startsWith", ident("decoded_url"), path),
+            slist
+            )
+          )
       elif current == "endswith":
         slist.insert(0,  # let url: string = decoded_url[0..^`path`.len]
           newNimNode(nnkLetSection).add(
@@ -303,21 +296,18 @@ macro pages*(server: ServerRef, body: untyped): untyped =
                 "[]",
                 ident("decoded_url"),
                 newCall(
-                  "..^",
-                  newLit(0),
-                  newCall("+", newLit(1), newCall("len", path))
+                  "..^", newLit(0), newCall("+", newLit(1), newCall("len", path))
                 )
               )
             )
           )
-          )
+        )
         ifstmtlist.add(  # decode_url.endsWith(`path`)
           newNimNode(nnkElifBranch).add(
-            newCall(
-              "endsWith",
-              ident("decoded_url"),
-              path),
-            slist))
+            newCall("endsWith", ident("decoded_url"), path),
+            slist
+          )
+        )
       elif current == "regex":
         slist.insert(0,  # discard match(decoded_url, `path`, url)
             newNimNode(nnkDiscardStmt).add(
@@ -347,14 +337,10 @@ macro pages*(server: ServerRef, body: untyped): untyped =
       newNimNode(nnkElse).add(
         newCall(  # await request.respond(Http404, "Not found")
           "await",
-          newCall(
-            "respond",
-            ident("request"),
-            ident("Http404"),
-            newLit("Not found"))
-          )
+          newCall("respond", ident("request"), ident("Http404"), newLit("Not found"))
         )
       )
+    )
 
   result = newNimNode(nnkProcDef).add(
     ident("receivepages"),  # procedure name.

+ 2 - 2
tests/test4/templates/index.html

@@ -5,12 +5,12 @@
 </head>
 <body>
   <h1 align="center">Now the value is $(myvariable)</h1>
-  if not $(can_place)
+  if not @can_place
   {
     <h1 align="center">Can't place</h1>
   }
 
-  if $(can_place)
+  if @can_place
   {
     <h1 align="center">Can place is "true"</h1>
   }

+ 2 - 2
tests/test6/templates/index.html

@@ -5,9 +5,9 @@
 </head>
 <body>
   <ul>
-    for i in 0..$(fruits)
+    for i in 0..@fruits
     {
-      <li>$fruits[i]</li>
+      <li>fruits[i]</li>
     }
   </ul>
 </body>