-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
454 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<?php | ||
|
||
namespace MtHaml\Parser; | ||
|
||
use MtHamlPHP\Dbg; | ||
|
||
class Buffer { | ||
protected $lines; | ||
protected $line; | ||
|
||
protected $lineno; | ||
protected $column; | ||
|
||
public function __construct( $string, $lineno = 1 ) { | ||
$this->lines = preg_split( '~\r\n|\n|\r~', $string ); | ||
$this->lineno = $lineno - 1; | ||
} | ||
|
||
public function injectLines( $lines, $column) { | ||
|
||
|
||
// //remove @inlcude line | ||
if ( empty( $lines ) ) { | ||
return false; | ||
} | ||
$this->lines = array_merge( $lines, $this->lines ); | ||
// $this->line = trim($this->getLine()); | ||
$this->line ="-#This comment is do magic, do not remove : inject start , reset parser. "; | ||
$this->column = $column; | ||
|
||
return true; | ||
} | ||
|
||
public function nextLine() { | ||
$this->line = array_shift( $this->lines ); | ||
if ( null !== $this->line ) { | ||
++ $this->lineno; | ||
$this->column = 1; | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function peekLine() { | ||
if ( isset( $this->lines[0] ) ) { | ||
return $this->lines[0]; | ||
} | ||
} | ||
|
||
public function hasNextLine() { | ||
return isset( $this->lines[0] ); | ||
} | ||
|
||
public function mergeNextLine() { | ||
if ( ! isset( $this->lines[0] ) ) { | ||
return; | ||
} | ||
++ $this->lineno; | ||
$this->line .= "\n" . array_shift( $this->lines ); | ||
} | ||
|
||
public function replaceLine( $string ) { | ||
$this->line = $string; | ||
} | ||
|
||
public function isEol() { | ||
return $this->line === ''; | ||
} | ||
|
||
public function peekChar() { | ||
if ( isset( $this->line[0] ) ) { | ||
return $this->line[0]; | ||
} | ||
} | ||
|
||
public function eatChar() { | ||
if ( isset( $this->line[0] ) ) { | ||
$char = $this->line[0]; | ||
$this->line = (string) substr( $this->line, 1 ); | ||
++ $this->column; | ||
|
||
return $char; | ||
} | ||
} | ||
|
||
public function eatChars( $n ) { | ||
$chars = (string) substr( $this->line, 0, $n ); | ||
$this->line = (string) substr( $this->line, $n ); | ||
$this->column += strlen( $chars ); | ||
|
||
return $chars; | ||
} | ||
|
||
public function match( $pattern, &$match = null, $eat = true ) { | ||
if ( $count = preg_match( $pattern, $this->line, $match, PREG_OFFSET_CAPTURE ) ) { | ||
$pos = array(); | ||
|
||
foreach ( $match as $key => &$capture ) { | ||
$pos[ $key ] = array( | ||
'lineno' => $this->lineno, | ||
'column' => $capture[1], | ||
); | ||
$capture = $capture[0]; | ||
} | ||
unset( $capture ); // ref | ||
|
||
$match['pos'] = $pos; | ||
|
||
if ( $eat ) { | ||
$this->eat( $match[0] ); | ||
} | ||
} | ||
|
||
return $count > 0; | ||
} | ||
|
||
public function eat( $string ) { | ||
$this->line = (string) substr( $this->line, strlen( $string ) ); | ||
$this->column += strlen( $string ); | ||
} | ||
|
||
public function skipWs() { | ||
$this->match( '~[ \t]+~A' ); | ||
} | ||
|
||
public function getColumn() { | ||
return $this->column; | ||
} | ||
|
||
public function getLineno() { | ||
return $this->lineno; | ||
} | ||
|
||
public function getPosition() { | ||
return array( | ||
'lineno' => $this->lineno, | ||
'column' => $this->column, | ||
); | ||
} | ||
|
||
public function getLine() { | ||
return $this->line; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//todo add base pach or inludes path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.