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

[REBOL] Re: how to parse thru nested parens?

From: nitsch-lists:netcologne at: 11-Dec-2001 15:01

RE: [REBOL] how to parse thru nested parens? Hi Pekr [petr--krenzelok--trz--cz] wrote:
> Hi, > > I am building sms system and I would like to trace following occurance: > > comand(text info or parameters) > > however, I wold like following to be parsed correctly, so ignoring > nested parens, e.g.: > > command(some params(some subparams), maybe some other params) > > Thanks a lot, >
see %parse-code.r in the script-library: REBOL [ Title: "Parse REBOL Source" Author: "Carl Sassenrath" File: %parse-code.r Date: 30-May-2000 Purpose: {An example of how to parse REBOL source code.} Category: [script util text 2] ] parse-code: func [ "Parse REBOL source code." text /local str new ] [ parse text blk-rule: [ some [; repeat until done str: newline | #";" [thru newline | to end] new: (probe copy/part str new) | [#"[" | #"("] blk-rule | [#"]" | #")"] | skip (set [value new] load/next str probe :value) :new ] ] ] i think your parsing has to replace the [skip ..]-part. beware, this is recursive and parse has no local variables for that. so real processing needs some workaround. whats the best way to to this? based on this is a pretty-printer %clean-script.r and a colorizer %color-code.r there. note there seems to be an bug in the parser, triggered by long rebol-scripts in %clean-script.r . starts doubling "[" to "[[" with the scripts rest, and nobody knows why. i replaced the 'some with 'any, now it runs stable. but it does not warn anymore if parents are unbalanced.
> Cheers, > -pekr- >