rebol解析函数能否创建完全解析css2 / css3的规则? [英] Can rebol parse function be able to create rules for parsing css2 / css3 fully?

查看:167
本文介绍了rebol解析函数能否创建完全解析css2 / css3的规则?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

rebol解析功能有限制吗?它是否能够解析整个css2 / css 3规范还是会遇到理论上不可能形成一些规则?

Are there limitation to rebol parse function power ? Would it be capable of parsing the whole css2 / css 3 spec or will it encounter theorical impossibility to form some rules ?

在HostileFork回答之后更新:我的意思是在regexp中我认为这是不可能的,解析得更强大了吗?

Update after HostileFork answer: I mean in regexp I think it would be rather impossible, is parse much more powerfull ?

如果是,是否可以在与html5兼容的rebol vid中构建浏览器?

If yes does it mean it would be possible to build a browser in rebol vid compatible with html5 ?

推荐答案

你的有限制的问题很滑。我会试着给你 回答,而不仅仅是是的,确定......这会更加便利,尽管不太教育。 :)

Your question of "are there limits" is slippery. I'll try and give you "the answer" instead of just "yeah, sure"...which would be more expedient albeit not too educational. :)

请考虑以下代码段。它将解析器位置捕获到 x 中,然后运行DO方言括号中的内容。如果 css-parser 函数成功,该代码会将 x 重新设置为输入的尾部,或者返回到头部如果函数失败,则输入最后,它将解析位置设置为当前 x 。而且正如我们所知,只有在规则结束时我们处于输入系列的末尾时,PARSE才返回true ...

Consider the following snippet. It captures the parser position into x, and then runs what's in parentheses in the DO dialect. That code re-sets x to the tail of the input if the css-parser function succeeds, or to the head of the input if the function fails. Finally, it sets the parse position to the current x. And as we know, PARSE returns true only if we're at the end of the input series when the rules finish...

parse my-css [x: (x: either css-parser x [tail x] [head x]]) :x]

这是有效的解析方言代码 AND 如果(且仅当) css-parser 函数成功,它返回true。因此,如果你可以在Rebol中编写一个css解析器,你可以用解析方言来编写它。

That's valid parse dialect code AND it returns true if (and only if) the css-parser function succeeds. Therefore, if you can write a css parser in Rebol at all, you can write it "in the parse dialect".

(这导致了在Rebol函数中解决给定的计算问题是可能的。值得庆幸的是,计算机科学家不必在每次弹出新语言时重新回答这个问题。你可以计算任何由图灵机计算的东西,而不是任何东西。不能......并以外行的方式查看 Alan Turing自己的话 .CSS解析不是这正是停顿问题,所以是的......可以做到。)

(This leads to the question of it's possible to solve a given computing problem in a Rebol function. Thankfully, computer scientists don't have to re-answer that question each time a new language pops up. You can compute anything that be computed by a Turing machine, and nothing that can't be...and check out Alan Turing's own words, in layman's terms. CSS parsing isn't precisely the halting problem, so yeah... it can be done.)

我会重新设计你的问题:

I'll take a stab at re-framing your question:

是否可以编写一个规则块(不使用PAREN!,SET-WORD!或GET-WORD!构造)被传递到PARSE函数并在任何有效的CSS文件上返回TRUE,在任何格式错误的文件上返回FALSE?

"Is it possible to write a block of rules (which do not use PAREN!, SET-WORD!, or GET-WORD! constructs) that can be passed into the PARSE function and return TRUE on any valid CSS file and FALSE on any malformed one?"

W3C推出了关于CSS好坏的正式规范:

The formal specification of what makes for good or bad CSS is put out by the W3C:

http://www.w3.org/TR/CSS2/grammar .html

但请注意,即使在那里,它也不是全部干涸。他们的正式颜色常量规范不能排除 #abcd ,他们不得不在评论中用英文写下来:

But notice that even there, it's not all cut-and-dry. Their "formal" specification of color constants can't rule out #abcd, they had to write about it in the comments, in English:

/*
 * There is a constraint on the color that it must
 * have either 3 or 6 hex-digits (i.e., [0-9a-fA-F])
 * after the "#"; e.g., "#000" is OK, but "#abcd" is not.
 */
hexcolor
  : HASH S*
  ;

这导致我们问我们是否会原谅Rebol之后无法做出那种认可我们通过带走PAREN来捆绑PARSE!/ GET-WORD!/ SET-WORD! (我只想根据你的问题指出这类问题)。

This leads us to ask if we would forgive Rebol for not being able to do that kind of recognition after we've tied PARSE's hands by taking away PAREN!/GET-WORD!/SET-WORD! (I just want to point out this kind of issue in light of your question).

作为Rebol 3解析项目的一部分,有一篇关于< a href =http://www.rebol.net/wiki/Parse_Project#Theory_of_PARSE =noreferrer> Parse理论 ...

As part of the Rebol 3 parse project there's been a write-up of the Theory of Parse...

PARSE方言是自上而下解析语言(TDPL系列)系列的增强成员,包括自顶向下解析语言(TDPL),广义自上而下解析语言(GTDPL)和解析表达式语法(PEG)并使用与该系列的其他成员相同的有序选择解析方法。

The PARSE dialect is an enhanced member of the family of Top-down parsing languages (TDPL family) including the Top-down parsing language (TDPL), the Generalized top-down parsing language (GTDPL) and the Parsing expression grammar (PEG) and uses the same "ordered choice" parsing method as the other members of the family.

如上面的链接所指出的那样,该类的成员使得Rebol的PARSE严格地比正则表达式和 LL解析器更强大。我认为它比LL(k)和LL *解析器更强大,但它已经有一段时间了,因为我研究了这些东西,我不打赌我的生活。 :)

As pointed out in the link above, being a member of this class makes Rebol's PARSE strictly more powerful than both regular expressions and LL parsers. I assume it's more powerful than LL(k) and LL* parsers as well, but it has been a while since I've studied this stuff and I wouldn't bet my life on it. :)

你真的不需要理解所有这些意味着什么,以便利用它来回答你的可以做到的问题。由于人们声称要解析CSS a href =http://en.wikipedia.org/wiki/ANTLR =noreferrer> ANTLR ,ANTLR是一个LL *解析器,然后我会说Rebol可以做到。 PAREN!如果你碰到一堵墙就会让你做任何事情,但这是一个很滑的斜坡,开始使用它太粗心了。

You don't really need to understand what all that means in order to make use of it to answer your "can it be done" question. Since people have claimed to parse CSS with ANTLR, and ANTLR is an LL* parser, then I'd say Rebol can do it. PAREN! is the ace-in-the-hole which lets you do "anything" if you hit a wall, but it's a slippery slope to start using it too carelessly.

这篇关于rebol解析函数能否创建完全解析css2 / css3的规则?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