## Apache Zeta Components Manual :: Docs For Class ezcDocumentBBCodeParser

### Document::ezcDocumentBBCodeParser

### Class ezcDocumentBBCodeParser

Parser for bbcode documents.

Source for this file: /Document/src/document/bbcode/parser.php

    ezcDocumentParser
       |
       --ezcDocumentBBCodeParser

Version: | //autogen//

### Member Variables

protected array

`$documentStack = 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.

protected array

`$reductions = array(
'ezcDocumentBBCodeClosingTagNode' => array(
'reduceTags',
),'ezcDocumentBBCodeParagraphNode'=>array('reduceParagraph',),'ezcDocumentBBCodeDocumentNode'=>array('reduceDocument',),'ezcDocumentBBCodeListItemNode'=>array('reduceListItem',),'ezcDocumentBBCodeListEndNode'=>array('reduceList',),)`
Array containing simplified reduce ruleset.

We cannot express the BBCode 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.

1. array(
2. ezcDocumentBBCodeNode ::DOCUMENT=>'reduceDocument'
3. ...
4. )

protected array

`$shifts = array(
'ezcDocumentBBCodeTagOpenToken'
=> 'shiftOpeningToken',
'ezcDocumentBBCodeTagCloseToken'
=> 'shiftClosingToken',
'ezcDocumentBBCodeListItemToken'
=> 'shiftListItemToken',
'ezcDocumentBBCodeWhitespaceToken'
=> 'shiftWhitespaceToken',
'ezcDocumentBBCodeTextLineToken'
=> 'shiftTextToken',
'ezcDocumentBBCodeLiteralBlockToken'
=> 'shiftLiteralBlockToken',
'ezcDocumentBBCodeNewLineToken'
=> 'shiftNewLineToken',
'ezcDocumentBBCodeEndOfFileToken'
=> 'shiftEndOfFileToken',
)`
Array containing simplified shift ruleset.

We cannot express the BBCode syntax as a usual grammar using a BNF. With the pumping lemma for context free grammars [1] you can easily prove, that the word a^n b c^n d e^n is not a context free grammar, and this is what the title definitions are.

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:

1. array(
2. WHITESPACE=>array(
3. reductionMethod,
4. ...
5. ),
6. ...
7. )

[1] http://en.bbcodepedia.org/bbcode/Pumping_lemma_for_context-free_languages

### Inherited Member Variables

From ezcDocumentParser
protected | `ezcDocumentParser::$options`
protected | `ezcDocumentParser::$properties`

### Method Summary

public ezcDocumentBBCodeDocumentNode | `parse( $tokens )` Parse token stream.
protected void | `reduceDocument( $node )` Reduce prior sections, if a new section has been found.
protected mixed | `reduceList( $node )` Reduce list.
protected mixed | `reduceListItem( $node )` Reduce list items.
protected mixed | `reduceParagraph( $node )` Reduce paragraph.
protected mixed | `reduceTags( $node )` Reduce tags.
protected mixed | `shiftClosingToken( $token , &$tokens , $tokens )` Shift tag clsoing token
protected mixed | `shiftEndOfFileToken( $token , &$tokens , $tokens )` Shift EOF token.
protected mixed | `shiftListItemToken( $token , &$tokens , $tokens )` Shift list item token
protected mixed | `shiftLiteralBlockToken( $token , &$tokens , $tokens )` Shift literal block token
protected mixed | `shiftNewLineToken( $token , &$tokens , $tokens )` Shift new line token.
protected mixed | `shiftOpeningToken( $token , &$tokens , $tokens )` Shift tag opening token
protected mixed | `shiftTextToken( $token , &$tokens , $tokens )` Shift text token.
protected mixed | `shiftWhitespaceToken( $token , &$tokens , $tokens )` Shift whitespace token.

### Inherited Methods

From ezcDocumentParser
public ezcDocumentParser | `ezcDocumentParser::__construct()` Construct new document
public array | `ezcDocumentParser::getErrors()` Return list of errors occured during visiting the document.
public void | `ezcDocumentParser::triggerError()` Trigger parser error

### Methods

#### parse

ezcDocumentBBCodeDocumentNode parse( $tokens )

Parse token stream.

Parse an array of ezcDocumentBBCodeToken objects into a bbcode abstract syntax tree.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$tokens` | array |

