NAME ^

Tcl Parser

DESCRIPTION ^

This is the parser that makes up the heart of Partcl. It follows the 11 rules that are found in the Tcl manpage, available online at <http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm>.

pmc commands = parse(string tcl_code)

Parses the Tcl code and returns an array of TclCommand objects. First, it performs the \<newline> substitution. Then it fetches commands, one at a time (skipping over comments).

int pos = skip_comment(string tcl_code, int pos)

Checks for a comment and returns either the original pos or the position after the comment.

    Incoming: # comment\n
              ^
    Outgoing: # comment\n
                       ^^
(pmc command, int pos) = get_command(string tcl_code, pmc chars, int pos)

Tries to get a command from the Tcl code at pos, stopping at the first character that's ord value exists in the chars hash.

    Incoming: puts [lindex "a b c" 1]
                    ^
    Outgoing: puts [lindex "a b c" 1]
                                    ^
(pmc word, int pos) = get_word(string tcl_code, pmc chars, int pos)

Parses a word, starting at pos and ending at the first character that's ord value exists in the chars hash. Returns either a TclWord object or a TclConst, TclCommand, or TclVar object if the Tclword contains only one.

    Incoming: puts foo\n
              ^
    Outgoing: puts foo\n
                      ^^
(pmc word, int pos) = get_quote(string tcl_code, pmc chars, int pos)

Parses a quote and returns a TclWord object containing the separate parts (or, if there's only one, it's child).

    Incoming; puts [lindex "a b c" 1]
                           ^
    Outgoing: puts [lindex "a b c" 1]
                                 ^
(pmc const, int pos) = get_brace(string tcl_code, pmc chars, int pos)

Parses a {} quoted expression, returning a TclConst object.

    Incoming: puts {foo}
                   ^
    Outgoing: puts {foo}
                       ^
(pmc command, int pos) = get_subcommand(string tcl_code, int pos)

Parses a subcommand and returns a TclCommand or TclCommandList object.

    Incoming: puts [lindex "a b c" 1]
                   ^
    Outgoing: puts [lindex "a b c" 1]
                                     ^
(pmc var, int pos) = get_variable(string tcl_code, int pos)

If it's really a variable, returns a TclVar object. If it's something else, return a TclConst object.

    Incoming: puts $foo\n
                   ^
    Outgoing: puts $foo\n
                       ^^
(int reg_num, str code) = compile(pmc thing, int reg_num)

Given an object, call its compile method, or assume it's constant and generate the code for it.

POD ERRORS ^

Hey! The above document had some coding errors, which are explained below:

Around line 13:

Unknown directive: =head


parrot