百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

see-phit

> 前端框架
开源

一款使用编译时 HTML 分析的 C++ HTML 模板引擎

393 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

一款使用编译时 HTML 分析的 C++ HTML 模板引擎

see-phit

See-phit is a compile time HTML templating library written in modern C++.

You write plain HTML as C++ string literals and it is parsed at compile time into a DOM like data structure.

It makes your "stringly typed" HTML text into an actual strongly typed DSL.

C++14 is required to compile - it implements a fairly complete HTML parser as constexpr functions. Before constexpr, the way to make C++ DSLs was by (ab)using operator overloading in ingenious ways, but now we can actually have a DSL as a user literal string and let the compiler compile your DSL into C++

Example:

cpp
#include 
#include "seephit.h"
using namespace std;

int main()
{
  constexpr auto parser =
    R"*(
    
    
{{name}} is a {{profession}} in {{city}}

    
    )*"_html;
    
  spt::tree spt_tree(parser);
  
  spt::template_dict dct;
  dct["name"] = "Mary";
  dct["profession"] = "doctor";
  dct["city"] = "London";
  
  spt_tree.root.render(cerr, dct);
  cerr 
  
    

    Mary is a doctor in London
    

  

  
    

    John is a janitor in New York
    

  

The program will fail to compile if the HTML is malformed - We attempt to make the compiler generate the most sensible error message:

For example, the following fragment:

xml

This is a bad closing tag

Generates the following compile errors in gcc:

$ g++ --std=c++14  -Wall main.cpp
In file included from seephit.h:21:0,
                 from main.cpp:3:
parse_error.h: In instantiation of 'constexpr spt::Error::Error() [with int ROW = 4; int COL = 3; WHAT = spt::Mismatched_Close_Tag]':
main.cpp:13:3:   required from here
parse_error.h:40:15: error: incompatible types in assignment of 'const int' to 'char [0]'
     SPTParser = fatal;
     ~~~~~~~~~~^~~~~~~

And the following in clang:

$ clang++ --std=c++14 -Wall main.cpp
In file included from main.cpp:3:
In file included from ./seephit.h:21:
./parse_error.h:40:15: error: array type 'char [0]' is not assignable
    SPTParser = fatal;
    ~~~~~~~~~ ^
main.cpp:13:3: note: in instantiation of member function 'spt::Error::Error' requested here
  REPORT_ERRORS(parser);
  ^
./parse_error_generated.h:100:94: note: expanded from macro 'REPORT_ERRORS'
spt::IF> {};
                                                                                             ^
1 error generated.

Some complicated template magic has been implemented to show the ROW and COLUMN in the text where the error occured. gcc actually prints ROW = xxx and COL = xxx, which is great! If your IDE does background parsing, it will indicate that your HTML template is malformed as you type it.

Limitations

The number of maximum nodes and attributes per parse is hardcoded to 1024.

Future plans

Add more complicated templating functionality with loops, conditionals and perhaps lambdas, and also allow this to be used on the frontend JS with emscripten.

Optimize the hell out of the templating engine

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++constexprcpp14htmlparsing

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架