### Get Tim Template by Path Source: https://openpeeps.github.io/tim/theindex.html Retrieves a Tim template using its path. This function is part of the Meta module and requires a TimEngine. ```nim proc getTemplateByPath(engine: TimEngine; path: string): TimTemplate ``` -------------------------------- ### Get Token from Lexer Source: https://openpeeps.github.io/tim/theindex.html Retrieves the next token from a lexer. This function is part of the Tokens module. ```nim proc getToken(lex: var Lexer): TokenTuple ``` -------------------------------- ### Get HTML Compiler Tail Source: https://openpeeps.github.io/tim/theindex.html Retrieves the tail of an HTML compiler. This function is part of the HTML module. ```nim proc getTail(c: HtmlCompiler): string ``` -------------------------------- ### Get Void AST Node Source: https://openpeeps.github.io/tim/theindex.html Creates and returns a void AST node. This function is part of the AST module. ```nim proc getVoidNode(): Node ``` -------------------------------- ### AST Utility Procedures Source: https://openpeeps.github.io/tim/tim/engine/ast.html Utility procedures for inspecting and converting AST nodes, including getting infix operators, tags, types, and converting JSON nodes to Tim nodes. ```APIDOC ## AST Utility Procedures ### Description Provides utility functions for working with AST nodes, such as retrieving operator information, node types, and converting between formats. ### Method Various (primarily `get*` and `to*` procedures) ### Endpoint N/A (Internal module procedures) ### Parameters Parameters vary per procedure. Examples: #### getInfixMathOp - **kind** (TokenKind) - Required - The token kind. - **isInfixInfix** (bool) - Required - Indicates if it's an infix operation. #### getInfixOp - **kind** (TokenKind) - Required - The token kind. - **isInfixInfix** (bool) - Required - Indicates if it's an infix operation. #### getTag - **x** (Node) - Required - The AST node. #### getType - **x** (NimNode) - Required - The Nim AST node. #### getVoidNode - Returns a void AST node. #### toTimNode - **x** (JsonNode) - Required - The JSON node to convert. ### Request Example ```nim let voidNode = getVoidNode() let timNode = toTimNode(parseJson("{\"key\": \"value\"}")) ``` ### Response #### Success Response (200) - **Result** (Various types: MathOp, InfixOp, string, NodeType, Node) - The result of the utility procedure. #### Response Example ```json { "operator": "+", "type": "Integer" } ``` ``` -------------------------------- ### Get Tim Template Tail Source: https://openpeeps.github.io/tim/theindex.html Retrieves the tail of a Tim template. This function is part of the Meta module. ```nim proc getTail(t: TimTemplate): string ``` -------------------------------- ### Get Tim Template Path Source: https://openpeeps.github.io/tim/theindex.html Retrieves the file path of a Tim template. This function is part of the Meta module and requires a TimEngine. ```nim proc getTemplatePath(engine: TimEngine; path: string): string ``` -------------------------------- ### Get Infix Math Operator (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Determines the appropriate MathOp based on a TokenKind and whether it's an infix-infix context. This procedure is used for parsing mathematical expressions. ```nim proc getInfixMathOp(kind: TokenKind; isInfixInfix: bool): MathOp {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Get Tim Template View Source: https://openpeeps.github.io/tim/theindex.html Retrieves a specific view from a Tim template using a key. This function is part of the Meta module and requires a TimEngine. ```nim proc getView(engine: TimEngine; key: string): TimTemplate ``` -------------------------------- ### Get Tag String (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Retrieves a string representation of a tag associated with a Node. This procedure is useful for debugging or introspection. ```nim proc getTag(x: Node): string {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Get Full HTML Content Source: https://openpeeps.github.io/tim/tim/engine/compilers/html.html Retrieves the complete HTML content generated by the HtmlCompiler. This procedure takes an HtmlCompiler instance. ```nim proc getHtml(c: HtmlCompiler): string {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Get Tim Template View Indentation Source: https://openpeeps.github.io/tim/theindex.html Retrieves the indentation level of a Tim template view. This function is part of the Meta module. ```nim proc getViewIndent(t: TimTemplate): uint ``` -------------------------------- ### Get Template Type Source: https://openpeeps.github.io/tim/theindex.html Retrieves the type of a Tim template. This function is part of the Meta module and requires an engine and a path to the template. ```nim proc getType(t: TimTemplate): TimTemplateType ``` -------------------------------- ### Check for Numbers in Lexer Source: https://openpeeps.github.io/tim/theindex.html Determines if there are numbers starting at a given position in the lexer's input. This function is part of the Tokens module. ```nim proc hasNumbers(lex`gensym0: var Lexer; pos`gensym0: int): bool ``` -------------------------------- ### Get HTML Head Section Source: https://openpeeps.github.io/tim/tim/engine/compilers/html.html Retrieves the top section of a split HTML layout. This procedure takes an HtmlCompiler instance as input. ```nim proc getHead(c: HtmlCompiler): string {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Get HTML Tail Section Source: https://openpeeps.github.io/tim/tim/engine/compilers/html.html Retrieves the bottom section of a split HTML layout. This procedure operates on an HtmlCompiler instance. ```nim proc getTail(c: HtmlCompiler): string {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Check for Letters in Lexer Source: https://openpeeps.github.io/tim/theindex.html Determines if there are letters starting at a given position in the lexer's input. This function is part of the Tokens module. ```nim proc hasLetters(lex`gensym0: var Lexer; pos`gensym0: int): bool ``` -------------------------------- ### Get Void Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Returns a Node representing a void type. This procedure is likely used to represent the absence of a value or a null type. ```nim proc getVoidNode(): Node {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Get AST from Parser in Nim Source: https://openpeeps.github.io/tim/tim/engine/parser.html Retrieves the Abstract Syntax Tree (AST) from a given 'Parser' object. This procedure is marked as 'gcsafe' and does not raise any exceptions. ```nim proc getAst(p: Parser): Ast {....gcsafe, raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Get Infix Operator (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Retrieves the InfixOp based on a TokenKind and an infix-infix flag. This is likely used in parsing or AST construction for infix operations. ```nim proc getInfixOp(kind: TokenKind; isInfixInfix: bool): InfixOp {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Initialize TimEngine Source: https://openpeeps.github.io/tim/tim/engine/meta.html Initializes the TimEngine instance with source, output, and base path configurations. It supports optional minification and indentation settings. ```Nim proc newTim(src, output, basepath: string; minify = true; indent = 2; showHtmlError = false): TimEngine {.raises: [TimError, ValueError, OSError, IOError], tags: [ReadDirEffect, WriteDirEffect], forbids: [].} ``` -------------------------------- ### Initialize Module System Source: https://openpeeps.github.io/tim/theindex.html Initializes the module system. This function is part of the Std module. ```nim proc initModuleSystem() ``` -------------------------------- ### Lexer and Parser Initialization Source: https://openpeeps.github.io/tim/theindex.html Contains procedures for creating new lexer and parser instances. The `newLexer` function initializes a lexer from file content, while `newParser` creates a parser instance with a given Tim engine and template. `parseSnippet` provides flexibility in parsing by accepting either a file path or an ID and code string. ```nim proc newLexer(fileContent`gensym0: string; allowMultilineStrings`gensym0 = false): Lexer proc newParser(engine: TimEngine; tpl: TimTemplate; isMainParser = true; refreshAst = false): Parser proc parseSnippet(snippetPath: string): Parser proc parseSnippet(id, code: string): Parser ``` -------------------------------- ### Get Lexer Error Status Source: https://openpeeps.github.io/tim/theindex.html Checks if a lexer has encountered an error. This function is part of the Tokens module. ```nim proc hasError(lex`gensym0: Lexer): bool ``` -------------------------------- ### Tim Engine and Rendering Source: https://openpeeps.github.io/tim/theindex.html Provides functions for initializing and interacting with the Tim engine, as well as rendering templates. `newTim` sets up the engine with source, output, and base path configurations. `render` generates the output string for a specified view, and `precompile` optimizes template compilation. ```nim proc newTim(src, output, basepath: string; minify = true; indent = 2; showHtmlError = false): TimEngine proc precompile(engine: TimEngine; callback: TimCallback = nil; flush = true; waitThread = false; browserSyncPort = Port(6502); browserSyncDelay = 200; global: JsonNode = newJObject(); watchoutNotify = true) proc render(engine: TimEngine; viewName: string; layoutName = defaultLayout; local = newJObject()): string ``` -------------------------------- ### Tim Engine Initialization Source: https://openpeeps.github.io/tim/tim/engine/meta.html Initializes the TimEngine engine with various configuration options. ```APIDOC ## newTim ### Description Initializes `TimEngine` engine with source, output, and base path. Optional parameters control minification, indentation, and HTML error display. ### Method PROC ### Parameters - **src** (string) - Required - Source directory path. - **output** (string) - Required - Output directory path. - **basepath** (string) - Required - Base path for the engine. - **minify** (bool) - Optional - Whether to minify output. Defaults to true. - **indent** (int) - Optional - Indentation level for output. Defaults to 2. - **showHtmlError** (bool) - Optional - Whether to show HTML errors. Defaults to false. ### Raises TimError, ValueError, OSError, IOError ### Effects ReadDirEffect, WriteDirEffect ``` -------------------------------- ### Get Parser Error Status Source: https://openpeeps.github.io/tim/theindex.html Checks if a parser has encountered an error. This function is part of the Parser module. ```nim proc hasError(p: Parser): bool ``` -------------------------------- ### Create New HTML Compiler Source: https://openpeeps.github.io/tim/theindex.html Creates a new HTML compiler instance. Overloads exist to initialize with an AST or an engine, AST, and template. ```nim proc newCompiler(ast: Ast; minify = true; indent = 2): HtmlCompiler ``` ```nim proc newCompiler(engine: TimEngine; ast: Ast; tpl: TimTemplate; minify = true; indent = 2; data: JsonNode = newJObject()): HtmlCompiler ``` -------------------------------- ### Configure Engine and Write Output Source: https://openpeeps.github.io/tim/tim/engine/meta.html Functions to set global engine data, check error reporting status, and write rendered HTML or HTML tails to the disk. ```Nim proc setGlobalData(engine: TimEngine; data: JsonNode) {.raises: [], tags: [], forbids: [].} proc showHtmlErrors(engine: TimEngine): bool {.raises: [], tags: [], forbids: [].} proc writeHtml(engine: TimEngine; tpl: TimTemplate; htmlCode: string) {.raises: [IOError], tags: [WriteIOEffect], forbids: [].} proc writeHtmlTail(engine: TimEngine; tpl: TimTemplate; htmlCode: string) {.raises: [IOError], tags: [WriteIOEffect], forbids: [].} ``` -------------------------------- ### Get Tim Template ID Source: https://openpeeps.github.io/tim/theindex.html Retrieves the unique identifier of a Tim template. This function is part of the Meta module. ```nim proc getTemplateId(t: TimTemplate): string ``` -------------------------------- ### Write AST and HTML to Engine Source: https://openpeeps.github.io/tim/theindex.html Procedures for writing compiled AST nodes or raw HTML content to a specific TimTemplate within the engine context. ```Nim proc writeAst(engine: TimEngine; tpl: TimTemplate; astCode: Ast) proc writeHtml(engine: TimEngine; tpl: TimTemplate; htmlCode: string) proc writeHtmlTail(engine: TimEngine; tpl: TimTemplate; htmlCode: string) ``` -------------------------------- ### Get AST Node Tag Source: https://openpeeps.github.io/tim/theindex.html Retrieves the tag associated with an AST node. This function is part of the AST module. ```nim proc getTag(x: Node): string ``` -------------------------------- ### Manage AST and Templates Source: https://openpeeps.github.io/tim/tim/engine/meta.html Procedures for reading, writing, and configuring ASTs and templates within the TimEngine. These functions handle disk I/O and template metadata. ```Nim proc readAst(engine: TimEngine; tpl: TimTemplate): Ast {.raises: [Exception], tags: [ReadIOEffect, RootEffect], forbids: [].} proc writeAst(engine: TimEngine; tpl: TimTemplate; astCode: Ast) {.raises: [IOError, Exception], tags: [WriteIOEffect, RootEffect], forbids: [].} proc setViewIndent(t: TimTemplate; i: uint) {.raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Create New Parser Instance in Nim Source: https://openpeeps.github.io/tim/tim/engine/parser.html Initializes and returns a new 'Parser' object. It requires an 'engine', 'tpl', and optional boolean flags for 'isMainParser' and 'refreshAst'. This procedure can raise various exceptions including ImportError, IOError, OSError, ValueError, Exception, KeyError, and RegexError. ```nim proc newParser(engine: TimEngine; tpl: TimTemplate; isMainParser = true; refreshAst = false): Parser {....gcsafe, raises: [ImportError, IOError, OSError, ValueError, Exception, KeyError, RegexError], tags: [ReadDirEffect, TimeEffect, ReadIOEffect, RootEffect, WriteIOEffect], forbids: [].} ``` -------------------------------- ### Get HTML Compiler Error Status Source: https://openpeeps.github.io/tim/theindex.html Checks if an HTML compiler has encountered an error. This function is part of the HTML module. ```nim proc hasError(c: HtmlCompiler): bool ``` -------------------------------- ### Create New Command Node Source: https://openpeeps.github.io/tim/theindex.html Creates a new AST node representing a command. It requires a CommandType, a node, and a TokenTuple. ```nim proc newCommand(cmdType: CommandType; node: Node; tk: TokenTuple): Node ``` -------------------------------- ### AST Node Creation Procedures Source: https://openpeeps.github.io/tim/tim/engine/ast.html This section details the procedures for creating various types of Abstract Syntax Tree (AST) nodes, including assignments, boolean values, function calls, and more. ```APIDOC ## AST Node Creation Procedures ### Description Provides functions to construct different AST node types, essential for building program representations. ### Method Various (primarily `new*` procedures) ### Endpoint N/A (Internal module procedures) ### Parameters Parameters vary per procedure. Examples: #### newArray - **items** (seq[Node]) - Optional - A sequence of nodes to include in the array. #### newAssignment - **tk** (TokenTuple) - Required - Token information for the assignment. - **varValue** (Node) - Required - The node representing the value to be assigned. #### newBool - **v** (bool) - Required - The boolean value. - **tk** (TokenTuple) - Optional - Token information. #### newCall - **tk** (TokenTuple) - Required - Token information for the call. #### newCommand - **cmdType** (CommandType) - Required - The type of command. - **node** (Node) - Required - The associated node. - **tk** (TokenTuple) - Required - Token information. #### newCondition - **condIfBranch** (ConditionBranch) - Required - The condition branch details. - **tk** (TokenTuple) - Required - Token information. #### newFloat - **v** (float) - Required - The float value. - **tk** (TokenTuple) - Optional - Token information. #### newFunction - **tk** (TokenTuple) - Required - Token information. - **ident** (string) - Required - The identifier for the function. #### newHtmlElement - **tag** (HtmlTag) - Required - The HTML tag. - **tk** (TokenTuple) - Required - Token information. #### newIdent - **tk** (TokenTuple) - Required - Token information. #### newInfix - **lhs** (Node) - Required - The left-hand side operand. - **rhs** (Node) - Required - The right-hand side operand. - **infixOp** (InfixOp) - Required - The infix operator. - **tk** (TokenTuple) - Required - Token information. #### newInteger - **v** (int) - Required - The integer value. - **tk** (TokenTuple) - Optional - Token information. #### newNode - **nt** (static NodeType) - Required - The type of the new node. - **tk** (TokenTuple) - Optional - Token information. #### newStream - **node** (JsonNode) - Required - The JSON node to stream. #### newString - **tk** (TokenTuple) - Required - Token information. - **v** (string) - Required - The string value. #### newVariable - **varName** (string) - Required - The name of the variable. - **varValue** (Node) - Required - The node representing the variable's value. - **meta** (Meta) - Required - Metadata for the variable. - **tk** (TokenTuple) - Optional - Token information. ### Request Example ```nim let assignmentNode = newAssignment((0, 0), newInteger(10)) let boolNode = newBool(true) ``` ### Response #### Success Response (200) - **Node** (Node) - The newly created AST node. #### Response Example ```json { "nodeType": "Assignment", "value": { "nodeType": "Integer", "value": 10 } } ``` ``` -------------------------------- ### Node Creation Procedures Source: https://openpeeps.github.io/tim/tim/engine/ast.html Procedures for instantiating various AST node types such as arrays, booleans, floats, integers, and strings. ```APIDOC ## POST /nodes/newArray ### Description Creates a new Array node containing the provided items. ### Method POST ### Parameters #### Request Body - **items** (seq[Node]) - Optional - A sequence of nodes to initialize the array. ### Response #### Success Response (200) - **node** (Node) - The newly created Array node. --- ## POST /nodes/newBool ### Description Creates a new boolean value node. ### Method POST ### Parameters #### Request Body - **v** (bool) - Required - The boolean value. - **tk** (TokenTuple) - Optional - Token metadata. ### Response #### Success Response (200) - **node** (Node) - The boolean node. --- ## POST /nodes/newVariable ### Description Creates a new variable definition node with a name and value. ### Method POST ### Parameters #### Request Body - **varName** (string) - Required - The name of the variable. - **varValue** (Node) - Required - The initial value node. - **meta/tk** (Meta/TokenTuple) - Required - Metadata or token information. ### Response #### Success Response (200) - **node** (Node) - The variable definition node. ``` -------------------------------- ### Create AST Nodes Source: https://openpeeps.github.io/tim/theindex.html Provides functions to create various types of Abstract Syntax Tree (AST) nodes. These functions are essential for building the AST representation of the input code or data. They handle different node types, including identifiers, infix expressions, integers, and HTML elements. ```nim proc newFunction(tk: TokenTuple; ident: string): Node proc newHtmlElement(tag: HtmlTag; tk: TokenTuple): Node proc newIdent(tk: TokenTuple): Node proc newInfix(lhs, rhs: Node; infixOp: InfixOp; tk: TokenTuple): Node proc newInteger(v: int): Node proc newInteger(v: int; tk: TokenTuple): Node proc newNode(nt: static NodeType): Node proc newNode(nt: static NodeType; tk: TokenTuple): Node proc newStream(node: JsonNode): Node proc newString(v: string): Node proc newString(tk: TokenTuple): Node proc newVariable(varName: string; varValue: Node; meta: Meta): Node proc newVariable(varName: string; varValue: Node; tk: TokenTuple): Node ``` -------------------------------- ### Get AST Node Type Source: https://openpeeps.github.io/tim/theindex.html Retrieves the type of an Abstract Syntax Tree (AST) node. This function is part of the AST module. ```nim proc getType(x: NimNode): NodeType ``` -------------------------------- ### Module System Procedures Source: https://openpeeps.github.io/tim/tim/engine/std.html Provides utility procedures for interacting with the standard library, including checking for module existence, initializing the system, and invoking Nim procedures dynamically. ```Nim proc call(lib, fnName: string; args: seq[Arg]): Node proc exists(lib: string): bool proc initModuleSystem() proc std(lib: string): (Module, SourceCode) proc toNimSeq(node: Node): seq[string] ``` -------------------------------- ### Enable JIT for Tim Template Source: https://openpeeps.github.io/tim/theindex.html Enables Just-In-Time (JIT) compilation for a Tim template. This function is part of the Meta module. ```nim proc jitEnable(t: TimTemplate) ``` -------------------------------- ### AST Operations Source: https://openpeeps.github.io/tim/tim/engine/meta.html Procedures for reading and writing Abstract Syntax Trees (AST) for Tim templates. ```APIDOC ## readAst ### Description Gets the `AST` of a `TimTemplate` from storage. ### Method PROC ### Parameters - **engine** (TimEngine) - Required - The TimEngine instance. - **tpl** (TimTemplate) - Required - The TimTemplate to read AST from. ### Returns Ast - The Abstract Syntax Tree of the template. ### Raises Exception ### Effects ReadIOEffect, RootEffect --- ## writeAst ### Description Writes `astCode` on disk using `tpl` info. ### Method PROC ### Parameters - **engine** (TimEngine) - Required - The TimEngine instance. - **tpl** (TimTemplate) - Required - The TimTemplate to write AST to. - **astCode** (Ast) - Required - The Abstract Syntax Tree code to write. ### Raises IOError, Exception ### Effects WriteIOEffect, RootEffect ``` -------------------------------- ### Create Array Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new Array node, optionally initializing it with a sequence of nodes. This procedure is part of the node creation utilities. ```nim proc newArray(items: seq[Node] = @[]): Node {....raises: [], tags: [], forbids: [].} Creates a new `Array` node ``` -------------------------------- ### Get Type Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Retrieves the NodeType of a NimNode. This procedure is marked as compileTime, suggesting it's used during compilation for type analysis. ```nim proc getType(x: NimNode): NodeType {.compileTime, ...raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Create HtmlCompiler Instance (Engine, AST, Template) Source: https://openpeeps.github.io/tim/tim/engine/compilers/html.html Creates a new HtmlCompiler instance using a TimEngine, AST, and TimTemplate. Supports minification, indentation, and optional JSON data. ```nim proc newCompiler(engine: TimEngine; ast: Ast; tpl: TimTemplate; minify = true; indent = 2; data: JsonNode = newJObject()): HtmlCompiler {. ...raises: [ValueError, Exception, JsonError, KeyError, IOError], tags: [RootEffect, WriteIOEffect], forbids: [].} ``` -------------------------------- ### Create HtmlCompiler Instance (AST only) Source: https://openpeeps.github.io/tim/tim/engine/compilers/html.html Creates a new HtmlCompiler instance using an Abstract Syntax Tree (AST). Allows configuration for minification and indentation. ```nim proc newCompiler(ast: Ast; minify = true; indent = 2): HtmlCompiler {. ...raises: [ValueError, Exception, JsonError, KeyError, IOError], tags: [RootEffect, WriteIOEffect], forbids: [].} ``` -------------------------------- ### Lexer Initialization and Token Extraction Source: https://openpeeps.github.io/tim/tim/engine/tokens.html Procedures for initializing a new lexer instance and extracting the next token from the input stream. These functions handle the core parsing logic and state management. ```Nim proc newLexer(fileContent: string; allowMultilineStrings = false): Lexer {.raises: [IOError, OSError], tags: [ReadIOEffect], forbids: [].} proc getToken(lex: var Lexer): TokenTuple {.raises: [IOError, OSError], tags: [ReadIOEffect], forbids: [].} ``` -------------------------------- ### Precompile Templates in Tim Engine (Nim) Source: https://openpeeps.github.io/tim/index.html Precompiles templates within 'layouts' and 'views' directories to static HTML or binary AST. It supports options for flushing outdated files, enabling filesystem monitoring via a compile-time flag, and running precompilation in a separate thread. ```nim proc precompile(engine: TimEngine; callback: TimCallback = nil; flush = true; waitThread = false; browserSyncPort = Port(6502); browserSyncDelay = 200; global: JsonNode = newJObject(); watchoutNotify = true) { ...raises: [OSError, ResourceExhaustedError], tags: [ReadDirEffect, WriteDirEffect], forbids: [] } ``` -------------------------------- ### Create Assignment Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new assignment node, taking a token tuple and the value to be assigned as input. This procedure is used for constructing assignment operations. ```nim proc newAssignment(tk: TokenTuple; varValue: Node): Node {....raises: [], tags: [], forbids: [].} Create a new assignment Node ``` -------------------------------- ### Manage Template Dependencies and Placeholders Source: https://openpeeps.github.io/tim/tim/engine/meta.html Procedures for tracking template dependencies and managing placeholders within the Tim engine. These functions allow adding, checking, and clearing template-related data. ```Nim proc addDep(t: TimTemplate; path: string) {....raises: [], tags: [], forbids: [].} proc addPlaceholder(engine: TimEngine; k: string; snippetTree: Ast) {. ...raises: [KeyError], tags: [], forbids: [].} proc hasDep(t: TimTemplate; path: string): bool {....raises: [], tags: [], forbids: [].} proc hasPlaceholder(engine: TimEngine; k: string): bool {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Create Command Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new command node, specifying the command type, an associated node, and a token tuple. This is used for representing commands within the AST. ```nim proc newCommand(cmdType: CommandType; node: Node; tk: TokenTuple): Node {. ...raises: [], tags: [], forbids: [].} Create a new command for `cmdType` ``` -------------------------------- ### Logging Functions Source: https://openpeeps.github.io/tim/theindex.html Defines procedures for logging messages at different severity levels (info, notice, warn). These functions are part of the logging module and are used to record events and potential issues during program execution. They accept a logger instance, message, location, and optional arguments. ```nim proc newInfo(logger: Logger; msg: Message; line, col: int; useFmt: bool; args: varargs[string]) proc newNotice(logger: Logger; msg: Message; line, col: int; useFmt: bool; args: varargs[string]) proc newWarn(logger: Logger; msg: Message; line, col: int; useFmt: bool; args: varargs[string]) proc newWarningMultiLines(logger: Logger; msg: Message; line, col: int; useFmt: bool; extraLines: seq[string]; extraLabel: string; args: varargs[string]) ``` -------------------------------- ### Create Generic Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new generic node based on a static NodeType. An overload also allows associating a token tuple with the new node. ```nim proc newNode(nt: static NodeType): Node ``` ```nim proc newNode(nt: static NodeType; tk: TokenTuple): Node ``` -------------------------------- ### Lexer Ready Check Source: https://openpeeps.github.io/tim/theindex.html Checks if the lexer is ready to process input. This function is part of the Tokens module. ```nim proc lexReady(lex`gensym0: var Lexer) ``` -------------------------------- ### Nim Templates for Compile-Time Error Reporting Source: https://openpeeps.github.io/tim/tim/engine/logging.html These Nim templates facilitate compile-time error reporting with flexible argument handling and metadata inclusion. Templates like `compileErrorWithArgs` and `error` allow developers to define error messages with varying numbers of arguments, token information, and optional metadata. The `warn` templates provide similar functionality for warnings. ```nim template compileErrorWithArgs(msg: Message) template compileErrorWithArgs(msg: Message; args: openArray[string]) template compileErrorWithArgs(msg: Message; args: openArray[string]; meta: Meta) template compileErrorWithArgs(msg: Message; meta: Meta; args: openArray[string]) template error(msg: Message; meta: Meta; args: varargs[string]) template error(msg: Message; tk: TokenTuple) template error(msg: Message; tk: TokenTuple; args: openArray[string]) template error(msg: Message; tk: TokenTuple; strFmt: bool; extraLines: seq[string]; extraLabel: string; args: varargs[string]) template errorWithArgs(msg: Message; tk: TokenTuple; args: openArray[string]) template warn(msg: Message; tk: TokenTuple; args: varargs[string]) template warn(msg: Message; tk: TokenTuple; strFmt: bool; args: varargs[string]) template warnWithArgs(msg: Message; tk: TokenTuple; args: openArray[string]) ``` -------------------------------- ### Tim Engine Configuration Source: https://openpeeps.github.io/tim/tim/engine/meta.html Procedures for setting global data and view indentation within the Tim Engine. ```APIDOC ## setGlobalData ### Description Sets global data for the TimEngine. ### Method PROC ### Parameters - **engine** (TimEngine) - Required - The TimEngine instance. - **data** (JsonNode) - Required - The JSON data to set globally. --- ## setViewIndent ### Description Sets the indentation level for a TimTemplate. ### Method PROC ### Parameters - **t** (TimTemplate) - Required - The TimTemplate to set indentation for. - **i** (uint) - Required - The indentation level. ``` -------------------------------- ### Create Variable Definition Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing a variable definition. It takes the variable name, its value, and either metadata or a token tuple. ```nim proc newVariable(varName: string; varValue: Node; meta: Meta): Node {. ...raises: [], tags: [], forbids: [].} Create a new variable definition Node ``` ```nim proc newVariable(varName: string; varValue: Node; tk: TokenTuple): Node {. ...raises: [], tags: [], forbids: [].} Create a new variable definition Node ``` -------------------------------- ### Type Definitions and Utilities Source: https://openpeeps.github.io/tim/theindex.html Defines core types like `Node`, `Lexer`, `Parser`, `TimEngine`, and `TimTemplate`, along with utility procedures. This includes functions for setting lexer errors, managing global data, and adjusting view indentation. ```nim type NimCall object OSModule object Parser type Node type NodeType type ScopeTable const nimValue = ValueKind.nimValue const scopeStorage = StorageType.scopeStorage proc setError(lex`gensym0: var Lexer; message`gensym0: string) proc setGlobalData(engine: TimEngine; data: JsonNode) proc setViewIndent(t: TimTemplate; i: uint) proc readAst(engine: TimEngine; tpl: TimTemplate): Ast ``` -------------------------------- ### Create New Assignment Node Source: https://openpeeps.github.io/tim/theindex.html Creates a new AST node representing an assignment. It requires a TokenTuple and the value node for the assignment. ```nim proc newAssignment(tk: TokenTuple; varValue: Node): Node ``` -------------------------------- ### Lexer Navigation and Utility Procedures Source: https://openpeeps.github.io/tim/tim/engine/tokens.html Utility procedures for navigating the lexer cursor, checking for specific character types, and managing lexer state such as errors and skipping characters. ```Nim proc current(lex: var Lexer): char proc inc(lex: var Lexer; offset = 1) proc skip(lex: var Lexer) proc hasLetters(lex: var Lexer; pos: int): bool proc hasNumbers(lex: var Lexer; pos: int): bool proc setError(lex: var Lexer; message: string) proc getError(lex: Lexer): string proc hasError(lex: Lexer): bool ``` -------------------------------- ### Create Function Definition Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing a function definition. It takes a token tuple and the function's identifier as input. ```nim proc newFunction(tk: TokenTuple; ident: string): Node {....raises: [], tags: [], forbids: [].} Create a new Function definition Node ``` -------------------------------- ### Iterate Engine Components Source: https://openpeeps.github.io/tim/tim/engine/meta.html Iterators for traversing layouts, views, placeholders, and snippets associated with the TimEngine instance. ```Nim iterator getLayouts(engine: TimEngine): TimTemplate {.raises: [], tags: [], forbids: [].} iterator getViews(engine: TimEngine): TimTemplate {.raises: [], tags: [], forbids: [].} iterator listPlaceholders(engine: TimEngine): (string, seq[Ast]) {.raises: [], tags: [], forbids: [].} iterator snippets(engine: TimEngine; k: string): Ast {.raises: [KeyError], tags: [], forbids: [].} ``` -------------------------------- ### Parser Procedures Source: https://openpeeps.github.io/tim/tim/engine/parser.html This section details the procedures available for interacting with the Tim Engine's parser, including functions to retrieve the Abstract Syntax Tree (AST), check for errors, and create new parser instances. ```APIDOC ## GET /engine/parser/getAst ### Description Retrieves the Abstract Syntax Tree (AST) from a given parser instance. ### Method GET ### Endpoint /engine/parser/getAst ### Parameters #### Query Parameters - **p** (Parser) - Required - The parser instance from which to retrieve the AST. ### Response #### Success Response (200) - **Ast** (object) - The Abstract Syntax Tree generated by the parser. #### Response Example ```json { "ast": {} } ``` ``` ```APIDOC ## GET /engine/parser/hasError ### Description Checks if a parser instance has encountered any errors during parsing. ### Method GET ### Endpoint /engine/parser/hasError ### Parameters #### Query Parameters - **p** (Parser) - Required - The parser instance to check for errors. ### Response #### Success Response (200) - **bool** (boolean) - True if the parser has errors, false otherwise. #### Response Example ```json { "hasErrors": false } ``` ``` ```APIDOC ## POST /engine/parser/newParser ### Description Creates a new parser instance for the Tim Engine. ### Method POST ### Endpoint /engine/parser/newParser ### Parameters #### Request Body - **engine** (TimEngine) - Required - The Tim Engine instance. - **tpl** (TimTemplate) - Required - The template to be parsed. - **isMainParser** (boolean) - Optional - Defaults to true. Indicates if this is the main parser. - **refreshAst** (boolean) - Optional - Defaults to false. Indicates whether to refresh the AST. ### Response #### Success Response (200) - **Parser** (object) - The newly created parser instance. #### Response Example ```json { "parser": {} } ``` ``` ```APIDOC ## POST /engine/parser/parseSnippet ### Description Parses a static snippet of code provided as a string. ### Method POST ### Endpoint /engine/parser/parseSnippet ### Parameters #### Request Body - **id** (string) - Required - An identifier for the snippet. - **code** (string) - Required - The code content of the snippet to parse. ### Response #### Success Response (200) - **Parser** (object) - The parser instance after processing the snippet. #### Response Example ```json { "parser": {} } ``` ``` ```APIDOC ## POST /engine/parser/parseSnippet ### Description Parses a snippet code from a specified file path. ### Method POST ### Endpoint /engine/parser/parseSnippet ### Parameters #### Request Body - **snippetPath** (string) - Required - The file path to the snippet to parse. ### Response #### Success Response (200) - **Parser** (object) - The parser instance after processing the snippet from the file. #### Response Example ```json { "parser": {} } ``` ``` -------------------------------- ### Create Condition Branch Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing a condition branch, using a ConditionBranch and a token tuple. This is likely for constructing conditional logic in the AST. ```nim proc newCondition(condIfBranch: ConditionBranch; tk: TokenTuple): Node {. ...raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Create Integer Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing an integer value. Overloads are provided for creating an integer node with or without a token tuple. ```nim proc newInteger(v: int): Node {....raises: [], tags: [], forbids: [].} ``` ```nim proc newInteger(v: int; tk: TokenTuple): Node {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Template Retrieval and Lifecycle Source: https://openpeeps.github.io/tim/tim/engine/meta.html Procedures for retrieving templates from the engine's internal tables and managing their lifecycle, including clearing templates and flushing precompiled files. ```Nim proc clearTemplateByPath(engine: TimEngine; path: string) {. ...raises: [ValueError], tags: [], forbids: [].} proc flush(engine: TimEngine) {....raises: [OSError], tags: [ReadDirEffect, WriteDirEffect], forbids: [].} proc getLayout(engine: TimEngine; key: string): TimTemplate {. ...raises: [KeyError, ValueError], tags: [], forbids: [].} proc getView(engine: TimEngine; key: string): TimTemplate {. ...raises: [KeyError, ValueError], tags: [], forbids: [].} proc getTemplateByPath(engine: TimEngine; path: string): TimTemplate {. ...raises: [KeyError], tags: [], forbids: [].} ``` -------------------------------- ### Create Float Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing a floating-point value. Overloads allow creation with or without a token tuple. ```nim proc newFloat(v: float): Node {....raises: [], tags: [], forbids: [].} Create a new float value node ``` ```nim proc newFloat(v: float; tk: TokenTuple): Node {....raises: [], tags: [], forbids: [].} Create a new float value node ``` -------------------------------- ### Create String Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing a string value. Overloads allow creating a string node from a token tuple or a string literal. ```nim proc newString(tk: TokenTuple): Node {....raises: [], tags: [], forbids: [].} Create a new string value node ``` ```nim proc newString(v: string): Node {....raises: [], tags: [], forbids: [].} Create a new string value node ``` -------------------------------- ### Logging and Error Handling Source: https://openpeeps.github.io/tim/theindex.html Procedures for handling compilation errors, logging messages, and retrieving error details. ```APIDOC ## POST /logging/error ### Description Logs a specific error message during the template compilation process. ### Method POST ### Endpoint /logging/error ### Parameters #### Request Body - **logger** (Logger) - Required - The active logger instance - **msg** (Message) - Required - The error message type - **line** (int) - Required - Line number of the error - **col** (int) - Required - Column number of the error - **args** (seq[string]) - Optional - Additional error context arguments ``` -------------------------------- ### Log Warning Messages Source: https://openpeeps.github.io/tim/theindex.html Provides multiple interfaces for logging warnings during template processing. Supports both explicit line/column positioning and token-based location tracking. ```Nim proc warn(logger: Logger; msg: Message; line, col: int; strFmt: bool; args: varargs[string]) proc warn(logger: Logger; msg: Message; line, col: int; args: varargs[string]) template warn(msg: Message; tk: TokenTuple; strFmt: bool; args: varargs[string]) template warn(msg: Message; tk: TokenTuple; args: varargs[string]) ``` -------------------------------- ### Create New Float Node Source: https://openpeeps.github.io/tim/theindex.html Creates a new AST node representing a floating-point number. It can optionally include a TokenTuple. ```nim proc newFloat(v: float): Node ``` ```nim proc newFloat(v: float; tk: TokenTuple): Node ``` -------------------------------- ### Create New Array Node Source: https://openpeeps.github.io/tim/theindex.html Creates a new AST node representing an array. It can optionally take a sequence of nodes as items. ```nim proc newArray(items: seq[Node] = @[]): Node ``` -------------------------------- ### Create Infix Operation Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node for an infix operation, taking the left-hand side (lhs), right-hand side (rhs), the infix operator, and a token tuple. ```nim proc newInfix(lhs, rhs: Node; infixOp: InfixOp; tk: TokenTuple): Node {. ...raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Create HTML Element Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing an HTML element, taking an HtmlTag and a token tuple as input. This procedure is for generating HTML structures within the AST. ```nim proc newHtmlElement(tag: HtmlTag; tk: TokenTuple): Node {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Create Function Call Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing a function call. It takes a token tuple as input, likely representing the function identifier and arguments. ```nim proc newCall(tk: TokenTuple): Node {....raises: [], tags: [], forbids: [].} Create a new function call Node ``` -------------------------------- ### Create New Condition Node Source: https://openpeeps.github.io/tim/theindex.html Creates a new AST node representing a conditional statement. It requires a ConditionBranch and a TokenTuple. ```nim proc newCondition(condIfBranch: ConditionBranch; tk: TokenTuple): Node ``` -------------------------------- ### Initialize Common Local Storage Macro (Nim) Source: https://openpeeps.github.io/tim/index.html A compile-time macro used to initialize a common local storage that can be shared across controllers. It utilizes untyped parameters for flexibility. ```nim macro initCommonStorage(x: untyped) ``` -------------------------------- ### Compile-time Local Storage Initializer Template (Nim) Source: https://openpeeps.github.io/tim/index.html A compile-time template that acts as a local storage initializer, facilitating the reuse of shareable data. After merging, it invokes the `%*` macro from `std/json` to convert NimNode to JsonNode. ```nim template `&*`(n: untyped): untyped ``` -------------------------------- ### Template Storage and Path Resolution Source: https://openpeeps.github.io/tim/tim/engine/meta.html Utility functions to resolve absolute paths for AST files, source files, and static HTML storage. These are essential for the engine to locate and persist template data. ```Nim proc getAstPath(t: TimTemplate): string {....raises: [], tags: [], forbids: [].} proc getAstStoragePath(engine: TimEngine): string {....raises: [], tags: [], forbids: [].} proc getHtmlPath(t: TimTemplate): string {....raises: [], tags: [], forbids: [].} proc getHtmlStoragePath(engine: TimEngine): string {....raises: [], tags: [], forbids: [].} proc getSourcePath(engine: TimEngine): string {....raises: [], tags: [], forbids: [].} proc getSourcePath(t: TimTemplate): string {....raises: [], tags: [], forbids: [].} ``` -------------------------------- ### Template Management API Source: https://openpeeps.github.io/tim/theindex.html Procedures for managing template lifecycles, dependencies, and storage within the Tim engine. ```APIDOC ## POST /meta/addDep ### Description Adds a dependency path to a specific TimTemplate instance. ### Method POST ### Endpoint /meta/addDep ### Parameters #### Request Body - **t** (TimTemplate) - Required - The template instance - **path** (string) - Required - The path to the dependency ### Response #### Success Response (200) - **status** (string) - Confirmation of dependency addition ``` ```APIDOC ## POST /meta/clearTemplateByPath ### Description Clears a cached template from the engine based on its file path. ### Method POST ### Endpoint /meta/clearTemplateByPath ### Parameters #### Request Body - **engine** (TimEngine) - Required - The active template engine instance - **path** (string) - Required - The path of the template to clear ``` -------------------------------- ### Dump Node to String (var string, Node) Source: https://openpeeps.github.io/tim/tim/engine/compilers/html.html Dumps a 'Node' to a stringified JSON format using the 'pkg/jsony' library. This procedure is part of the dumpHook overloads. ```nim proc dumpHook(s: var string; v: Node) {....raises: [Exception], tags: [RootEffect], forbids: [].} ``` -------------------------------- ### Create Boolean Node (Nim) Source: https://openpeeps.github.io/tim/tim/engine/ast.html Creates a new node representing a boolean value. Overloads exist to create a boolean node with or without a token tuple. ```nim proc newBool(v: bool): Node {....raises: [], tags: [], forbids: [].} Create a new bool value Node ``` ```nim proc newBool(v: bool; tk: TokenTuple): Node {....raises: [], tags: [], forbids: [].} Create a new bool value Node ``` -------------------------------- ### Create New Call Node Source: https://openpeeps.github.io/tim/theindex.html Creates a new AST node representing a function or procedure call. It requires a TokenTuple. ```nim proc newCall(tk: TokenTuple): Node ``` -------------------------------- ### List Placeholders in Tim Engine Source: https://openpeeps.github.io/tim/theindex.html An iterator that lists all placeholders within a Tim engine, yielding their keys and associated AST nodes. This function is part of the Meta module. ```nim iterator listPlaceholders(engine: TimEngine): (string, seq[Ast]) ```