ctkParser

        This package provides some (RDP) parser mainly to analyze
        options strings.

Data members

                None

Class data

                None.

Methods

        new
        destroy
        parseString
        parseWidgetOptions
        parseWidgetDefinition  (not yet implemented)

Programming notes

        All methods may also be used as class methods.

Maintenance

        Author: marco
        Date:   01.01.2007
        History:
                        26.05.2008 version 1.04
                        26.05.2008 version 1.05
                        14.04.2009 version 1.06 (P072)


Methods

string2Array

        This method converts the given string into an array
        - check wether the string contains a code which represents a ref to array,
          that means either '[ items,items, ... ]' or '( items,items, ... )'
        - parse the string by means of message ctkParser::parseString
        - quotate the items by means of message ctkParser::quotatY
        - embed the string returned by quotatY into '[]' and evaluate it
        - return the array or the ref to array depending on context
        Arguments
                array in string form
        Return
                array or ref to array depending on context
        Exceptions
                'Could not convert string'
                Unexpected array in string form

quotatX

        Handle optionslist for Scrolled widgets
        Shift out class name if scrolled widget
        call QuotatY
        unshift class name if scrolled widget
        stringify the optionslist
        return stringified optionslist

Arguments

        - ref to array of options list
        - argument type (class name i.e. 'Scrolledlistbox')

Return

        - stringified option's list

Exceptions

        'Missing mandatory argument type'

Notes

        None
=cut

sub quotatX {
my $self = shift;
my ($opt,$type) = @_;
my $rv ;
my $opt_list ='';
my $c;
my $prefix = '';

        &main::trace("quotatX opt_list ",@$opt,"type = $type");
        die "Missing mandatory argument type" unless (defined($type));
        return '' unless (@$opt);
        my $class = shift @$opt if ($type =~ /^Scrolled/);
        $prefix = "'$class' , " if(defined($class));
        $opt_list = $self->quotatY($opt);
        unshift @$opt, $class if(defined($class));
        $rv = "$prefix$opt_list";
        &main::trace("rv='$rv'");
        return $rv;
        }

quotatZZ

        Parse the given optlist :
                - quotate values keeping existing quotations
                - resolve list values
                - return list or string of options depending on context.
        Arguments
                options list (ref to array)
                quotating char ,(optional, default "'")
        Return
                list of options as array or
                string of options in scalar context.

quotatZ

        Make the given optlist operational in the clickTk run time environmnt.
        - parse the given optlist by means of main::quotatZZ
        - scan the received optlist:
                - resolve list of option :
                        - replace <widget name> with $widgets->{<widget name>}
                - resolve scalar variables:
                        - replace ref name with $widgets->{<ref name>} if
                          it exists.

quotatY

        Parse the given optlist :
                - quotate values
                - resolve list values
                - return string of options .
        Argument
                Ref to array of options
                quotating char (optional, default "'")
        Return
                stringified options separated by commas
        Notes
                - recursive call for arrays
                - empty options values are set to empty string
                - numeric values are never quoted
                - ANON blocks remain unchanged

convertToList

        The given option's string is converted to an array, whereby all
        options values are quotate by means of a call to quotatY.
        Arguments
                string to be converted
                ref to array of error's messages
        Return
                The return value is , depending on the context, an array or
                a ref to array.
        Notes
                TODO : recognize and recurse on options value lists, support qw/ list /

parseString

        Notation see 'parse Tk definition'
        string := substring [separator substring]
        separator := ',' | '=>' | '(' | ')' | '=' | '->'
        substring := nonquotedString | quotedString | list | quotedWords
        nonquotedString := [\S+]
        quotedString := quotedString1 | quotedString2
        quotedString1 := "'" [^\'] "'"
        quotedString2 := '"' [^\"] '"'
        list := '[' [^]]+ ']'
        quotedWords = qw '(' [^)]+ ')'          ## not yet implemented
        Examples :
                string = "-text => 'This is a substring!' -bg , #FFFFFF"
                string = "-fg , white , -command => ['main::doExit',$mw,$rc]"
                string = '-fg , white , -command => ["main::doExit",$mw,$rc]'
                string = '$w = $mw->Button(-command => ["main::doExit",$mw,$rc])->pack()'

