Tcl Library Source Code

Documentation
Login


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

NAME

pt::peg::export - PEG Export

Table Of Contents

SYNOPSIS

package require Tcl 8.5 9
package require snit
package require struct::map
package require pt::peg
package require pluginmgr
package require pt::peg::export ?1.0.2?

::pt::peg::export objectName
objectName method ?arg arg ...?
objectName destroy
objectName export serial serial ?format?
objectName export object object ?format?
objectName configuration names
objectName configuration get
objectName configuration set name ?value?
objectName configuration unset pattern...

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 export of them to other formats, i.e. their conversion to, for example nroff, HTML, etc.

It resides in the Export 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 Import, and

  2. PEG Storage

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

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

  1. the environment variable GRAMMAR_PEG_EXPORT_PLUGINS,

  2. the environment variable GRAMMAR_PEG_PLUGINS,

  3. the environment variable GRAMMAR_PLUGINS,

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

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

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

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

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

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

  10. the registry entry "HKEY_CURRENT_USER\SOFTWARE\GRAMMAR\PEG\EXPORT\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 export plugins, namely

For readers wishing to write their own export plugin for some format, i.e. plugin writers, reading and understanding the Parser Tools Export 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::export 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