Script Library: 1180 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: brett

Documentation for: parse-analysis-view.r


Parse Analysis Toolset /View

1. What is this for?

Uses REBOL/View to visualise the results of Parse. Currently provides a View representation on the results from the Tokenise-parse (see parse-analysis.r script and documentation).

2. Why is it useful?

  • It shows you at a glance the parts of your input that match your parse rules.
  • It allows you to navigate through the input, a parse event at a time.

3. What is in the script?

  • Scroll-Panel VID style to implement a scrolling area. This has been published before.
  • Highlighted-Text VID style to highlight sections of text with different colours.
  • Make-Token-Stepper function that creates a layout face that you view to see your results. This is the one you'll want to use.
  • Make-Token-Highlighter function that creates a layout face that you view to see your results. This is practically obsolete now.

4. How do you use it?

  • The script starts by calling a function I have set in my REBOL environment called SCRIPT-MANAGER. Here's a simplified stand-in for that function you can use - just put it in your calling script:
        if not value? 'script-manager [
            script-manager: func ['word /local needs][
                if any [
                    :word <> 'do-needs
                    none? in system/script/header 'needs
                    none? needs: system/script/header/needs
                ][return]
                if not parse needs: compose [(:needs)] [some file!][make error! {Expected a NEEDS block consisting of file!.}]
                foreach [file] needs [do file]
            ]
        ]
  • You need the parse-analysis.r in the same directory.
  • Call Visualse-parse.
  • Click the on the input, the buttons and use your mouse to visually analyse your data. All the navigation controls are described in the comments of the script.

4.1 Example

Here we specify the parse rules and the text.

    mygrammar: context [
        alpha: charset [#"A" - #"Z" #"a" - #"z"]
        digit: charset {0123456789}
        word: [some alpha]
        number: [some digit]
        main: [
            some [word | number | skip]
        ]
    ]
    text: {Word 123 +=+ 45 End}
    visualise-parse/ignore text mygrammar [parse/all text mygrammar/main] [alpha digit]

Another example. In this example we are going leverage the built-inxml rules of REBOL. That is why the BIND is used below.

    ; An old xml example
    xml: {<movie>
        <title>Star Trek: Insurrection</title>
        <star>Patrick Stewart</star>
        <star>Brent Spiner</star>
        <theater>
            <theater-name>MonoPlex 2000</theater-name>
            <showtime>14:15</showtime>
            <showtime>16:30</showtime>
            <showtime>18:45</showtime>
            <showtime>21:00</showtime>
            <price adult="8.50" child="5.00" />
        </theater>
        <theater price="6.00">
            <theater-name>Bigscreen 1</theater-name>
            <showtime>19:30</showtime>
        </theater>
    </movie>}

    rules: bind [
        element name content attribute attr-value
    ] xml-language

    visualise-parse xml rules [parse-xml xml]

4.2 What should I do with these examples?

  • Try moving the highlight around by using the arrow keys and buttons at the top.
  • Green represents a rule success, red a rule failure, and orange means the rule is about to be tested.
  • Hold Ctrl and hit Home to go to the start again. Try using a Ctrl Mouse click in the text.
  • Read the navigation control comments in the script for more information.

4.2.1 Thinking about what you are seeing

  • It is important to realise that this program does not understand xml. It just displays some results by the parse-analysis script.
  • The example shows how a given set of parse rules (in this case the built-in REBOL xml rules) can be understood when overlayed on some input.
  • Using this program you can see the structure of input when given some parse rules. The rules give the input structure. A different set of rules would show a different structure.

5. About the script author

Brett Handley started programming REBOL early 2000 and maintains a site of REBOL information and scripts at:

http://www.codeconscious.com/rebol/