PHP Class Gregwar\RST\Parser

Show file Open project: gregwar/rst Class Usage Examples

Protected Properties

Property Type Description
$buffer The buffer is an array containing current lines that are parsed
$currentLine Current line
$directive Current directive to be applied on next node
$directives Current directives
$document Current document
$environment Environment
$filename File name
$includeAllowed Allow include directives?
$includeRoot Behaves like PHP's open_basedir
$isCode Is the current node code ?
$lineInfo
$listFlow
$listLine
$specialLetter Current level of special lines (==== and so)
$state Current state

Public Methods

Method Description
__construct ( $environment = null, $kernel = null )
createSpan ( $span ) : Span Create a span, which is a text with inline style
getCurrentLine ( ) Gets the current line
getDocument ( ) : Gregwar\RST\Document Get the current document
getEnvironment ( ) : Environment Get the current environment
getFilename ( ) Gets the current filename
getIncludeAllowed ( ) : boolean
getIncludeRoot ( ) : string
getKernel ( ) : Kernel Get the current kernel
getSubParser ( ) : Parser Get a parser with the same environment that this one
includeFileAllowed ( $path ) : boolean Is this file allowed to be included?
includeFiles ( $document ) Include all files described in $document and returns the new string of the given document with includes processed
initDirectives ( ) Initializing built-in directives
initReferences ( ) Initializing references
parse ( string $document ) : Gregwar\RST\Document Parse a document and return a Document instance
parseFile ( string $file ) : Gregwar\RST\Document Parses a given file and return a Document instance
parseLink ( string $line ) : boolean Try to parse a link definition
parseLocal ( string $document ) : Gregwar\RST\Document
pushListLine ( string $line, boolean $flush = false ) : boolean Push a line to the current list node buffer
registerDirective ( Gregwar\RST\Directive $directive ) Register a new directive handler
setIncludePolicy ( boolean $allow, string $directory = null ) : self Allow/disallow includes, or restrict them to a directory

Protected Methods

Method Description
directiveAddOption ( string $line ) Try to add an option line to the current directive, returns true if sucess and false if failure
findTableChars ( string $line ) : array | boolean Finding the table chars
flush ( ) Flushes the current buffer to create a node
getCurrentDirective ( ) : Gregwar\RST\Directive Gets the current directive
init ( )
initDirective ( string $line ) : false Get current directive if the buffer contains one
isBlockLine ( string $line ) : boolean A line is a code line if it's empty or if it begins with a trimable caracter, for instance:
isComment ( string $line ) : boolean Is this line a comment ?
isDirective ( string $line ) : boolean Is this line a directive ?
isListLine ( string $line ) : boolean Is the given line a list line ?
isSpecialLine ( string $line ) : boolean Tell if a line is a special separating line for title and separators, returns the depth of the special line
parseLine ( string &$line ) Process one line
parseLines ( string $document ) Process all the lines of a document string
parseListLine ( string $line ) : array Parses a list line
parseTableLine ( string $line ) : mixed If the given line is a table line, this will returns the parts of the given line, i.e the offset of the separators
prepareCode ( ) : boolean Tells if the current buffer is announcing a block of code

Method Details

__construct() public method

public __construct ( $environment = null, $kernel = null )

createSpan() public method

Create a span, which is a text with inline style
public createSpan ( $span ) : Span
$span the content string
return Span a span object

directiveAddOption() protected method

Try to add an option line to the current directive, returns true if sucess and false if failure
protected directiveAddOption ( string $line )
$line string

findTableChars() protected method

Finding the table chars
protected findTableChars ( string $line ) : array | boolean
$line string
return array | boolean

flush() protected method

Flushes the current buffer to create a node
protected flush ( )

getCurrentDirective() protected method

Gets the current directive
protected getCurrentDirective ( ) : Gregwar\RST\Directive
return Gregwar\RST\Directive

getCurrentLine() public method

Gets the current line
public getCurrentLine ( )

getDocument() public method

Get the current document
public getDocument ( ) : Gregwar\RST\Document
return Gregwar\RST\Document the document

getEnvironment() public method

Get the current environment
public getEnvironment ( ) : Environment
return Environment the parser environment

getFilename() public method

Gets the current filename
public getFilename ( )

getIncludeAllowed() public method

public getIncludeAllowed ( ) : boolean
return boolean

getIncludeRoot() public method

