Html 解释器问题
自去年以来,我一直在兼职编写 HTML 解释器。我不认为 HTML 是一种非常好的语言,并且认为我可以创建一个解释器,将我漂亮的代码翻译成 HTML 以在网络上使用。
它工作得非常好,并且正在一个小型网络应用程序上使用它,但是我在解析特定行时遇到问题,并且非常感谢任何关于如何解析它的建议。
我的代码:
HmtlDocument {
Page.Title: "Test webpage using JTHtml";
Using[] {
"../Assets/Stylesheets/default.css",
"../Assets/Scripts/slidercordian",
"../Assets/Scripts/jquery.1.4.1.js"
};
HtmlBody {
HtmlElement Divider(container) {
HtmlElement Divider(Header) {
HtmlElement Image(Logo, "../Assets/Images/logo.png");
HtmlElement Menu(MainMenu, Horizontal, Ul, li) {
li.Text: "Home", "index.html";
li.Text: "About Us", "about.html";
li.Text: "Services", "services.html";
li.Text: "Contact Us", "contact.html";
li.Text: "My Account", "../myaccount/default.html";
}
}
HtmlElement Divider(MainContent) {
HtmlElement Heading(Heading, 1) {
Heading.Text: "Welcome!";
}
HtmlElement Text(Text) {
Text.Text: "Welcome to my new website written purely in jthtml";
}
}
}
}
看,我遇到的问题在于以下行:
li.Text: "[value]", [resource]";
我的旧方法是这样写:
li.Text("[value]", "[resource]");
但是,这并不完全符合语法的其余部分,这就是为什么我会这样做喜欢保持这样:
li.Text: "[value]", "[resource]";
但我只是不确定如何解析该行。由于第一个结束引用和后面的逗号、空格和第二个开始引用,我陷入了困境。我似乎无法找出正确的逻辑。
任何帮助都值得赞赏。
谢谢你!
On the side since last year i've been writing an interpreter for HTML. I don't think HTML is a very nice language, and thought I might create an interpreter that translates my nice looking code into HTML for use on the web.
It works really well, and am using it on a little web app, but I'm having a problem parsing a particular line, and would appreciate any advice on how I could go about parsing it.
My code:
HmtlDocument {
Page.Title: "Test webpage using JTHtml";
Using[] {
"../Assets/Stylesheets/default.css",
"../Assets/Scripts/slidercordian",
"../Assets/Scripts/jquery.1.4.1.js"
};
HtmlBody {
HtmlElement Divider(container) {
HtmlElement Divider(Header) {
HtmlElement Image(Logo, "../Assets/Images/logo.png");
HtmlElement Menu(MainMenu, Horizontal, Ul, li) {
li.Text: "Home", "index.html";
li.Text: "About Us", "about.html";
li.Text: "Services", "services.html";
li.Text: "Contact Us", "contact.html";
li.Text: "My Account", "../myaccount/default.html";
}
}
HtmlElement Divider(MainContent) {
HtmlElement Heading(Heading, 1) {
Heading.Text: "Welcome!";
}
HtmlElement Text(Text) {
Text.Text: "Welcome to my new website written purely in jthtml";
}
}
}
}
See, the problem I am having is with the following line:
li.Text: "[value]", [resource]";
The old way I had it was to write it like this:
li.Text("[value]", "[resource]");
However, that doesn't quite stay true to the rest of the syntax, which is why I would like to keep it like this:
li.Text: "[value]", "[resource]";
But I'm just not sure how I would parse that line. I'm getting stuck because of the first closing quote and the following comma, space and second opening quote. I can't seem to figure out the right logic for it.
Any help at all is appreciated.
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
行: li.Text: "[value]", [resource]"; 缺少一个开头引号。
您是否缺少一个开头引号,或者解析器是否应该在没有开头引号的情况下理解它?
The line: li.Text: "[value]", [resource]"; is missing an opening quote.
Are you missing an opening quote or is the parser suppose to understand it without the opening quote?
如果你已经有了这条线,你可以轻松地使用像这样的正则表达式
但这似乎是你可以自己弄清楚的。也许我误解了这个问题?
If you already have the line, you can easily use a regex like
But that seems like something you could figure out by yourself. Maybe I'm misunderstanding the question?