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

Parsing question

 [1/4] from: robert::muench::robertmuench::de at: 9-Aug-2001 19:56


Hi, in make-doc-pro I have a block of parsing rules like this: newline | "sometag" someaction | ... | paragraph paragraph: [copy para to newline] I would like to parse thru the chars of the paragraph as well, to perform some further actions. So I wold like to parse for a pattern like *bold*. Therefore I tried: paragraph: [ to "*" 1 skip copy boldtext "*" |copy para to newline] But this doesn't work, as the rule is only triggered once. Than I tried to add a 'some rule and expected the rule to "return" as soon as one of the given rules were used. paragraph: [ some [ to "*" 1 skip copy boldtext "*" 1 skip |copy para to newline] ] But this doesn't work too. How do I handle the parsing of a sequence in sub-rule to find some tags and act on these tags inside the sequence? Robert

 [2/4] from: g:santilli:tiscalinet:it at: 9-Aug-2001 21:41


[I'm giving Eudora a try, so I hope it won't create problems] At 19.56 09/08/01 +0200, you wrote:
>How do I handle the parsing of a sequence in sub-rule to find some tags >and act >on these tags inside the sequence? Robert
I'd suggest to describe the grammar of a line of text in more detail; this way you'll get the parse rule for free. Regards, Gabriele.

 [3/4] from: robert:muench:robertmuench at: 10-Aug-2001 18:30


> -----Original Message----- > From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]On Behalf Of
<<quoted lines omitted: 4>>
> I'd suggest to describe the grammar of a line of text in more detail; this > way you'll get the parse rule for free.
Hi, well ok here it is. Some parts are stripped to keep the mail lean. ;-- Text Format Language: rules: [some parts] parts: [ newline | "***" text-line (if title [alert reform ["Duplicate title:" text]] emit title text) | ["===" | "-1-"] text-line (emit-section 1) | ["---" | "-2-"] text-line (emit-section 2) | ["+++" | "-3-"] text-line (emit-section 3) ... ;--Defaults: | example (emit code trim/auto code) | paragraph (either title [emit para para][emit title title: para]) | skip ] paragraph: [copy para to newline] I would like to parse for special character sequences in the block up to the 'newline and handle them. The situation is that if 'paragraph is reached, no other rule out of 'parts has matched the input stream. My idea was to use the same approach as in 'parts paragraph: [ some [ "*" copy boldtext to "*" (handle-bold-text) | "_" copy underlinetext to "_" (handle-underline-text) | copy para to newline ] ] But this doesn't seem to work. I thought 'some tries as long as possible to apply a rule and only if it doesn't succeeds, control is given back to the parent-rule block. Robert

 [4/4] from: g:santilli:tiscalinet:it at: 13-Aug-2001 19:25


Hello Robert! On 10-Ago-01, you wrote: RM>> I'd suggest to describe the grammar of a line of text in RM>> more detail; this way you'll get the parse rule for free. RM> Hi, well ok here it is. Some parts are stripped to keep the RM> mail lean. [...] Sorry, I think I was not clear. I didn't mean you should provide us the rules in make-doc.r (they are available in the source anyway for all of us to look at). RM> I would like to parse for special character sequences in the RM> block up to the 'newline and handle them. The situation is What I meant was: if you are able to describe the grammar for a generic line with "special chaacter sequences" then you will easily get to the parse rule. I'll try with an example. We want to parse: "This is a *bold text*." I can describe the grammar for a string like that as "zero or more characters different from an asterisk, an asterisk, zero or more characters different from an asterisk, an asterisk, zero or more characters different from an asterisk". Turning it into PARSE rules: chars: complement charset "*" [any chars "*" any chars "*" any chars] Then we can add COPY to save the text: [copy normal-text any chars "*" copy bold-text any chars "*" copy normal-text any chars] This is of course a trivial example, but this way you should be able to solve your problem. Or maybe I'll have some free time in the next days and will try to come up with something. Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted