World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Rebolek 1-Mar-2006 [863] | Thanks Oldes, that should help me |
Oldes 1-Mar-2006 [864x2] | Volker: blocks |
it's much more easier as you can use Rebol's datatypes | |
Volker 1-Mar-2006 [866] | i thought about something like "js-load string" which would do the comma-conversion. But if your dialect works, no need for extra work. |
Rebolek 1-Mar-2006 [867] | maybe fixing REBOL should be better? If "." can work without problem, why not "," ? |
Volker 1-Mar-2006 [868] | interesting question why it is left out. but you would have other problems too, although not that often. like "\"". in rebol that is "\" " . in javascript "^"" |
Rebolek 1-Mar-2006 [869] | Volker this is some special case, you can replace that before parsing string, but you cannot replace all commas in action script, some of them may be parts of string |
Rondon 2-Mar-2006 [870x2] | Does anybody have an script to parse BNFs? |
BHF's specification.. | |
Gregg 3-Mar-2006 [872] | I think Bretty Handley did. Check codeconscious. |
Rebolek 5-Mar-2006 [873] | I think this should print 5 and return 'true. But it does not. >> parse [1 2 3 4 5][any number! set val number! (print val)] == false Help please? :) |
Anton 5-Mar-2006 [874x2] | >> parse [1 2 3 4 5][any [set val number!] (if value? 'val [print val])] 5 == true |
What you did was consume the five numbers, then try to set val to a sixth one. | |
Rebolek 5-Mar-2006 [876] | What I want is work with first four numbers and not with the last one |
Anton 5-Mar-2006 [877] | Is it always 5 numbers ? |
Rebolek 5-Mar-2006 [878] | No :( |
Anton 5-Mar-2006 [879] | >> parse [1 2 3 4 5][4 [set val number! (print val)] number!] 1 2 3 4 == true |
Rebolek 5-Mar-2006 [880] | Actually, the real elements may be very different. I just simplified the example. |
Anton 5-Mar-2006 [881] | Ok, so you don't know how many numbers you have until you fail to find another one. |
Rebolek 5-Mar-2006 [882] | I want to process all elements excluding the last one. |
Anton 5-Mar-2006 [883] | And do you want to avoid putting them into a block first ? |
Rebolek 5-Mar-2006 [884] | They are in block already |
Anton 5-Mar-2006 [885x2] | Actually, you can do it like this: |
>> parse [1 2 3 4 5][any [set val number! pos: number! (print val) :pos] number!] 1 2 3 4 == true | |
Rebolek 5-Mar-2006 [887] | Interesting, that should probably work, thanks! |
Anton 5-Mar-2006 [888x3] | Welcome. |
Actually, the last number! can probably become opt number! | |
for the case when there are no numbers at all. | |
Rebolek 5-Mar-2006 [891] | there is at least one. I f theres at least one, don't do any action. If there are two do one action and so on. |
Anton 5-Mar-2006 [892x2] | Ok, that should be ok then. |
Man, I wish you could do: parse [1][integer! -1 skip] and arrive back at the head of the input. | |
Oldes 5-Mar-2006 [894x2] | infinitive loop? |
(infinite) | |
Geomol 5-Mar-2006 [896x2] | Another possible way: >> parse [1 2 3 4 5] [any [set val number! pos: (if not tail? pos [print val])]] |
Anton, you can do: >> parse [9] [integer! to 1] and arrive back at the beginning. | |
Anton 6-Mar-2006 [898] | Oh yes! forgot about that. :) Great ! |
sqlab 6-Mar-2006 [899x2] | Can you explain this curious results ? REBOL/View 1.3.2.3.1 5-Dec-2005 Core 2.6.3 >> parse [1 2 3 4][any [number! set val number!] (print val)] 4 == true >> parse [1 2 3 4 5 ][any [number! set val number!] (print val)] 4 == false >> parse [1 2 3 4 5 6][any [number! set val number!] (print val)] 6 == true >> parse [1 2 3 4 5 6 7][any [number! set val number!] (print val)] 6 == false >> parse [1 2 3 4 5 6 7 8][any [number! set val number!] (print val)] 8 == true note the results with odd numbers of items! |
Forget my question. I see that the block tries to consume two items.( | |
Anton 6-Mar-2006 [901] | :) |
Geomol 6-Mar-2006 [902] | 'parse' is the path to great explorations and inventions - and also to great confusion and maybe despair. ;-) No really, it can be a bit confusing at times, but I guess, it can't be done otherwise to have such great functionality. There's no short cut with 'parse'. Learning by doing is the way to go. And it's a brilliant tool! |
sqlab 6-Mar-2006 [903x2] | So it is parse [1 2 3 4 b 5][ some [ set val number! v: number! :v (print val)] to end (?? val)] |
too late.( | |
Oldes 7-Mar-2006 [905x4] | Maybe someone will find this usefull: |
count-word-frequency: func[ "Counts word frequency from the given text" text [string!] "text to analyse" /exclude ex [block!] "words which should not be counted" /local counts f wordchars nonwordchars ][ counts: make hash! 100000 wordchars: charset [#"a" - #"z" #"A" - #"Z" "̊؎ύѪ"] nonwordchars: complement wordchars parse/all text [ any nonwordchars any [ copy word some wordchars ( ;probe word if any [not exclude none? find ex word][ either none? f: find/tail counts word [ repend counts [ word 1 ] ][ change f (f/1 + 1) ] ] ) any nonwordchars ] ] counts: to-block counts sort/skip/compare/reverse counts 2 2 new-line/skip counts true 2 ] | |
If you know some other chars, which should be included in the words, please let me know, now it should be complete for czech language and hope that for spanish too (as I use it to count spanish words:). | |
found missing czech chars-> wordchars: charset [#"a" - #"z" #"A" - #"Z" "̊؎ύѪ"] | |
Oldes 13-Mar-2006 [909] | Is this a bug? parse/all {"some words"} {" } ;== ["some words"] parse/all {and "some words"} {" } ;== ["and" "some words"] parse {and "some words"} {" } ;== ["and" "some" "words"] parse {"some words"} {" } ;== ["some words"] |
Geomol 13-Mar-2006 [910] | Good question! It's in a tough corner of REBOL - parsing. REBOL is in many ways more like a human language, than a computer language. Strictly speaking, you can argue, that those examples have a bug or two, but can you live with it? The behaviour might make it difficult to parse input strings, written by humans, because people write all sorts of things. (If it can go wrong, it will.) Try change the quotation marks to something else and see the results change, like: >> parse/all {Xsome wordsX}{X } == ["" "some" "words"] |
Gabriele 13-Mar-2006 [911] | parse, without a rule, treats quotes specially. this is to allow parse to be used directly with things like csv data. |
Oldes 14-Mar-2006 [912] | I think it's a bug! I was trying to use this to divide large string to words and found that I have all sentences inside , instead of just words. It's problem only if you have the divider on the edge. |
older newer | first last |