A small compiler that turns SCSS-like markup into HTML. Selectors become tags, properties become inline styles, and nested rules become nested elements.
Only a C++20 compiler (g++) is required. The lexer and parser are pre-generated and committed to the repo.
makeThis produces an htms binary in the project root.
To regenerate the lexer/parser from lexer.l and parser.y install flex and bison (≥ 3.8), then:
make regen-clean && makemacOS note: the bundled bison is too old. Install with
brew install bisonand put it ahead of/usr/binonPATH.
htms reads source from stdin and writes HTML to stdout.
echo "div { backgroud: green; span { color: white; } }" | ./htmsOutput:
<div style="backgroud: green;">
<span style="color: white;"> </span>
</div>selector {
property: value;
nested-selector {
property: 23px;
}
}- Selectors — plain identifiers become HTML tag names.
.foobecomes<div class="foo">;#foobecomes<div id="foo">. - Properties —
name: value;. They become entries in the element'sstyleattribute. - Values — strings (
'…'/"…"), numbers with optional unit suffix (23px,-1), identifiers, or space-separated combinations. - Nested rules — emit child elements inside the parent.
make && ./test.shGreen lines pass, red lines fail.