#### reduceDocument

void reduceDocument( ezcDocumentBBCodeDocumentNode $node )

Reduce prior sections, if a new section has been found.

If a new section has been found all sections with a higher depth level can be closed, and all items fitting into sections may be aggregated by the respective sections as well.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$node` | ezcDocumentBBCodeDocumentNode |

#### reduceList

mixed reduceList( ezcDocumentBBCodeNode $node )

Reduce list.

Aggregates list items and puts them into a found list.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$node` | ezcDocumentBBCodeParagraphNode |

#### reduceListItem

mixed reduceListItem( ezcDocumentBBCodeNode $node )

Reduce list items.

Aggregates list items and puts them into a found list.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$node` | ezcDocumentBBCodeParagraphNode |

#### reduceParagraph

mixed reduceParagraph( ezcDocumentBBCodeParagraphNode $node )

Reduce paragraph.

Paragraphs are reduce with all inline tokens, which have been added to the document stack before. If there are no inline nodes, the paragraph will be ommitted.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$node` | ezcDocumentBBCodeParagraphNode |

#### reduceTags

mixed reduceTags( ezcDocumentBBCodeClosingTagNode $node )

Reduce tags.

Locates the matching opening tag for a closing tag and reduces the contents found on the way back.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$node` | ezcDocumentBBCodeClosingTagNode |

#### shiftClosingToken

mixed shiftClosingToken( ezcDocumentBBCodeToken $token , &$tokens , array $tokens )

Shift tag clsoing token

Closing tags mean that the preceeding contents will be aggregated, once a matching opening tag is found. Is just shifted to the document stack, and the appropriate reduce call will follow right away.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$token` | ezcDocumentBBCodeToken |
`$tokens` | array |
`&$tokens` | array |

#### shiftEndOfFileToken

mixed shiftEndOfFileToken( ezcDocumentBBCodeToken $token , &$tokens , array $tokens )

Shift EOF token.

Shift End-Of-File token. We reached the end of the document, and therefore shift a document node onto the stack.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$token` | ezcDocumentBBCodeToken |
`$tokens` | array |
`&$tokens` | array |

#### shiftListItemToken

mixed shiftListItemToken( ezcDocumentBBCodeToken $token , &$tokens , array $tokens )

Shift list item token

List item tokens indicate a new list item. Just put them on the stack, they will be aggregated later.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$token` | ezcDocumentBBCodeToken |
`$tokens` | array |
`&$tokens` | array |

#### shiftLiteralBlockToken

mixed shiftLiteralBlockToken( ezcDocumentBBCodeToken $token , &$tokens , array $tokens )

Shift literal block token

Literal blocks are just a chunk of code or similar, where the token can jsut be converted into an apropriate node.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$token` | ezcDocumentBBCodeToken |
`$tokens` | array |
`&$tokens` | array |

#### shiftNewLineToken

mixed shiftNewLineToken( ezcDocumentBBCodeToken $token , &$tokens , array $tokens )

Shift new line token.

Double new lines are considered as paragraphs. All other new lines are just shifted as single whitespace text nodes.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$token` | ezcDocumentBBCodeToken |
`$tokens` | array |
`&$tokens` | array |

#### shiftOpeningToken

mixed shiftOpeningToken( ezcDocumentBBCodeToken $token , &$tokens , array $tokens )

Shift tag opening token

Opening tags mean that the following contents will be aggregated, once a matching closing tag is found. Is just shifted to the document stack.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$token` | ezcDocumentBBCodeToken |
`$tokens` | array |
`&$tokens` | array |

#### shiftTextToken

mixed shiftTextToken( ezcDocumentBBCodeToken $token , &$tokens , array $tokens )

Shift text token.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$token` | ezcDocumentBBCodeToken |
`$tokens` | array |
`&$tokens` | array |

#### shiftWhitespaceToken

mixed shiftWhitespaceToken( ezcDocumentBBCodeToken $token , &$tokens , array $tokens )

Shift whitespace token.

Shift whitespace tokens. Whitespaces are only considered significant, if the prior token was not a block level element.

##### Parameters:

Name | Type | Description
--- | --- | ---
`$token` | ezcDocumentBBCodeToken |
`$tokens` | array |
`&$tokens` | array |

Documentation generated by phpDocumentor 1.4.3