r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Parse] Discussion of PARSE dialect

Pekr
22-Jun-2005
[232x3]
I used csv = semicolon separated values and no quotes in-there ...
yes, it is, as I expect all lines having 7 elements ... once there 
is not such an element, I can't loop thru result ... well, one condition 
will probably solve it, but imo it is a gug .... rebol identifies 
;; and puts "" inthere, but csv, at the end, will use "value;", and 
rebol does not count that ...
gug = bug :-)
Gabriele
22-Jun-2005
[235]
hmm, either use append/only, or as you say add it manually. submit 
this example to rambo if you think it's a bug.
Pekr
22-Jun-2005
[236x2]
append/only will not help, result of parse will varry, and it should 
not ...
I will put that in RAMBO then ...
Gabriele
22-Jun-2005
[238]
append/only will, because pick returns none if a column is not present, 
and set works with that too
Pekr
22-Jun-2005
[239]
but I like to use flat structure and foreach [real name of vars here], 
so I need consistent record length :-)
Gabriele
22-Jun-2005
[240]
i do too usually, just suggesting an alternative :-)
Pekr
22-Jun-2005
[241]
hmm, if (length? tmp) <> 7 [append tmp ""] will hopefully help :-)
Allen
22-Jun-2005
[242]
Pekr for now, just add an extra "," as you parse each row. That will 
give you a consistent length with the current behaviour
Pekr
22-Jun-2005
[243]
oh no, I am at the ends ... so bye bye beautifull oneliners ... I 
just found item which contains set of quotes :-) rebol will not translate 
that and my block is confused once again :-)
Allen
22-Jun-2005
[244]
foreach line ln-tel-list [append result parse/all join line ";" ";"]
Pekr
22-Jun-2005
[245x3]
damned, I will delete that contact and I will be done ;-) One contact 
from 3 000 does not count, even if that is secreatery of general 
director :-)
thanks allen, might work ....
but still - should I fill RAMBO bug? Imo rebol should add empty quotes 
automatically, if the line ends with ;
Allen
22-Jun-2005
[248]
Put it in for Carl to decide. Mention the work around too
Pekr
22-Jun-2005
[249x2]
why are following quotes causing a trouble? I did not ask rebol to 
take them into accout?

parse/all {test1    ;test2;"test3   "quoted""} ";"

["test1     " "test2" "test 3 " {quoted""}]

that is really completly weird ...
the only delimiter I asked rebol to use was semicolon, so everything 
following test2; should be one element ...
Allen
22-Jun-2005
[251x2]
That's a good one for the parse/all test suite. Rambo it.
; same bug again here too.
parse/all {a: b ":" c} ":"
== ["a" { b "} " c"]
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 "^/^/"