Created
February 25, 2024 14:04
-
-
Save lantos1618/89ecfca3f593990775acc799d51588ed to your computer and use it in GitHub Desktop.
custom programing language
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HtmlTag: enum = { | |
div = "Div", | |
p = "P", | |
h1 = "H1", | |
h2 = "H2", | |
} | |
HtmlNode = { | |
tag: HtmlTag, | |
attr: Map<String, String>, | |
children: Vec<HtmlNode>, | |
render: () String { | |
let mut result = String::new(); | |
result.push_str("<"); | |
result.push_str(self.tag); | |
for (key, value) in self.attr { | |
result.push_str(" "); | |
result.push_str(key); | |
result.push_str("=\""); | |
result.push_str(value); | |
result.push_str("\""); | |
} | |
result.push_str(">"); | |
for child in self.children { | |
result.push_str(child.render()); | |
} | |
result.push_str("</"); | |
result.push_str(self.tag); | |
result.push_str(">"); | |
result | |
} | |
} | |
Div: (attr: Map<String, String>, children: Vec<HtmlNode>) -> HtmlNode = { | |
tag: HtmlTag::div, | |
attr: attr, | |
children: children, | |
} | |
genHtml: comp Fn = () { | |
loop (HtmlTag, (tag) { | |
`tag`(attr: Map<String, String>, children: Vec<HtmlNode>) -> HtmlNode { | |
tag: tag, | |
attr: attr, | |
children: children, | |
} | |
}) | |
} | |
genHtml() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment