World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Romano 15-Sep-2005 [389] | or a: 19 append/only [] to-paren compose [append w (join "the b value is " a)] |
Ingo 15-Sep-2005 [390x3] | You _just_ beat me to it ... |
;-) | |
Forgot to use /only on first try | |
Josh 15-Sep-2005 [393] | Thank you Romano and Ingo |
Graham 21-Sep-2005 [394] | How do you parse for a particular integer value ? parse [ -1 ] [ integer! ] but I want parse [ 1] to fail ... |
Geomol 21-Sep-2005 [395x2] | you can do it as a string: >> parse form [-1] ["-1"] == true >> parse form [1] ["-1"] == false |
but as a block... hmmm | |
Gabriele 21-Sep-2005 [397] | >> parse [-1] [1 1 -1] == true >> parse [1] [1 1 -1] == false |
Geomol 21-Sep-2005 [398x2] | lol How did you do that? Why does it work? :-) |
ah of course. Number of instances (1 1 means exactly 1, right?). | |
Graham 21-Sep-2005 [400] | tricky :) |
Geomol 21-Sep-2005 [401x3] | >> parse [1 1 1 1] [1 4 1] == true >> parse [1 1 1 1] [1 3 1] == false |
Putting numbers in the rule block indicates number of something. So [1 4 1] means 1 to 4 times 1. | |
Easier to see this way: >> parse [a a a a] [1 4 'a] == true >> parse [a a a a] [1 3 'a] == false | |
JaimeVargas 21-Sep-2005 [404] | Shouldn't? parse [1][1] ;== true |
Geomol 21-Sep-2005 [405x2] | So if you wanna check for exactly one time -1, you write [1 1 -1]. |
Jaime, when you put a number in, it's the start of a min/max indicator. You never type max or what to search for, so it fails. | |
Graham 21-Sep-2005 [407] | well, apparently numbers are not literals when parsing ... |
Geomol 21-Sep-2005 [408] | Same as >> parse [1] [] == false |
Graham 21-Sep-2005 [409] | must add this to the wikibook :) |
Geomol 21-Sep-2005 [410x2] | >> parse [-1 -1] [2 -1] == false >> parse [-1 -1] [2 2 -1] == true |
The first doesn't give meaning to parse, because a number means a min, so parse look for a max, and then the data. | |
JaimeVargas 21-Sep-2005 [412x3] | A bit consusing. Maybe we should express ranges differently. |
Maybe with an issue. | |
#1-4 | |
Geomol 21-Sep-2005 [415x2] | Then that needs to be parsed too. >> i: #1-4 == #1-4 >> i/1 == #"1" >> i/2 == #"-" >> i/3 == #"4" But I could have written: #001-00004 >> parse [1 1 1] [001 00004 1] == true |
I think, Carl likes to keep it short. :-) | |
JaimeVargas 21-Sep-2005 [417] | What about a pair for ranges. |
Geomol 21-Sep-2005 [418] | Yes, that is better. |
JaimeVargas 21-Sep-2005 [419] | literals can help sometimes. But then the problem becomes that pair literal could have the same problem than number literal has now. |
Geomol 21-Sep-2005 [420] | But then this will give problem: >> parse [1x2] [1x2] == true |
JaimeVargas 21-Sep-2005 [421x3] | Yep. |
But parse [1][1] ;== false (seems odd). | |
Maybe rebol needs a literal representation for ranges. | |
Geomol 21-Sep-2005 [424] | yes, but if you changed min/max to a pair, then parse [1x2][1x2] wourld fail. |
JaimeVargas 21-Sep-2005 [425x3] | I understand. I just suggesting that the parse dialect could be further optimized. |
Or enhanced. | |
But I guess adding extra syntax still get us in trouble. | |
Graham 21-Sep-2005 [428x2] | I guess block parsing is by datatypes and not Rebol values. |
except for words .. hmm... confusing. | |
BrianH 22-Sep-2005 [430] | But numbers are literals when parsing. It's just that they're syntax too, at least in parse rules. |
Ladislav 22-Sep-2005 [431x2] | hi all, this is an "old" issue Graham: it is in REP for quite a long time |
(together with my suggestion how to solve it) | |
Graham 22-Sep-2005 [433] | where on REP ? |
Ladislav 22-Sep-2005 [434x3] | let me look |
One place is this: http://www.compkarori.com/vanilla/display/TO%2C+THRU+And+NOT+PARSE+Rules , but I think, there was more | |
then I found this: http://www.rebol.net/list/list-msgs/32392.html | |
Graham 22-Sep-2005 [437] | LIT, or LITERAL would be good. |
Ladislav 22-Sep-2005 [438] | and one more: http://www.fm.vslib.cz/~ladislav/rebol/rep.html |
older newer | first last |