Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Parsing question

From: gscottjones:mchsi at: 14-Apr-2003 7:00

From: "Serge Gilette"
> ... I have a parsing question. I am trying to parse a > string of PGN format. it is the formalize way to notee > a chess game, for those who don't know.
I didn't know that. Thanks!
> I want to explicitly say that the space or the newline can end some > sub-pattern. But i have an error message if i use the commented line > below...
rest of posting: Hi, Serge, I am no expert on parsing. I am trying to get better, so yours was an interesting problem. If I recall correctly, one cannot use the parse word to with charsets, hence the continual errors. I had to hunt and peck myself to figure this one out, but the following seems to work. I also added a bit more to the rules to be sure the last move was parsed. I am sure that a real parse guru will show *the best way* to do it also. HTH! --Scott Jones digit: charset [#"0" - #"9"] space: #" " crlf: #"^/" spacer: [to space | to crlf | to end] round_number: [copy x some digit #"." (print join "tour=" x)] round_played: [copy y spacer (print join "played=" y)] round_comment: [#"{" copy comm to #"}" (print comm) spacer] round: [round_number round_played round_played opt round_comment] game: [some round] rules: [game to end] parse "1.d3 d5 2.Nf3 Nf6 3.Bd2 c5 4.g3 Nc6 {a comment} 5.Na3 e6 6.b3 Be7" rules