Documention for: parse-analysis-view.r
Created by: brett
on: 18-Dec-2004
Last updated by: brett on: 6-Mar-2013
Format: html
Downloaded on: 30-Apr-2025
Parse Analysis Toolset /View
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).
- 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.
- 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.
- 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.
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]
- 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.
- 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.
Brett Handley started programming REBOL early 2000 and maintains a site of REBOL information and scripts at:
http://www.codeconscious.com/rebol/