World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Ladislav 3-Dec-2009 [4661] | It looks, that I could have used: C: [while [and [A | B] accept | skip | reject]] |
Graham 3-Dec-2009 [4662x2] | Janko, charset is short for make bitset! so you can call them bitsets or charsets :) |
Ladislav, what 'choice operator? | |
BrianH 4-Dec-2009 [4664] | | |
jack-ort 11-Dec-2009 [4665] | Help! Still struggling to understand parse. How could I replace any and all SINGLE occurrences of the single-quote character anywhere in a string (beginning, middle or end) with TWO single-quotes? But if there are already TWO single-quotes together, I want to leave them alone. TIA for any and all help for a newbie! |
Maxim 11-Dec-2009 [4666x2] | easy, actually. you match double quotes first then fallback to single quotes, adding a new one and skiping one char... give me a minute I should get something working... |
R2? | |
jack-ort 11-Dec-2009 [4668] | yes, View 2.7.6 under Windows XP |
Steeve 11-Dec-2009 [4669x2] | >> parse/all str [ any [thru {"} [{"} | p: (insert p {"} skip) ]]] something like this (not tested) |
i think i misunderstood something, replace {"} by {'} maybe | |
Maxim 11-Dec-2009 [4671x2] | >> str: {1 ''2 '3 4 ' '5 ''6 '7 8 9 '0'} >> parse/all str [some [{''} | [{'} here: (insert here {'}) skip] | skip]] >> print str == {1 ''2 ''3 4 '' ''5 ''6 ''7 8 9 ''0''} |
note all ticks... ( ' ) are single quote chars in the above. | |
Steeve 11-Dec-2009 [4673] | same as mine, except i use THRU to speed up the process |
jack-ort 11-Dec-2009 [4674] | Thanks! I'm going to have to look @ this for awhile to understand why you even need to worry about the double-quote character. Much to learn.... Thanks Maxim and Steeve for the prompt replies! |
Maxim 11-Dec-2009 [4675] | print it out in the rebol console... you will see that my exampe doesn't nave any double quote characters.. they just look like so in altme's font ;-) |
Steeve 11-Dec-2009 [4676] | corrected version with thru: >> parse/all str [ any [thru {'} [{'} | p: (insert p {'} ) skip ]]] |
jack-ort 11-Dec-2009 [4677] | Ah! when you said "...you match double quotes first then fallback to single quotes, ..." I was thinking double-quote character, not double single-quotes. Need more coffee... Thanks very much! |
Maxim 11-Dec-2009 [4678] | ( I can see that being misleading when read hehehe :-) |
Rebolek 11-Dec-2009 [4679] | Just curious, I tested both versions and Steeve's version is about 2times faster than Maxim's :) |
Steeve 11-Dec-2009 [4680] | we should add a DONATE account somewhere, linked with Altme. I'm sure people would be glad to add 1 dollar for such fast assistance. Then, we could finance some interesting projects |
Maxim 11-Dec-2009 [4681x3] | actually, having a paypal account linked with your login and a "donate" button would be really nice :-) right in the chat tool. |
I sure would use it... some people have helped save days of work with free code and insight. | |
I'd gladly give back a few $ for their efforts | |
Reichart 11-Dec-2009 [4684] | Jack, Parse is my fav REBOL command. If I ever have time, this is the one funciton I would like to create hundreds of examples for in a Wiki. |
WuJian 11-Dec-2009 [4685] | newbie's solution,without PARSE: >> s2: {1 ''2 '3 4 ' '5 ''6 '7 8 9 '0'} >> replace/all s2 {''} {'} replace/all s2 {'} {''} print str 1 ''2 ''3 4 '' ''5 ''6 ''7 8 9 ''0'' >> str == s2 == true |
Maxim 12-Dec-2009 [4686x4] | I just adopted a new notation standard for parse rules... the goal is to make rules a bit more verbose as to the type of each rule token... I find this reads well in any direction, since we encouter the "=" character when reading from left to right or right to left... and parse rules often have to be read from right to left. example: =terminal=: [ =quote= copy terminal to =quote= skip (print ["found terminal: " terminal]) ] on very large rules, and with the syntax highlighting in my editor making the "=" signs very distinct, I can instantly detect what parts of my rules are other rules or character patterns... it also helps out in the declarations... I see when blocks are intended to be used as rules quite instantly where ever they are in my code. in my current little parser, I find I can edit my rules almost twice as fast and loose MUCH less time scanning my blocks to find the rule tokens, and switching them around. wonder what you guys think about it... |
another example.... in this dense block of text, I can spot the =eol= (end of line) token instantly in both x and y dimensions of the rule paragraph: =line-comment=: [ =comment-symbol= [ [thru =eol= (print "comment to end of line")] |[to end] ] (print "success") ] | |
when using rules in other contexts, they also stick out... =alphabet=: rejoin [=digit= =letter= bits "_"] here I immediately see that bits isn't a rule, but a function or a word. | |
with syntax highlighting it's quite amazing how bits stands out. ... in my editor at least. | |
Graham 12-Dec-2009 [4690] | use color instead :) |
Maxim 12-Dec-2009 [4691] | what do you mean color? |
Graham 12-Dec-2009 [4692x3] | Use an editor that colorises the words |
Gab uses the == in his literate editor .. | |
Chuck Moore uses color extensively in his color forth .. to replace other types of syntactic markup. | |
Maxim 12-Dec-2009 [4695x2] | syntax highlighting colorizes words ... stuff is colorized... but user words aren't colorised and they all get mixed up between functions, variables and rules... and having colors which are two strong next to each other and in relative distribution ... cancels out. |
stuff is colorized... (*in my editor*) | |
Graham 12-Dec-2009 [4697x2] | so you could write a parser that reads your rules and colorises them ... |
without the need for all those = signs everywhere | |
Maxim 12-Dec-2009 [4699] | but not while I'm coding... this is not for presentation, its for coding... I'm writing rules twice as fast now... just cause I'm not waisting time "searching" for the keywords within all of that text. |
Graham 12-Dec-2009 [4700] | exactly ... for coding. |
Maxim 12-Dec-2009 [4701] | unfortunately what you say isn't feasible, even if you can technically do it. who is going to program a parser to colorise code which is usefull for only one application? its actually going to take more time to write your color parser for each piece of code than write the code itself :-P so bottom line, Graham doesn't like this syntax. any others care to comment? |
Graham 12-Dec-2009 [4702] | Max, just do what ever suits you. |
Maxim 12-Dec-2009 [4703] | I'm just trying to get a feel for what others think about the idea. and sharing a bit of a discovery at the same time, if it may help others. the goal isn't to be popular or convince others... and sorry, if my last line may have looked harsh, it wasn't. :-) I was just resuming your reaction plainly and relaunching the question to be sure others realize I want a few opinions. |
Graham 12-Dec-2009 [4704] | it's not a syntax but a convention ... |
Maxim 12-Dec-2009 [4705] | true :-) |
PeterWood 12-Dec-2009 [4706] | any others care to comment? I'm afraid t looks very messy to me and reminded me of Perl for some reasion. |
Maxim 12-Dec-2009 [4707x2] | yay, I've got the BNF grammar done... its ripping through a C language BNF grammar definition... :-) now I've just got to make a parse rule emitter ... easy enough. |
(all in R3, but not using newer parse stuff, cause its not required) | |
Maxim 13-Dec-2009 [4709] | the new parse rejection system is VERY cool. ( can simplify the structure of some rules a lot :-) |
Gregg 13-Dec-2009 [4710] | For a long time I've added = to the end of my parse rules, and = to the beginning of parse variables. I think it matches the production rule grammar well, and also emulates set-word/get-word syntax. |
older newer | first last |