parseStringQuotate

        Notation see 'parse Tk definition'
        string := substring [separator substring]
        separator := ',' | '=>' | '(' | ')' | '=' | '->'
        substring := nonquotedString | quotedString | list | quotedWords
        nonquotedString := [\S+]
        quotedString := quotedString1 | quotedString2
        quotedString1 := "'" [^\'] "'"
        quotedString2 := '"' [^\"] '"'
        list := '[' [^]]+ ']'
        quotedWords = qw '(' [^)]+ ')'          ## not yet implemented
        Example :
        string = "-text => 'This is a substring!' -bg , #FFFFFF"
        string = "-fg , white , -command => ['main::doExit',$mw,$rc]"
        string = '-fg , white , -command => ["main::doExit",$mw,$rc]'
        string = '$w = $mw->Button(-command => ["main::doExit",$mw,$rc])->pack()'
        Unlike parseString, this method carries the quotations marks into output values.

Thus, the string

        string = "-text => 'This is a substring!' -bg , #FFFFFF"
        yields the token list
                -text 'This is a substring!' -bg '#FFFFFF'

parseStringExtended

        Notation see 'parse Tk definition'
        string := substring [separator substring]
        separator := ',' | '=>' | '(' | ')' | '=' | '->'
        substring := nonquotedString | quotedString | list | quotedWords
        nonquotedString := [\S+]
        quotedString := quotedString1 | quotedString2
        quotedString1 := "'" [^\'] "'"
        quotedString2 := '"' [^\"] '"'
        list := '[' [^]]+ ']'
        quotedWords = qw '(' [^)]+ ')'          ## not yet implemented
        Example :
        string = "-text => 'This is a substring!' -bg , #FFFFFF"
        string = "-fg , white , -command => ['main::doExit',$mw,$rc]"
        string = '-fg , white , -command => ["main::doExit",$mw,$rc]'
        string = '$w = $mw->Button(-command => ["main::doExit",$mw,$rc])->pack()'
        Unlike parseSring this method creates a token for '=','(',')','->' and ';'
        when it is in state READNEXT.
        This allow a further process to recognize options lists, type and id as in
        <id> = <parent>-><class>(<optionslist>)-><geom-manager>(<geom-optlist>);

Method parseWidgetOptions

        Method parseWidgetOptions converts a token list into
        an useable options list.
        In fact the method parseString do not recognize
        compound options like anonymous subroutines.
Input
        Token list
Output
        Valid options list (array)
Precondition
        Method parseString successfully done (lexer)

parseWidgetOptionsQuotate

        Same as parseWidgetOptions but surrounding otions
        which contains \S oe [\\\/] with simple quotations
        Precondition : input tokenlist doesn't contain quotated
                       tokens!

parse_qw_array

        This method convert a string containing a qw(list)
        into an array or a string containing a list of quotated
        items as ruled by clickTk.
        the following formats are valid
        '[qw( options list)]'
        '(qw/ options list/)'
        'qq/-option, value , option ,value, .../
        'qq/-option, value , option ,\$var, .../
        Arguments
                string to be converted
        Return
                array of tokens in array context, or
                number of tokens in scalar context.
        Exceptions
                Could not eval
        Notes
                None

Parse Tk widget definition

        Notation :
                {}                      iteration of 0..1 items
                []                      iteration of 0..n items
                ()                      iteration of 1..n items
                |                       selection (inclusive or)
                & or none       sequence (mandatory)
                .                       concatenation (subsequence)
                word            non terminal token \w+
                'x'                     ascii char (terminal token)
                "x"                     ascii char (terminal token)
                "\'"            ascii char (terminal token)
                \w,\d,          perl regexp elements
                /regexp/
        Definition
                def := (widgetDef | variable)  {'->' geometryDef} ';'
                widgetDef :=  variable '=' variable '->' className {'(' {widgetOptions} ')'} ';'
                variable := '$'.\w+
                classname := \w+
                widgetOptions = [optionsName '=>' | ',' value]
                optionsname := '-' \w
                value := baseValue | variable | reference | array
                simpleValue := numeric | string
                numeric := \d+
                string := delimiter (chars) delimiter
                delimiter := ''' | '"'
                chars := \S | '\'chars
                reference := '\' variable | 'sub' '{' code '}' | '\'.entry
                code := '&'.entry {'(' list ')'}
                entry {{\w+]}.'::'}.\w+
                array :=  staticArray | dynamicArray
                staticArray := '(' list  ')'
                dynamicArray := '[' list ']'
                list := [value [',' value]]
                geometryDef := geometryManager {'(' geometryOptions ')'}
                geometryOptions := [optionsName '=>' | ',' baseValue]

Back to index