Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Mar 24, 2024
1 parent f7ce40a commit 0fbec7a
Show file tree
Hide file tree
Showing 7 changed files with 384 additions and 204 deletions.
13 changes: 11 additions & 2 deletions example/templates/partials/ws.timl
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
@js
{
const watchout = new WebSocket('ws://127.0.0.1:6502/ws');
watchout.addEventListener('message', () => location.reload());
function connectWatchoutServer() {
const watchout = new WebSocket('ws://127.0.0.1:6502/ws');
watchout.addEventListener('message', () => location.reload());
watchout.addEventListener('close', () => {
setTimeout(() => {
console.log('Watchout WebSocket is closed. Try again...')
connectWatchoutServer()
}, 300)
})
}
connectWatchoutServer()
}
@end
17 changes: 12 additions & 5 deletions example/templates/views/index.timl
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
section.pt-5 > div.container > div.row > div#content-zone.col-lg-7.mx-auto
div.text-center > img src="https://raw.githubusercontent.com/openpeeps/tim/main/.github/timengine.png" alt="Tim Engine" width="200px"
h1.display-4.fw-bold:
"This is Tim 👋 A super fast template engine for cool kids!"
p.mb-4.h4.fw-normal.px-4 style="line-height: 1.8em":
// tips: variables declared at template level
// with default value are known at compile-time

var logo = "https://raw.githubusercontent.com/openpeeps/tim/main/.github/timengine.png"
var heading = "This is Tim 👋 A super fast template engine for cool kids!"
var lead = // double quote in multi-line strings
"Build sleek, dynamic websites and apps in a breeze with
Tim Engine's intuitive syntax and powerful features.
It's the template engine that keeps up with your creativity."

section.pt-5 > div.container > div.row > div#content-zone.col-lg-7.mx-auto
div.text-center
img src=$logo alt="Tim Engine" width="200px"
h1.display-4.fw-bold: $heading
p.mb-4.h4.fw-normal.px-4 style="line-height: 1.8em": $lead
@include "foot" // include footer
41 changes: 22 additions & 19 deletions src/tim/engine/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ type
ConditionBranch* = tuple[expr: Node, body: seq[Node]]
FnParam* = tuple[pName: string, pType: NodeType, pImplVal: Node, meta: Meta]
Node* {.acyclic.} = ref object
## Part of the compiler's abstract syntax tree
## **Important** do not initialize this object directly
case nt*: NodeType
of ntHtmlElement:
tag*: HtmlTag
Expand Down Expand Up @@ -181,11 +183,12 @@ type
# identifier name
identSafe*: bool
# whether to escape the stored value of `identName`
of ntCall:
callIdent*: string
## identifier name of a callable function
callArgs*: seq[Node]
## a sequence of arguments to to pass
identArgs*: seq[Node]
# of ntCall:
# callIdent*: string
# ## identifier name of a callable function
# callArgs*: seq[Node]
# ## a sequence of arguments to to pass
of ntDotExpr:
storageType*: StorageType
## holds the storage type of a dot expression
Expand All @@ -211,7 +214,8 @@ type
## if a function has no return type, then `ntUnknown`
## is used as default (void)
fnReturnHtmlElement*: HtmlTag
fnFwdDecl*, fnExport*: bool
fnFwdDecl*, fnExport*, fnImportNim*: bool
fnSource*: string
of ntJavaScriptSnippet,
ntYamlSnippet, ntJsonSnippet:
snippetCode*: string
Expand Down Expand Up @@ -260,23 +264,22 @@ type
Meta* = array[3, int]
ScopeTable* = TableRef[string, Node]
TimPartialsTable* = TableRef[string, (Ast, seq[cli.Row])]
Ast* = object
TimModulesTable* = TableRef[string, Ast]
Ast* {.acyclic.} = ref object
src*: string
## trace the source path
## the source path of the ast
nodes*: seq[Node]
## a seq containing tree nodes
partials*: TimPartialsTable
## other trees resulted from imports
## AST trees from included partials
modules*: TimModulesTable
## AST trees from imported modules
jit*: bool
## whether the current AST requires JIT compliation or not

const ntAssignableSet* = {ntLitString, ntLitInt, ntLitFloat, ntLitBool, ntLitObject, ntLitArray}

# proc add*(x: Node, y: Node) =
# if likely y != nil:
# case x.nt
# of ntStmtList:
# x.stmtList.add(y)
# else: discard
const ntAssignableSet* =
{ntLitString, ntLitInt, ntLitFloat,
ntLitBool, ntLitObject, ntLitArray}

proc getInfixOp*(kind: TokenKind, isInfixInfix: bool): InfixOp =
result =
Expand Down Expand Up @@ -533,8 +536,8 @@ proc newFunction*(tk: TokenTuple, ident: string): Node =

proc newCall*(tk: TokenTuple): Node =
## Create a new function call Node
result = newNode(ntCall, tk)
result.callIdent = tk.value
result = newNode(ntIdent, tk)
result.identName = tk.value

proc newInfix*(lhs, rhs: Node, infixOp: InfixOp, tk: TokenTuple): Node =
result = newNode(ntInfixExpr, tk)
Expand Down
Loading

0 comments on commit 0fbec7a

Please sign in to comment.