Author: kn
Date: Wed Feb 13 22:44:10 2008
New Revision: 7362

Log:
- Added class stubs for parser and AST

Added:
    experimental/Document/src/document/rst/node.php   (with props)
    experimental/Document/src/document/rst/nodes/
    experimental/Document/src/document/rst/nodes/document.php   (with props)
    experimental/Document/src/document/rst/parser.php   (with props)

Added: experimental/Document/src/document/rst/node.php
==============================================================================
--- experimental/Document/src/document/rst/node.php (added)
+++ experimental/Document/src/document/rst/node.php [iso-8859-1] Wed Feb 13 
22:44:10 2008
@@ -1,0 +1,74 @@
+<?php
+/**
+ * File containing the ezcDocumentRstNode struct
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Struct for RST document document abstract syntax tree nodes
+ * 
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class ezcDocumentRstNode extends ezcBaseStruct implements RecursiveIterator
+{
+    // Node types
+    const DOCUMENT      = 0;
+    const SECTION       = 1;
+    const TITLE         = 2;
+    const PARAGRAPH     = 3;
+    // ...
+
+    /**
+     * Node type
+     * 
+     * @var int
+     */
+    public $type;
+
+    /**
+     * Child nodes
+     * 
+     * @var mixed
+     */
+    public $nodes;
+
+    /**
+     * Construct RST node
+     * 
+     * @ignore
+     * @param int $type 
+     * @param mixed $content 
+     * @param int $line 
+     * @param int $position 
+     * @return void
+     */
+    public function __construct( $type, array $nodes = array() )
+    {
+        $this->type         = $type;
+        $this->nodes        = $nodes;
+    }
+
+    /**
+     * Set state after var_export
+     * 
+     * @param array $properties 
+     * @return void
+     * @ignore
+     */
+    public static function __set_state( $properties )
+    {
+        return new ezcDocumentRstNode(
+            $properties['type'],
+            $properties['nodes']
+        );
+    }
+}
+
+?>

Propchange: experimental/Document/src/document/rst/node.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: experimental/Document/src/document/rst/nodes/document.php
==============================================================================
--- experimental/Document/src/document/rst/nodes/document.php (added)
+++ experimental/Document/src/document/rst/nodes/document.php [iso-8859-1] Wed 
Feb 13 22:44:10 2008
@@ -1,0 +1,39 @@
+<?php
+/**
+ * File containing the ezcDocumentRstDocumentNode struct
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * The document AST node
+ * 
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class ezcDocumentRstDocumentNode extends ezcDocumentRstNode
+{
+    /**
+     * Construct RST document node
+     * 
+     * @ignore
+     * @param int $type 
+     * @param mixed $content 
+     * @param int $line 
+     * @param int $position 
+     * @return void
+     */
+    public function __construct( array $nodes = array() )
+    {
+        // Perhaps check, that only node of type section and metadata are
+        // added.
+        parent::__construct( self::DOCUMENT, $nodes );
+    }
+}
+
+?>

Propchange: experimental/Document/src/document/rst/nodes/document.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: experimental/Document/src/document/rst/parser.php
==============================================================================
--- experimental/Document/src/document/rst/parser.php (added)
+++ experimental/Document/src/document/rst/parser.php [iso-8859-1] Wed Feb 13 
22:44:10 2008
@@ -1,0 +1,123 @@
+<?php
+/**
+ * File containing the ezcDocumentRstParser
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+
+/**
+ * Parser for RST documents
+ * 
+ * @TODO: Think about providing methods to add callbacks for manual handling of
+ * additional elements. This still may be done by just extending the parser.
+ *
+ * @package Document
+ * @version //autogen//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+class ezcDocumentRstParser
+{
+    /**
+     * Array containing simplified shift ruleset
+     * 
+     * We cannot express the RST syntax as a usual grammar using a BNF. This
+     * structure contains an array with callbacks implementing the shift rules
+     * for all tokens. There may be multiple rules for one single token. 
+     *
+     * The callbacks itself create syntax elements and push them to the
+     * document stack. After each push the reduction callbacks will be called
+     * for the pushed elements.
+     *
+     * The array should look like:
+     * <code>
+     *  array(
+     *      WHITESPACE => array(
+     *          reductionMethod,
+     *          ...
+     *      ),
+     *      ...
+     *  )
+     * </code>
+     *
+     * @var array
+     */
+    protected $shifts = array(
+        ezcDocumentRstToken::WHITESPACE => array(
+        ),
+        ezcDocumentRstToken::NEWLINE => array(
+        ),
+        ezcDocumentRstToken::BACKSLASH => array(
+            'reduceBackslash'
+        ),
+        ezcDocumentRstToken::SPECIAL_CHARS => array(
+        ),
+        ezcDocumentRstToken::TEXT_LINE => array(
+        ),
+    );
+
+    /**
+     * Array containing simplified reduce ruleset
+     *
+     * We cannot express the RST syntax as a usual grammar using a BNF. This
+     * structure implements a pseudo grammar by assigning a number of callbacks
+     * for internal methods implementing reduction rules for a detected syntax
+     * element.
+     *
+     * <code>
+     *  array(
+     *      end_of_file => array(
+     *          'reduceDocument'
+     *      ),
+     *      ...
+     *  )
+     * </code>
+     * 
+     * @var array
+     */
+    protected $reductions = array(
+    );
+
+    /**
+     * Contains a list of detected syntax elements.
+     *
+     * At the end of a successfull parsing process this should only contain one
+     * document syntax element. During the process it may contain a list of
+     * elements, which are up to reduction.
+     *
+     * Each element in the stack has to be an object extending from
+     * ezcDocumentRstNode, which may again contain any amount such objects.
+     * This way an abstract syntax tree is constructed.
+     * 
+     * @var array
+     */
+    protected $documentStack = array();
+
+    /**
+     * List with parsed tokens.
+     *
+     * Each token which has been parsed will be removed from the list, until
+     * the list is empty.
+     * 
+     * @var array
+     */
+    protected $tokens = array();
+
+    /**
+     * Construct parser
+     *
+     * Construct the parser from an array of tokens (ezcDocumentRstToken), and
+     * create a cocument out of this token array.
+     *
+     * @return void
+     */
+    public function __construct( array $tokens )
+    {
+        // @TODO: Implement
+    }
+}
+
+?>

Propchange: experimental/Document/src/document/rst/parser.php
------------------------------------------------------------------------------
    svn:eol-style = native


-- 
svn-components mailing list
svn-components@lists.ez.no
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to