views:

73

answers:

2

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 ?

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

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

+1  A: 

Should be perfectly capable of parsing the spec, should you have motive and patience to write the rules. It'd be a bit more involved than, say, a JSON parser, but it'd be the same idea.

rgchris
yeah good idea should look at json parser
Rebol Tutorial
+5  A: 

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. :)

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]

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".

(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:

"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?"

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

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*
  ;

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).

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

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.

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. :)

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.

Hostile Fork
My question was implicitely parse vs regex. I think RegEx cannot do this.
Rebol Tutorial
Devil is in the detail: will parse be able to process optional properties ? I remember having such a headache with that when just parsing html.
Rebol Tutorial
If I believe you, nothing would prevent to do an html 5 browser in rebol view am I wrong ? ;)
Rebol Tutorial
Much of Rebol's vision is about "rebelling" against the existing bulky evolution of the web and standards. Similarly, Douglas Crockford made JSON as a competitor to XML, and he noted Rebol as an inspiration. So while there is no technical reason why you couldn't build an HTML5 browser in Rebol, there is a reason why this is not a focus...their vision is to browse Rebol documents, not HTML5 documents. It's like HTML/CSS are "legacy" formats in the Rebol world, to be tended to in spare time. It's part of what's good about the initiative, and also part of what's kinda nuts about it!
Hostile Fork
JSON is javascript for the browse. So he has never repelled the browser nor html. Why did Crockford choose JSON instead of Rebol format ? Because you can't talk to the rest of the world. This is typical of what people in the it says:http://twitter.com/dfinke@reboltutorial I hear you. I played with rebol, a little, in the '90s. I liked it but didn't stay with it. Not integrated. PowerShell is :)So if you don't bother to listen to the world don't be surprised that the world does the same towards rebol. Even if people like they can't use it.
Rebol Tutorial
Yes, but with REBOL 3's plugin system, I think integration of all sorts will be on the horizon.
Gregory Higley