Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Mar 25, 2024
1 parent d2091d1 commit ca3035d
Show file tree
Hide file tree
Showing 9 changed files with 610 additions and 325 deletions.
7 changes: 7 additions & 0 deletions src/web/web-css/rule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once

namespace Web::Css {

struct Rule {};

} // namespace Web::Css
16 changes: 16 additions & 0 deletions src/web/web-css/style-sheet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <karm-base/rc.h>
#include <karm-base/vec.h>

namespace Web::Css {

struct Rule;

struct StyleSheet {
Vec<Strong<Rule>> cssRules;

StyleSheet() = default;
};

} // namespace Web::Css
274 changes: 0 additions & 274 deletions src/web/web-html/builder.cpp

This file was deleted.

21 changes: 4 additions & 17 deletions src/web/web-html/cli/main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <karm-io/funcs.h>
#include <karm-sys/entry.h>
#include <karm-sys/file.h>
#include <web-html/builder.h>
#include <web-html/lexer.h>
#include <web-html/parser.h>

Res<> entryPoint(Sys::Ctx &) {
auto file = try$(Sys::File::open("bundle://web-html-cli/exemple.html"_url));
Expand All @@ -12,23 +12,10 @@ Res<> entryPoint(Sys::Ctx &) {
Sys::println("Orginal Source:");
Sys::println("{}", buf);

Sys::println("Lexing:");
Web::Html::Lexer lexer;
for (auto r : iterRunes(buf))
lexer.consume(r);

lexer.consume(-1, true);
Sys::println("\t(no output if successful)");

Sys::println("Tokens:");
for (auto const &t : lexer.tokens())
Sys::println("{}", t);

Sys::println("Building:");
Sys::println("Parsing:");
auto doc = makeStrong<Web::Dom::Document>();
Web::Html::Builder builder{doc};
for (auto const &t : lexer.tokens())
builder.accept(t);
Web::Html::Parser builder{doc};
builder.write(buf);

Sys::println("Result:");
Io::Emit emit{Sys::out()};
Expand Down
File renamed without changes.
11 changes: 3 additions & 8 deletions src/web/web-html/lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void Lexer::_raise(Str msg) {
logError("{}: {}", toStr(_state), msg);
}

Slice<Token> Lexer::consume(Rune rune, bool isEof) {
void Lexer::consume(Rune rune, bool isEof) {
// logDebug("Consuming '{c}' {#x} in {}", rune, rune, toStr(_state));

switch (_state) {
Expand Down Expand Up @@ -1661,8 +1661,7 @@ Slice<Token> Lexer::consume(Rune rune, bool isEof) {
// U+0060 GRAVE ACCENT (`)
// This is an unexpected-character-in-unquoted-attribute-value parse
// error. Treat it as per the "anything else" entry below.
else if (rune == '"' or rune == '\'' or rune == '<' or rune == '=' or
rune == '`') {
else if (rune == '"' or rune == '\'' or rune == '<' or rune == '=' or rune == '`') {
_raise("unexpected-character-in-unquoted-attribute-value");
_builder.append(rune);
}
Expand Down Expand Up @@ -3475,9 +3474,7 @@ Slice<Token> Lexer::consume(Rune rune, bool isEof) {

// If the number is a noncharacter, then this is a
// noncharacter-character-reference parse error.
else if ((0xFDD0 <= _currChar and _currChar <= 0xFDEF) or
(_currChar & 0xFFFF) == 0xFFFE or
(_currChar & 0xFFFF) == 0xFFFF) {
else if ((0xFDD0 <= _currChar and _currChar <= 0xFDEF) or (_currChar & 0xFFFF) == 0xFFFE or (_currChar & 0xFFFF) == 0xFFFF) {
_raise("noncharacter-character-reference");
}

Expand Down Expand Up @@ -3574,8 +3571,6 @@ Slice<Token> Lexer::consume(Rune rune, bool isEof) {
panic("unknown-state");
break;
}

return sub(_sink);
}

} // namespace Web::Html
Loading

0 comments on commit ca3035d

Please sign in to comment.