Tcl Library Source Code

Documentation
Login


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]

NAME

pt::peg::import - PEG Import

Table Of Contents

SYNOPSIS

package require Tcl 8.5 9
package require Tcl 8.5 9
package require snit
package require fileutil::paths
package require pt::peg
package require pluginmgr
package require pt::peg::import ?1.0.2?

::pt::peg::import objectName
objectName method ?arg arg ...?
objectName destroy
objectName import text text ?format?
objectName import file path ?format?
objectName import object text object text ?format?
objectName import object file object path ?format?
objectName includes
objectName include add path
objectName include remove path
objectName include clear

DESCRIPTION

Are you lost ? Do you have trouble understanding this document ? In that case please read the overview provided by the Introduction to Parser Tools. This document is the entrypoint to the whole system the current package is a part of.

This package provides a manager for parsing expression grammars, with each instance handling a set of plugins for the import of them from other formats, i.e. their conversion from, for example peg, container, json, etc.

It resides in the Import section of the Core Layer of Parser Tools, and is one of the three pillars the management of parsing expression grammars resides on.

The other two pillars are, as shown above

  1. PEG Export, and

  2. PEG Storage

For information about the data structure which is the major output of the manager objects provided by this package see the section PEG serialization format.

The plugin system of our class is based on the package pluginmgr, and configured to look for plugins using

  1. the environment variable GRAMMAR_PEG_IMPORT_PLUGINS,

  2. the environment variable GRAMMAR_PEG_PLUGINS,

  3. the environment variable GRAMMAR_PLUGINS,

  4. the path "~/.grammar/peg/import/plugin"

  5. the path "~/.grammar/peg/plugin"

  6. the path "~/.grammar/plugin"

  7. the path "~/.grammar/peg/import/plugins"

  8. the path "~/.grammar/peg/plugins"

  9. the path "~/.grammar/plugins"

  10. the registry entry "HKEY_CURRENT_USER\SOFTWARE\GRAMMAR\PEG\IMPORT\PLUGINS"

  11. the registry entry "HKEY_CURRENT_USER\SOFTWARE\GRAMMAR\PEG\PLUGINS"

  12. the registry entry "HKEY_CURRENT_USER\SOFTWARE\GRAMMAR\PLUGINS"

The last three are used only when the package is run on a machine using the Windows(tm) operating system.

The whole system is delivered with three predefined import plugins, namely

For readers wishing to write their own import plugin for some format, i.e. plugin writers, reading and understanding the Parser Tools Impport API specification is an absolute necessity, as it documents the interaction between this package and its plugins in detail.

API

Package commands

Object command

All objects created by the ::pt::peg::import command have the following general form:

Object methods

PEG serialization format

Here we specify the format used by the Parser Tools to serialize Parsing Expression Grammars as immutable values for transport, comparison, etc.

We distinguish between regular and canonical serializations. While a PEG may have more than one regular serialization only exactly one of them will be canonical.

Example

Assuming the following PEG for simple mathematical expressions

PEG calculator (Expression)
    Digit      <- '0'/'1'/'2'/'3'/'4'/'5'/'6'/'7'/'8'/'9'       ;
    Sign       <- '-' / '+'                                     ;
    Number     <- Sign? Digit+                                  ;
    Expression <- Term (AddOp Term)*                            ;
    MulOp      <- '*' / '/'                                     ;
    Term       <- Factor (MulOp Factor)*                        ;
    AddOp      <- '+'/'-'                                       ;
    Factor     <- '(' Expression ')' / Number                   ;
END;

then its canonical serialization (except for whitespace) is

pt::grammar::peg {
    rules {
        AddOp      {is {/ {t -} {t +}}                                                                mode value}
        Digit      {is {/ {t 0} {t 1} {t 2} {t 3} {t 4} {t 5} {t 6} {t 7} {t 8} {t 9}}                mode value}
        Expression {is {x {n Term} {* {x {n AddOp} {n Term}}}}                                        mode value}
        Factor     {is {/ {x {t (} {n Expression} {t )}} {n Number}}                                  mode value}
        MulOp      {is {/ {t *} {t /}}                                                                mode value}
        Number     {is {x {? {n Sign}} {+ {n Digit}}}                                                 mode value}
        Sign       {is {/ {t -} {t +}}                                                                mode value}
        Term       {is {x {n Factor} {* {x {n MulOp} {n Factor}}}}                                    mode value}
    }
    start {n Expression}
}

PE serialization format

Here we specify the format used by the Parser Tools to serialize Parsing Expressions as immutable values for transport, comparison, etc.

We distinguish between regular and canonical serializations. While a parsing expression may have more than one regular serialization only exactly one of them will be canonical.

Example

Assuming the parsing expression shown on the right-hand side of the rule

Expression <- Term (AddOp Term)*

then its canonical serialization (except for whitespace) is

{x {n Term} {* {x {n AddOp} {n Term}}}}

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category pt of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.

KEYWORDS

EBNF, LL(k), PEG, TDPL, context-free languages, expression, grammar, matching, parser, parsing expression, parsing expression grammar, push down automaton, recursive descent, state, top-down parsing languages, transducer

CATEGORY

Parsing and Grammars

COPYRIGHT

Copyright © 2009 Andreas Kupries