Documention for: parse-analysis-view.r Created by: brett on: 18-Dec-2004 Last updated by: brett on: 6-Mar-2013 Format: text/editable Downloaded on: 29-Mar-2024 Parse Analysis Toolset /View ===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). ===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. ===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. ===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. ---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-in xml rules of REBOL. That is why the BIND is used below. ; An old xml example xml: { Star Trek: Insurrection Patrick Stewart Brent Spiner MonoPlex 2000 14:15 16:30 18:45 21:00 Bigscreen 1 19:30 } rules: bind [ element name content attribute attr-value ] xml-language visualise-parse xml rules [parse-xml xml] ---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. +++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. ===About the script author Brett Handley started programming REBOL early 2000 and maintains a site of REBOL information and scripts at: =url http://www.codeconscious.com/rebol/ http://www.codeconscious.com/rebol/