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

[REBOL] Re: More Parsing questions

From: lmecir:mbox:vol:cz at: 7-Sep-2001 10:24

You can try this: to-rule: function [ {generate a to A parse rule} a [block!] ] [cont finish] [ reduce [ 'any reduce [ reduce [ a to paren! [cont: [to end skip] finish: []] '| to paren! [cont: [] finish: [to end skip]] 'skip ] 'cont ] 'finish ] ] comment { Example #1: to-space-or-br: to-rule [" " | "<br>"] result: "" parse/all "aa" [to-space-or-br copy result to end] probe result parse/all "a a<br>" [to-space-or-br copy result to end] probe result parse/all "ab<br> " [to-space-or-br copy result to end] probe result Example #2: digit: charset [#"0" - #"9"] four-digit: [4 digit] to-four-digit: to-rule four-digit tfd: [to-four-digit copy fd four-digit to end] parse/all "abcd 1234" tfd probe fd ; == "1234" } Regards Ladislav P.S. Other functions that may be of some use are: a-b: function [ {Generate an A-B parse rule} a [block!] b [block!] ] [finish] [ reduce [ reduce [ b to paren! [finish: [to end skip]] '| to paren! reduce [first [finish:] a] ] 'finish ] ] comment { Example: a: [any "a" "b"] b: ["aa"] parse "ab" a-b a b parse "aab" a-b a b } not-rule: function [ {Generate a not A parse rule} a [block!] ] [finish] [ reduce [ reduce [ a to paren! [finish: [to end skip]] '| to paren! [finish: []] ] 'finish ] ] comment { Example: a: [any "a" "b"] parse "ab" not-rule a parse "b" not-rule a parse "" not-rule a }