World: r3wp
[Parse] Discussion of PARSE dialect
older newer | first last |
Pekr 22-Jun-2005 [253] | OK, submitting ... |
Allen 22-Jun-2005 [254] | ; would have expected == ["a" { b "} {" c}] |
sqlab 23-Jun-2005 [255] | I just remember, that this was discussed already. The solution was to use something like split: func [string delim /local tokens token] [ tokens: make block! 32 parse/all string [ any [copy token to delim (append tokens probe token) delim] copy token to end (append tokens token) ] tokens ] |
Vincent 23-Jun-2005 [256] | sqlab: if 'parse can't do it, 'parse can do it ;) |
Alek_K 6-Jul-2005 [257x3] | I have "(name1) - (name2) (result)" |
eg. {team one - team two 3,0-3,0} Any simple solution to split it ["team one" "team two" "3,0-3,0"]? | |
I've done such a rule: [copy x to "-" (team1: x) - any " " copy x to " " (team2: x) any [mark: alpha :mark copy x to " " (append team2 join x " ")] any " " x: digit to end (result: x)] | |
Chris 6-Jul-2005 [260x3] | How many possibilities are there for the values "team one" and "team two"? Could you use a team repository? -- |
teams: ["team one" | "team two"] chars-n: charset "0123456789" points: [1 4 chars-n "," 1 4 chars-n] score: [points "-" points] parse str [teams "-" teams score] | |
str: {team one - team two 3,0-3,0} ;-- natch | |
Tomc 7-Jul-2005 [263x2] | not really simple but: name: complement charset {1234567890-} score: [integer! "," integer! "-" integer! "," integer!] str: {team one - team two 3,0-3,0} rst: copy [] parse/all str [ 2 [copy token some name(append rst trim token) opt "-"] copy token score (append rst token) ] rst |
of course this would preclude names like "team were#1" | |
Alek_K 7-Jul-2005 [265] | Thank You, it's nice to see such a pretty solutions :) |
Ingo 3-Aug-2005 [266] | What are the recursion limits on 'parse? Because I just hit it in the imap:// protocol ... |
Rebolek 3-Aug-2005 [267x2] | Ingo I made simple test and it seems it's something like 512 |
x: copy [] loop 1000 [append x 1] i: 0 rule: [number! (i: i + 1 print i) rule] parse x rule | |
Ingo 3-Aug-2005 [269x2] | <Slaps his head> Thanks! I could have thought about just trying it myself ;-) |
Well, I'll have to try to rewrite the parse rules, then. 512 is by far not enough in this case. | |
Tomc 3-Aug-2005 [271x2] | the parse limit it will vary with platform |
arrg not awake ... recursion limit | |
Ingo 3-Aug-2005 [273] | make that parse recursion limit, the limit on recursions for functions is a _lot_ higher (at least on winxp, view 1.3.1) |
shadwolf 13-Aug-2005 [274x2] | I have some problems to translate RULE based on PERL regular expression to rebol parse rules. Maybe this group can help me. For example: PERL REGULAR EXPRESSION RULE: [[ c ]] (e|è|é|ê|i|î|y) -> s we need to match the #"c" char and test the next char to know if we trap S phonem. example "Ce" must be emited S et E. I plan to have 2 rules rule: [ .../... "c" etc... | "e" etc... ] More complicated rule: an [[ c ]] T -> like for "banc" |
CLASS V [aeiouàâéèêëîïôöùûü] # voyelles CLASS C [bcçdfghjklmnñpqrstvwxyz] # consonnes CLASS L (V|C) # toutes les lettres CLASS P [\,\.\;\:\!\?] # ponctutions CLASS N [0123456789] # chiffres CLASS W [_&\']+ # espace CLASS S (^|W|P) # limite gauche d'un mot CLASS T ($|W|P) # limite droite d'un mot | |
Volker 13-Aug-2005 [276x2] | s: "Hello cè World" es: charset[#"e" #"è"#"è"#"ê"#"i"#"î" #"y"] parse/all s [ to "c" p: skip es p2: ( p: change/part p "s" p2 ) :p ] ? s |
questions: -long string? then better copy instead of change/part -more patterns in same path, then not 'to. | |
shadwolf 13-Aug-2005 [278] | Volker that's not what I want to get ... I'm seeking a rebol ruke that allow me to test the character after a key char example #"c" but keeping it into the parsing stack |
Volker 13-Aug-2005 [279] | you know p: and :p in parse-rules? |
shadwolf 13-Aug-2005 [280] | k I will try it thank u :) |
BrianW 13-Aug-2005 [281] | yargh. I know how to split with a single character as the delimiter: chunks: parse/all text "^/" How do I split where a blank line (2 newlines with nothing in between) is the delimiter? The naive solution I can think of just doesn't work: chunks: parse/all text "^/^/" |
Graham 13-Aug-2005 [282x2] | you can make up a rule. |
lines: copy [] rule: [ copy txt to "^/^/" (append lines txt) skip 2 ] parse mytext [ some rule ] untested ... | |
BrianW 13-Aug-2005 [284] | I get lost trying to find a good way to describe my rule. Here's the bad code that states my intent, but doesn't work ('parse doesn't seem to like having that 'until in there) chunks: parse/all text [ until [ chunk: copy "" copy chunk to "^/^/" skip if chunk [ append chunks chunk ] ] ] |
Graham 13-Aug-2005 [285] | ummm.. don't think you can do that |
BrianW 13-Aug-2005 [286] | nope, I discovered that :-D |
Graham 13-Aug-2005 [287x4] | parse expects to see a parse dialect if you following it with a block |
try my way ... | |
and your code is mixing rebol code with the parse dialect. | |
Rebol code has to be in ( ) when used within the dialect | |
BrianW 13-Aug-2005 [291] | oh okay. I understand that now. |
Graham 13-Aug-2005 [292] | that should be parse/all mytext [ some rule ] |
BrianW 13-Aug-2005 [293] | thanks |
Graham 13-Aug-2005 [294] | np |
BrianW 13-Aug-2005 [295x2] | Hm. Still having issues: >> rule: [ copy chunk to "^/^/" (append lines chunk) skip 2 ] == [copy chunk to "^/^/" (append lines chunk) skip 2] >> text: "Dude.^/^/Sweet!^/" == "Dude.^/^/Sweet!^/" >> lines: copy [] == [] >> parse/all text rule ** Script Error: Invalid argument: ** Near: parse/all text rule >> |
oh, wait. | |
Graham 13-Aug-2005 [297] | oops .. should be "2 skip" and not "skip 2" |
BrianW 13-Aug-2005 [298x2] | That's okay, I forgot to include the possibility that there would be only one line, so my tests were blowing up somewhere else. |
Hm, that misses the last line if the text doesn't end in "^/^/" | |
Graham 13-Aug-2005 [300] | easy enough .. add {^/^} to end of text before parsing |
BrianW 13-Aug-2005 [301x2] | That *is* a nice and easy solution, thanks a lot! |
sweet, all my tests pass now. Time to add more tests :-) | |
older newer | first last |