All Projects → rep-movsd → See Phit

rep-movsd / See Phit

Licence: lgpl-3.0
A C++ HTML template engine that uses compile time HTML parsing

Programming Languages

cpp14
131 projects

Projects that are alternatives of or similar to See Phit

Nlpython
This repository contains the code related to Natural Language Processing using python scripting language. All the codes are related to my book entitled "Python Natural Language Processing"
Stars: ✭ 265 (-28.38%)
Mutual labels:  parsing
Pom
PEG parser combinators using operator overloading without macros.
Stars: ✭ 310 (-16.22%)
Mutual labels:  parsing
Atto
friendly little parsers
Stars: ✭ 340 (-8.11%)
Mutual labels:  parsing
Creek
Ruby library for parsing large Excel files.
Stars: ✭ 270 (-27.03%)
Mutual labels:  parsing
Gval
Expression evaluation in golang
Stars: ✭ 297 (-19.73%)
Mutual labels:  parsing
Kgt
BNF wrangling and railroad diagrams
Stars: ✭ 312 (-15.68%)
Mutual labels:  parsing
Stringsareevil
Reducing memory allocations from 7.5GB to 32KB
Stars: ✭ 260 (-29.73%)
Mutual labels:  parsing
Vncorenlp
A Vietnamese natural language processing toolkit (NAACL 2018)
Stars: ✭ 354 (-4.32%)
Mutual labels:  parsing
Phply
PHP parser written in Python using PLY
Stars: ✭ 301 (-18.65%)
Mutual labels:  parsing
Estree
The ESTree Spec
Stars: ✭ 3,867 (+945.14%)
Mutual labels:  parsing
Ldetool
Code generator for fast log file parsers
Stars: ✭ 273 (-26.22%)
Mutual labels:  parsing
Semver
Semantic version parsing and comparison.
Stars: ✭ 283 (-23.51%)
Mutual labels:  parsing
Maya
Datetimes for Humans™
Stars: ✭ 3,298 (+791.35%)
Mutual labels:  parsing
Nearley
📜🔜🌲 Simple, fast, powerful parser toolkit for JavaScript.
Stars: ✭ 3,089 (+734.86%)
Mutual labels:  parsing
Como Lang Ng
como-lang-ng is now ana-lang, located at https://github.com/analang/ana
Stars: ✭ 342 (-7.57%)
Mutual labels:  parsing
Angourimath
Open-source symbolic algebra library for C# and F#. One of the most powerful in .NET
Stars: ✭ 266 (-28.11%)
Mutual labels:  parsing
Tag
ID3, MP4 and OGG/FLAC metadata parsing in Go
Stars: ✭ 314 (-15.14%)
Mutual labels:  parsing
Scnlib
scanf for modern C++
Stars: ✭ 359 (-2.97%)
Mutual labels:  parsing
Reek
Code smell detector for Ruby
Stars: ✭ 3,693 (+898.11%)
Mutual labels:  parsing
Clangkit
ClangKit provides an Objective-C frontend to LibClang. Source tokenization, diagnostics and fix-its are actually implemented.
Stars: ✭ 330 (-10.81%)
Mutual labels:  parsing

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:

#include <iostream>
#include "seephit.h"
using namespace std;



int main()
{
  constexpr auto parser =
    R"*(
    <span >
    <p  color="red" height='10' >{{name}} is a {{profession}} in {{city}}</p  >
    </span>
    )*"_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 << endl;
  
  dct["city"] = "New York";
  dct["name"] = "John";
  dct["profession"] = "janitor";

  spt_tree.root.render(cerr, dct);
  cerr << endl;
}

produces the following output

<HTML>
  <span>
    <p COLOR='red' HEIGHT='10'>
    Mary is a doctor in London
    </p>
  </span>
</HTML>

<HTML>
  <span>
    <p COLOR='red' HEIGHT='10'>
    John is a janitor in New York
    </p>
  </span>
</HTML>

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:

<DIV>
This is a bad closing tag
</DIVV>

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<ROW, COL, WHAT>::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<4, 3, spt::Mismatched_Close_Tag>::Error' requested here
  REPORT_ERRORS(parser);
  ^
./parse_error_generated.h💯94: note: expanded from macro 'REPORT_ERRORS'
spt::IF<hasErr, spt::Error<parser.errRow, parser.errCol, spt::MsgToType<parser.err>::type>> {};
                                                                                             ^
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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].