public getIncludeRoot ( ) : string
return string

getKernel() public method

Get the current kernel
public getKernel ( ) : Kernel
return Kernel the kernel

getSubParser() public method

Get a parser with the same environment that this one
public getSubParser ( ) : Parser
return Parser a new parser with the same environment

includeFileAllowed() public method

Is this file allowed to be included?
public includeFileAllowed ( $path ) : boolean
$path
return boolean

includeFiles() public method

Include all files described in $document and returns the new string of the given document with includes processed
public includeFiles ( $document )

init() protected method

protected init ( )

initDirective() protected method

.. |variable| name:: data :option: value :otherOption: otherValue
protected initDirective ( string $line ) : false
$line string
return false if this is not a directive, else an array containing : - variable: the variable name of the directive - name: the directive name - data: the data of the directive - options: an array of all the options and their values

initDirectives() public method

Initializing built-in directives
public initDirectives ( )

initReferences() public method

Initializing references
public initReferences ( )

isBlockLine() protected method

This is a block because there is a space in the front of the caracters This is still part of the block, even if there is an empty line
protected isBlockLine ( string $line ) : boolean
$line string the line text
return boolean true if the line is still in a block

isComment() protected method

Is this line a comment ?
protected isComment ( string $line ) : boolean
$line string the line
return boolean true if it's a comment

isDirective() protected method

Is this line a directive ?
protected isDirective ( string $line ) : boolean
$line string the line
return boolean true if it's a directive

isListLine() protected method

Is the given line a list line ?
protected isListLine ( string $line ) : boolean
$line string
return boolean true if the given line is a list line

isSpecialLine() protected method

Tell if a line is a special separating line for title and separators, returns the depth of the special line
protected isSpecialLine ( string $line ) : boolean
$line string
return boolean

parse() public method

Parse a document and return a Document instance
public parse ( string $document ) : Gregwar\RST\Document
$document string The contents (string) of the document
return Gregwar\RST\Document The created document

parseFile() public method

Parses a given file and return a Document instance
public parseFile ( string $file ) : Gregwar\RST\Document
$file string the file name to parse
return Gregwar\RST\Document $document the document instance

parseLine() protected method

Process one line
protected parseLine ( string &$line )
$line string the line string

parseLines() protected method

Process all the lines of a document string
protected parseLines ( string $document )
$document string the string (content) of the document

parseListLine() protected method

Parses a list line
protected parseListLine ( string $line ) : array
$line string the string line
return array containing: - true if the list is ordered, false else - the depth of the list - the text of the first line without the tick

parseLocal() public method

public parseLocal ( string $document ) : Gregwar\RST\Document
$document string
return Gregwar\RST\Document The created document

parseTableLine() protected method

====================== ========= =========== 0 23 33 +---------------------+---------+-----------+ 1 23 33
protected parseTableLine ( string $line ) : mixed
$line string
return mixed

prepareCode() protected method

Tells if the current buffer is announcing a block of code
protected prepareCode ( ) : boolean
return boolean

pushListLine() public method

Push a line to the current list node buffer
public pushListLine ( string $line, boolean $flush = false ) : boolean
$line string
$flush boolean
return boolean

registerDirective() public method

Register a new directive handler
public registerDirective ( Gregwar\RST\Directive $directive )
$directive Gregwar\RST\Directive a directive handler

setIncludePolicy() public method

Allow/disallow includes, or restrict them to a directory
public setIncludePolicy ( boolean $allow, string $directory = null ) : self
$allow boolean
$directory string
return self

Property Details

$buffer protected property

The buffer is an array containing current lines that are parsed
protected $buffer

$currentLine protected property

Current line
protected $currentLine

$directive protected property

Current directive to be applied on next node
protected $directive

$directives protected property

Current directives
protected $directives

$document protected property

Current document
protected $document

$environment protected property

Environment
protected $environment

$filename protected property

File name
protected $filename

$includeAllowed protected property

Allow include directives?
protected $includeAllowed

$includeRoot protected property

Behaves like PHP's open_basedir
protected $includeRoot

$isCode protected property

Is the current node code ?
protected $isCode

$lineInfo protected property

protected $lineInfo

$listFlow protected property

protected $listFlow

$listLine protected property

protected $listLine

$specialLetter protected property

Current level of special lines (==== and so)
protected $specialLetter

$state protected property

Current state
protected $state