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

[REBOL] Re: Parsing Exercise

From: SunandaDH::aol::com at: 4-Sep-2005 3:29

> I posted a REBOL version, but I'm not terribly gifted at writing > parse rules. I'd be curious to see how other REBOLers might handle it.
Just saw your message this morning -- or some reason it's on the archive but didn't make it to my inbox. It's never clear just how much validation should be involved in an exercise like this. Should we be handling invalid cases where the last group does not contain a number? If the answer to that is no, then the code can be very simple - just need to find and increment the last string of digits. In fact, it can be simpler than below as my code is not a pre-parse solution. But it works, and that's usually as far as I take things. bump-id: func [id [string!] /local number number-copy digit digits ][ digit: charset "0123456789" digits: [some digit] id: head reverse id parse/all find id digit [copy number digits] number-copy: 1 + to-integer head reverse copy number replace id number head reverse form number-copy id: head reverse id return id ] Sunanda.