JetCore engine (Tag.cpp/.h, Global.cpp/.h, __*.cpp tag classes): - Numerous __mysql.cpp connection-pooling correctness fixes (stale result sets, double-indirection sessionid bugs, field caching, pool keying) and a session-registration-before-connection-confirmed ordering fix (dangling pointer on a failed connect) - Tag.cpp: large body of fixes to the tag-dispatch/container-scanning logic (bare-name fallback, database aliasing, single-quote handling, @-prefix session variable resolution, TAGDEF caching, nested split-tag scanning for if/while/until/ifrow so an inner one doesn't corrupt an outer one's own boundary scan) plus the process-first rendering order fix (a <process> now runs before <checksession>/page resolution, fixing a real "blank page after successful login" bug) - Global.h/.cpp: added imapSessions (parallel to the existing __mysql* session map) for the new <imap> tag family - __whiledir.cpp/__include.cpp: caching and directory-name-aliasing fixes - __call.cpp/.h: fixed a dangling-pointer bug - __write.cpp: fixed an O_WRONLY-only open that couldn't create a new file - __ifrow.cpp/__sql.cpp: fixed the same sessionid double-indirection bug __mysql.cpp had (resolveKeyword's result was being used as a map key lookup instead of the resolved value itself) jetc compiler (jetc/JetParser.cpp/.h, JetCodegen.cpp/.h, JetAST.h, jetc.cpp, build-shared.sh, build-compiled.sh): - Parser fixes: inline <include>, nested-quote handling, void-tag recognition - Codegen fixes and expanded AST support - build-shared.sh: atomic rename into place for a freshly-built .jtc (a live server dlopen()ing the same path mid-rebuild was corrupting its own already-mapped view of the old file) and a staleness check so a cached JetCore .o doesn't silently keep serving yesterday's fixes forever - Added -lssl to both build scripts' link lines (needed once the new <imap> tag's client-side TLS code existed - previously nothing in this codebase used OpenSSL's SSL/TLS client API, only libcrypto) Site content (jetc/barant-site/): SPA (fetch-and-swap navigation) rollout across essentially every .page/.jet/.section/.tag/.proc/.method file - dynamic-content fixes, fragment-mode stripping, native $[@name] session variables replacing older mechanisms, and this session's own checkout.page redesign, login start-param redirect fix, and per-page side-menu (menu.bar/$[PAGE].menu) refresh support. Completed the earlier main.css/control.css move from assets/ to assets/images/ (git still showed the old paths as tracked-but-deleted until now). Deliberately left out of this commit: dozens of .pre-<description>- <date> manual backup files (this session's and earlier ones' own before/after snapshots, not meant for permanent history), compiled .jtc build outputs, ad hoc test binaries and scripts under jetc/ (login_asan, wcwc_test, optest2_bin, etc.), and jetc/__pycache__/ - none of these are meant to be tracked; a .gitignore covering them would be worth adding separately.
111 lines
4.9 KiB
C++
Executable File
111 lines
4.9 KiB
C++
Executable File
#ifndef __JetParser_h__
|
|
#define __JetParser_h__
|
|
|
|
#include "JetAST.h"
|
|
#include <string>
|
|
#include <map>
|
|
#include <utility>
|
|
|
|
namespace jetc {
|
|
|
|
// Standalone parser for a subset of the JET template grammar. Mirrors the
|
|
// character-level grammar implemented by JetCore's Tag::parseContainer /
|
|
// Tag::Tag (attribute scanning, same-tag-name nesting depth, the <if>
|
|
// <else> split) closely enough for well-formed templates, but is a fresh
|
|
// implementation - it does not reuse JetCore's Tag classes, since those
|
|
// fuse parsing and execution together (a real parse/execute split there
|
|
// is a separate, larger refactor). Anything outside the modeled subset
|
|
// (set/if/for/while/$[...]/literal text) is captured as an exact raw
|
|
// source span and left for the existing interpreter (Tag::interpretSpan)
|
|
// to run at compiled-program runtime, so unsupported constructs degrade
|
|
// gracefully instead of failing to compile.
|
|
class Parser {
|
|
public:
|
|
// topLevel is false for any nested sub-parse (an <if>/<for>/<while>
|
|
// body, via parseSub) and true for the file's own top-level flow and
|
|
// for anything spliced in from an <include> (which inherits the
|
|
// includer's own topLevel, since it's meant to read as if written
|
|
// inline at that point - see parseInclude). Only used to decide
|
|
// whether a <tag name="X"> definition is eligible for compilation
|
|
// (see parseTagDef) - one found at topLevel==false (nested inside
|
|
// another construct) stays FALLBACK, unchanged, matching __tag.cpp's
|
|
// own locally-scoped-registration semantics that only a true
|
|
// top-level definition is guaranteed to always be registered by the
|
|
// time any invocation could reach it.
|
|
explicit Parser(const std::string &src, std::string baseDir = "", int includeDepth = 0, bool topLevel = true)
|
|
: s(src), pos(0), baseDir(baseDir), includeDepth(includeDepth), topLevel(topLevel) {}
|
|
|
|
std::vector<NodePtr> parseNodes();
|
|
|
|
private:
|
|
std::string s;
|
|
size_t pos;
|
|
size_t nextId = 0;
|
|
std::string baseDir;
|
|
int includeDepth;
|
|
bool topLevel;
|
|
|
|
bool eof() const { return pos >= s.size(); }
|
|
bool starts(const std::string &lit) const;
|
|
static bool isNameChar(char c);
|
|
void skipWs();
|
|
std::string readName();
|
|
std::string peekTagName(size_t at) const;
|
|
|
|
bool matchTagOpen(const std::string &name, size_t at) const;
|
|
bool matchTagClose(const std::string &name, size_t at) const;
|
|
|
|
// p points at '<' of some tag's opening; advances p past its '>' or
|
|
// "/>", skipping quoted attribute values. Returns true if self-closing.
|
|
bool skipOpenTag(size_t &p);
|
|
void skipQuotedValue(size_t &p);
|
|
void skipEmbeddedTag(size_t &p);
|
|
|
|
std::map<std::string, std::string> parseAttrs(bool &hasContainer);
|
|
|
|
// Scans forward from bodyStart (just after the opening tag's '>') for
|
|
// tagName's matching close, tracking same-tag-name nesting depth and
|
|
// (if lookForElse) a depth==1 "<else>" split point.
|
|
// Returns {closePos, elsePos} (elsePos == npos if not found/not sought).
|
|
std::pair<size_t, size_t> scanBody(size_t bodyStart, const std::string &tagName, bool lookForElse);
|
|
|
|
std::vector<NodePtr> parseSub(size_t start, size_t end);
|
|
|
|
// <include file="..."> is spliced in at compile time - read the
|
|
// referenced file (resolved relative to baseDir) and parse ITS
|
|
// content as if it had been written inline here, so everything in
|
|
// it (custom <tag> definitions included) goes through this real
|
|
// compiler, not the separate runtime interpreter (which has its own,
|
|
// independently-buggy nested-tag handling). Returns the parsed nodes
|
|
// to be spliced into the caller's own node list.
|
|
std::vector<NodePtr> parseInclude();
|
|
|
|
NodePtr parseVar();
|
|
NodePtr parseSet();
|
|
NodePtr parseIf();
|
|
NodePtr parseFor();
|
|
NodePtr parseWhile();
|
|
NodePtr parseFallback();
|
|
|
|
// <tag name="X">...</tag> at true top level (see topLevel above) -
|
|
// compiles the definition body with a nested (topLevel=false) parse
|
|
// instead of falling back to raw text, so jetc can generate a real
|
|
// render function for it (see JetCodegen). Falls back to an ordinary
|
|
// FALLBACK node (same as today) if the definition has no container
|
|
// or no literal name= - degrades gracefully rather than failing to
|
|
// compile.
|
|
NodePtr parseTagDef();
|
|
|
|
// <container> (any case/attributes/closing style, always void - see
|
|
// isVoidTag) - a leaf node; the actual rendering logic lives in
|
|
// Tag::renderContainer, called from generated code exactly as the
|
|
// interpreter's own <container> dispatch calls it today.
|
|
NodePtr parseContainerSlot();
|
|
|
|
std::string newId(const std::string &prefix) { return prefix + std::to_string(nextId++) + "_"; }
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|