Hi All,

My erebol script for embedded rebol in text (XML, HTML) etc. for web server 
use to out-everything JSP, ASP, SSI and PHP has been rewritten by Ernie.

The actual erebol parsing has been reduced dramatically. What have we 
learned? Complex rules (the one with subrules) first in parsing! Otherwise 
matches may not occur while parsing. 

If you inline the parse stuff it can be reduce to one line.

See below....

--Maarten


REBOL
[
  Title: {eRebol embedded rebol code evaluator.}
  Author: {Maarten Koopmans, Ernie van der Meer}
  Comment: {Added console capturing, thanx to dockimbel.
    So... now with /as-string refinement. Rewrite by Ernie.}
]

ctx-console-capture: context
[
  out: none
  sys-print: get in system/words 'print
  sys-prin:  get in system/words 'prin

  set 'get-captured does [out]

  print-out: func [value][append out reform [reduce value newline]]
  prin-out:  func [value][append out reform value]

  set 'capture func
  [
    {Capture console output}
    flag [logic!]
  ]
  [
    either flag
    [
      out: copy {}
      set 'print :print-out
      set 'prin :prin-out
    ]
    [
      set 'print :sys-print
      set 'prin  :sys-prin
    ]
  ]
]

erebol: func
[
  {Preprocesses a text file and evaluates all rebol code between
   <% and %> tags. Everything that is printed is visible in the output.
   Who needs PHP?}
  content [file! string!] {The content to erebol}
  /as-string {Return the processed content as a string}
  /local text comment-rule exec-rule code other
]
[
  if as-string [ capture on ]
  text: either file? content [read content][copy content]

  comment-rule: [ "<%#" thru "%>" ]
  exec-rule: [ "<%" copy code to "%>" thru "%>" ]

  ; Parse input text, skipping comments, executing code and printing
  ; whatever other stuff we run into.
  parse/all text [
    any
    [
      comment-rule
      | exec-rule (error? try reduce [ 'do code ])
      | copy other skip (prin other)
    ]
  ]

  if as-string
  [
    capture off
    return get-captured
  ]
]
-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to