diff options
Diffstat (limited to 'txr.1')
-rw-r--r-- | txr.1 | 329 |
1 files changed, 1 insertions, 328 deletions
@@ -67155,335 +67155,8 @@ that is located in the same directory. .brev .SH* DEBUGGER -\*(TX has a simple, crude, built-in debugger. The debugger is invoked by adding -the -.code -d -command line option to an invocation of \*(TX. -In this debugger it is possible to step through code, set breakpoints, -and examine the variable binding environment. - -Prior to executing any code, the debugger waits at the -.code txr> -prompt, allowing for the opportunity to set breakpoints. - -Help can be obtained with the -.code h -or -.code ? -command. - -Whenever the program stops at the debugger, it prints the Lisp-ified -piece of syntax tree that is about to be interpreted. -It also shows the context of the input being matched. - -The s command can be used to step into a form; n to step over. -Sometimes the behavior seems counter-intuitive. For instance stepping -over a -.code @(next) -directive actually means skipping everything which follows -it. This is because the query material after a -.code @(next) -is actually child -nodes in the abstract syntax tree node of the -.code next -directive, whereas the surface syntax appears flat. - -The following is an example of the debugger being applied to a web scraping program -which connects to a US NAVY clock server to retrieve a dynamically-generated -web page, from which the current time is extracted, in various time zones. -The handling of the web request is done by the wget command; the -\*(TX query opens a wget command as and scans the body of the HTTP response -containing -HTML. This is the code, saved in a file called navytime.txr: - -.verb - @(bind url "http://tycho.usno.navy.mil/cgi-bin/timer.pl") - @(next (open-command `wget -c @url -O - 2> /dev/null`)) - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final"//EN> - <html> - <body> - <TITLE>What time is it?</TITLE> - <H2> US Naval Observatory Master Clock Time</H2> <H3><PRE> - @(collect :vars (MO DD HH MM SS (PM " ") TZ TZNAME)) - <BR>@MO. @DD, @HH:@MM:@SS @(maybe)@{PM /PM/} @(end)@TZ@/\t+/@TZNAME - @ (until) - </PRE>@/.*/ - @(end) - </PRE></H3><P><A HREF="http://@(skip)"> US Naval Observatory</A> - - </body></html> - @(output) - @ (repeat) - @MO-@DD @HH:@MM:@SS @PM @TZ - @ (end) - @(end) -.brev - -This is the debug session: - -.verb - $ txr -d navytime.txr - stopped at line 1 of navytime.txr - form: ((bind url "http://tycho.usno.navy.mil/cgi-bin/timer.pl")) - depth: 1 - data (1): - nil - txr> s -.brev - -Control stops on the first line of the script. The -.code form: -line output by the debugger shows the internal syntax. -The user issues the -.code s -command to step: - -.verb - stopped at line 2 of navytime.txr - form: ((next (open-command `wget -c @url -O - 2> /dev/null`))) - depth: 1 - data (1): - nil -.brev - -The user types -.code s -to step into the -.code "(next ...)" -form. - -.verb - txr> s - stopped at line 2 of navytime.txr - form: (open-command `wget -c @url -O - 2> /dev/null`) - depth: 2 - data (nil): - nil -.brev - -The current form now is the \*(TL -.code open-command -form which will create an input stream from the given -.code wget -command. The user types -.code s -again to step in: - -.verb - txr> s - stopped at line 2 of navytime.txr - form: `wget -c @url -O - 2> /dev/null` - depth: 3 - data (nil): - nil -.brev - -Now, the argument expression of the -.code open-command -form is about to be evaluated. -.verb - txr> s - stopped at line 3 of navytime.txr - form: ((sys:text "<!DOCTYPE" #/ +/ "HTML" #/ +/ "PUBLIC" - #/ +/ "\e"-//W3C//DTD" #/ +/ "HTML" #/ +/ "3.2" - #/ +/ "Final\e"//EN>")) - depth: 2 - data (1): - "<!DOCTYPE HTML PUBLIC \e"-//W3C//DTD HTML 3.2 Final\e"//EN>" -.brev - -Now, the input stream has been opened, and control has stopped at line 3 -of the query. The -.code "((sys:text ...) ...)" -syntax is the internal representation of this line. The pattern matching -is in vertical mode, and so the current line of input is shown without -an indication of the character position. - -.verb - txr> s - stopped at line 3 of navytime.txr - form: ((sys:text "<!DOCTYPE" #/ +/ "HTML" #/ +/ "PUBLIC" - #/ +/ "\e"-//W3C//DTD" #/ +/ "HTML" #/ +/ "3.2" - #/ +/ "Final\e"//EN>")) - depth: 3 - data (1:0): - "" . "<!DOCTYPE HTML PUBLIC \e"-//W3C//DTD HTML 3.2 Final\e"//EN>" -.brev - -Now, the form about to be processed is the first item of the -.codn "(sys:text ...)" , -the string -.strn <!DOCTYPE . - -The input is shown broken into two quoted strings with a dot in between. -The dot indicates the current position. The left string is empty, meaning -that this is the leftmost position. The programmer steps: - -.verb -txr> s - stopped at line 3 of navytime.txr - form: ("<!DOCTYPE" #/ +/ "HTML" #/ +/ "PUBLIC" #/ +/ "\e"-//W3C//DTD" - #/ +/ "HTML" #/ +/ "3.2" #/ +/ "Final\e"//EN>") - depth: 4 - data (1:0): - "" . "<!DOCTYPE HTML PUBLIC \e"-//W3C//DTD HTML 3.2 Final\e"//EN>" -.brev - -The literal text -.str "<!DOCTYPE" -is about to be matched. - -.verb - txr> s - stopped at line 3 of navytime.txr - form: (#/ +/ "HTML" #/ +/ "PUBLIC" #/ +/ "\e"-//W3C//DTD" #/ +/ "HTML" - #/ +/ "3.2" #/ +/ "Final\e"//EN>") - depth: 4 - data (1:9): - "<!DOCTYPE" . " HTML PUBLIC \e"-//W3C//DTD HTML 3.2 Final\e"//EN>" -.brev - -The -.str "<!DOCTYPE" -text matches and so the current position advances in the input. -Control has now passed to the second element of the -.codn "(sys:text ...)" , -the regular expression -.code "#/ +/" -which matches one or more spaces. This regular expression is -produced by a single space in the source code, according to the language rules. - -.verb - txr> s - stopped at line 3 of navytime.txr - form: ("HTML" #/ +/ "PUBLIC" #/ +/ "\e"-//W3C//DTD" #/ +/ "HTML" #/ +/ - "3.2" #/ +/ "Final\e"//EN>") - depth: 4 - data (1:10): - "<!DOCTYPE " . "HTML PUBLIC \e"-//W3C//DTD HTML 3.2 Final\e"//EN>" -.brev - -Now, the regular expression has matched and moved the position past -the space; the facing input is now -.strn "HTML ..." . - -The programmer then repeats the -.code s -command by hitting Enter. - -.verb - txr> - stopped at line 3 of navytime.txr - form: (#/ +/ "PUBLIC" #/ +/ "\e"-//W3C//DTD" #/ +/ "HTML" #/ +/ "3.2" - #/ +/ "Final\e"//EN>") - depth: 4 - data (1:14): - "<!DOCTYPE HTML" . " PUBLIC \e"-//W3C//DTD HTML 3.2 Final\e"//EN>" - txr> - stopped at line 3 of navytime.txr - form: ("PUBLIC" #/ +/ "\e"-//W3C//DTD" #/ +/ "HTML" #/ +/ "3.2" #/ +/ - "Final\e"//EN>") - depth: 4 - data (1:15): - "<!DOCTYPE HTML " . "PUBLIC \e"-//W3C//DTD HTML 3.2 Final\e"//EN>" - txr> - stopped at line 3 of navytime.txr - form: (#/ +/ "\e"-//W3C//DTD" #/ +/ "HTML" #/ +/ "3.2" #/ +/ - "Final\e"//EN>") - depth: 4 - data (1:21): - "<!DOCTYPE HTML PUBLIC" . " \e"-//W3C//DTD HTML 3.2 Final\e"//EN>" - txr> - stopped at line 3 of navytime.txr - form: ("\e"-//W3C//DTD" #/ +/ "HTML" #/ +/ "3.2" #/ +/ "Final\e"//EN>") - depth: 4 - data (1:22): - "<!DOCTYPE HTML PUBLIC " . "\e"-//W3C//DTD HTML 3.2 Final\e"//EN>" - txr> - stopped at line 3 of navytime.txr - form: (#/ +/ "HTML" #/ +/ "3.2" #/ +/ "Final\e"//EN>") - depth: 4 - data (1:34): - "<!DOCTYPE HTML PUBLIC \e"-//W3C//DTD" . " HTML 3.2 Final\e"//EN>" -.brev - -It is not evident from the session transcript, but during interactive use, -the input context appears to be animated. Whenever the programmer hits -Enter, the new context is printed and the dot appears to advance. - -Eventually the programmer becomes bored and place a breakpoint on line 16, -where the -.code @(output) -block begins, and invokes the -.code c -command to continue the execution: - -.verb - txr> b 16 - txr> c - stopped at line 16 of navytime.txr - form: ((output (((repeat () ((@MO "-" @DD - " " @HH ":" - @MM ":" @SS - " " @PM " " - @TZ)) - () () () () - () ()))))) - depth: 2 - data (16): - "" -.brev - -The programmer issues a -.code v -command to take a look at the variable bindings, -which indicate that the -.code @(collect) -has produced some lists: - -.verb - txr> v - bindings: - 0: ((PM " " " " " " " " " " "PM" "PM") - (TZNAME "Universal Time" "Eastern Time" - "Central Time" "Mountain Time" "Pacific Time" - "Alaska Time" "Hawaii-Aleutian Time") - (TZ "UTC" "AM EDT" "AM CDT" - "AM MDT" "AM PDT" "AKDT" "HAST") - (SS "03" "03" "03" "03" "03" "03" "03") - (MM "09" "09" "09" "09" "09" "09" "09") - (HH "07" "03" "02" "01" "12" "11" "09") - (DD "07" "07" "07" "07" "07" "06" "06") - (MO "Apr" "Apr" "Apr" "Apr" "Apr" "Apr" "Apr")) -.brev - -Then the continue command -.code c -is isued twice, which finishes the program, whose output appears: - -.verb - txr> c - stopped at line 16 of navytime.txr - form: ((output (((repeat () ((@MO "-" @DD - " " @HH ":" - @MM ":" @SS - " " @PM " " - @TZ)) - () () () () - () ()))))) - depth: 3 - data (nil): - nil - txr> c - Apr-07 07:09:03 UTC - Apr-07 03:09:03 AM EDT - Apr-07 02:09:03 AM CDT - Apr-07 01:09:03 AM MDT - Apr-07 12:09:03 AM PDT - Apr-06 11:09:03 PM AKDT - Apr-06 09:09:03 PM HAST -.brev +\*(TX had a simple, crude, built-in debugger, which was removed. .SH* COMPATIBILITY |