1

I want to be able to parse between 2 marks in parse rule. For a contrieved example:

src: {a b c d e f}

rule: [
    to "b" mark1: thru "e" mark2: 
    to mark1 copy text to mark2
]

This doesn't work, text contains "[" instead of what I'd like to get:

b c d e
user310291
  • 36,946
  • 82
  • 271
  • 487

2 Answers2

3

You're trying to implement a "DO desire" of copying using PARSE. PARSE's COPY is looking for patterns, not treating the series as positions.

You can escape into DO in mid-parse via a PAREN!, it will run if the parse rule reaches that point.

src: {a b c d e f}

rule: [
    to "b" mark1: thru "e" mark2: 
    (text: copy/part mark1 mark2)
    to end ;-- not strictly necessary, but makes PARSE return true
]

parse src rule

That will give you text as b c d e

Note that you can't have it both ways, either with COPY or with TO. TO <series!> meant "look for b", not "jump to the position of b". So when you say to mark1 you're invoking another match. If you want to set the parse position to the specific position recorded in mark1, use :mark1 in the parse rule.

  • as I said it's a contrieved example. so I updated the example where I have markers: at first div and closing div with nested div inside. – user310291 Apr 29 '18 at 15:02
  • @user310291 If you would like to ask a new question, it's usually better to just do that...and be sure to be as clear as possible when you do. – HostileFork says dont trust SE Apr 29 '18 at 15:28
  • ok see https://stackoverflow.com/questions/50088909/rebo-red-parse-is-it-possible-to-copy-between-two-marks-embedding-nested-div – user310291 Apr 29 '18 at 16:33
1

two alternative solutions/rules working in Red

rule: [
   to "b" copy text thru "e" to end
]

and

 rule: [ to "b" collect  [keep thru "e"] to end]
 text: first parse src rule
sqlab
  • 6,412
  • 1
  • 14
  • 29