From 8ca6cc32b2c789a3149861159ad258f2cb9491e3 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:39:39 +0200 Subject: Adding upstream version 2.11.4. Signed-off-by: Daniel Baumann --- .../vendor/lessphp/lib/Less/Exception/Chunk.php | 200 +++++++++++++++++++++ .../vendor/lessphp/lib/Less/Exception/Compiler.php | 11 ++ .../vendor/lessphp/lib/Less/Exception/Parser.php | 107 +++++++++++ 3 files changed, 318 insertions(+) create mode 100644 library/vendor/lessphp/lib/Less/Exception/Chunk.php create mode 100644 library/vendor/lessphp/lib/Less/Exception/Compiler.php create mode 100644 library/vendor/lessphp/lib/Less/Exception/Parser.php (limited to 'library/vendor/lessphp/lib/Less/Exception') diff --git a/library/vendor/lessphp/lib/Less/Exception/Chunk.php b/library/vendor/lessphp/lib/Less/Exception/Chunk.php new file mode 100644 index 0000000..2458cc5 --- /dev/null +++ b/library/vendor/lessphp/lib/Less/Exception/Chunk.php @@ -0,0 +1,200 @@ +message = 'ParseError: Unexpected input'; // default message + + $this->index = $index; + + $this->currentFile = $currentFile; + + $this->input = $input; + $this->input_len = strlen( $input ); + + $this->Chunks(); + $this->genMessage(); + } + + /** + * See less.js chunks() + * We don't actually need the chunks + */ + protected function Chunks() { + $level = 0; + $parenLevel = 0; + $lastMultiCommentEndBrace = null; + $lastOpening = null; + $lastMultiComment = null; + $lastParen = null; + + for ( $this->parserCurrentIndex = 0; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { + $cc = $this->CharCode( $this->parserCurrentIndex ); + if ( ( ( $cc >= 97 ) && ( $cc <= 122 ) ) || ( $cc < 34 ) ) { + // a-z or whitespace + continue; + } + + switch ( $cc ) { + + // ( + case 40: + $parenLevel++; + $lastParen = $this->parserCurrentIndex; + break; + + // ) + case 41: + $parenLevel--; + if ( $parenLevel < 0 ) { + return $this->fail( "missing opening `(`" ); + } + break; + + // ; + case 59: + // if (!$parenLevel) { $this->emitChunk(); } + break; + + // { + case 123: + $level++; + $lastOpening = $this->parserCurrentIndex; + break; + + // } + case 125: + $level--; + if ( $level < 0 ) { + return $this->fail( "missing opening `{`" ); + + } + // if (!$level && !$parenLevel) { $this->emitChunk(); } + break; + // \ + case 92: + if ( $this->parserCurrentIndex < $this->input_len - 1 ) { $this->parserCurrentIndex++; break; + } + return $this->fail( "unescaped `\\`" ); + + // ", ' and ` + case 34: + case 39: + case 96: + $matched = 0; + $currentChunkStartIndex = $this->parserCurrentIndex; + for ( $this->parserCurrentIndex += 1; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { + $cc2 = $this->CharCode( $this->parserCurrentIndex ); + if ( $cc2 > 96 ) { continue; + } + if ( $cc2 == $cc ) { $matched = 1; break; + } + if ( $cc2 == 92 ) { // \ + if ( $this->parserCurrentIndex == $this->input_len - 1 ) { + return $this->fail( "unescaped `\\`" ); + } + $this->parserCurrentIndex++; + } + } + if ( $matched ) { break; + } + return $this->fail( "unmatched `" . chr( $cc ) . "`", $currentChunkStartIndex ); + + // /, check for comment + case 47: + if ( $parenLevel || ( $this->parserCurrentIndex == $this->input_len - 1 ) ) { break; + } + $cc2 = $this->CharCode( $this->parserCurrentIndex + 1 ); + if ( $cc2 == 47 ) { + // //, find lnfeed + for ( $this->parserCurrentIndex += 2; $this->parserCurrentIndex < $this->input_len; $this->parserCurrentIndex++ ) { + $cc2 = $this->CharCode( $this->parserCurrentIndex ); + if ( ( $cc2 <= 13 ) && ( ( $cc2 == 10 ) || ( $cc2 == 13 ) ) ) { break; + } + } + } else if ( $cc2 == 42 ) { + // /*, find */ + $lastMultiComment = $currentChunkStartIndex = $this->parserCurrentIndex; + for ( $this->parserCurrentIndex += 2; $this->parserCurrentIndex < $this->input_len - 1; $this->parserCurrentIndex++ ) { + $cc2 = $this->CharCode( $this->parserCurrentIndex ); + if ( $cc2 == 125 ) { $lastMultiCommentEndBrace = $this->parserCurrentIndex; + } + if ( $cc2 != 42 ) { continue; + } + if ( $this->CharCode( $this->parserCurrentIndex + 1 ) == 47 ) { break; + } + } + if ( $this->parserCurrentIndex == $this->input_len - 1 ) { + return $this->fail( "missing closing `*/`", $currentChunkStartIndex ); + } + } + break; + + // *, check for unmatched */ + case 42: + if ( ( $this->parserCurrentIndex < $this->input_len - 1 ) && ( $this->CharCode( $this->parserCurrentIndex + 1 ) == 47 ) ) { + return $this->fail( "unmatched `/*`" ); + } + break; + } + } + + if ( $level !== 0 ) { + if ( ( $lastMultiComment > $lastOpening ) && ( $lastMultiCommentEndBrace > $lastMultiComment ) ) { + return $this->fail( "missing closing `}` or `*/`", $lastOpening ); + } else { + return $this->fail( "missing closing `}`", $lastOpening ); + } + } else if ( $parenLevel !== 0 ) { + return $this->fail( "missing closing `)`", $lastParen ); + } + + // chunk didn't fail + + //$this->emitChunk(true); + } + + public function CharCode( $pos ) { + return ord( $this->input[$pos] ); + } + + public function fail( $msg, $index = null ) { + if ( !$index ) { + $this->index = $this->parserCurrentIndex; + } else { + $this->index = $index; + } + $this->message = 'ParseError: '.$msg; + } + + /* + function emitChunk( $force = false ){ + $len = $this->parserCurrentIndex - $this->emitFrom; + if ((($len < 512) && !$force) || !$len) { + return; + } + $chunks[] = substr($this->input, $this->emitFrom, $this->parserCurrentIndex + 1 - $this->emitFrom ); + $this->emitFrom = $this->parserCurrentIndex + 1; + } + */ + +} diff --git a/library/vendor/lessphp/lib/Less/Exception/Compiler.php b/library/vendor/lessphp/lib/Less/Exception/Compiler.php new file mode 100644 index 0000000..1c3727a --- /dev/null +++ b/library/vendor/lessphp/lib/Less/Exception/Compiler.php @@ -0,0 +1,11 @@ +currentFile = $currentFile; + $this->index = $index; + + $this->genMessage(); + } + + protected function getInput() { + if ( !$this->input && $this->currentFile && $this->currentFile['filename'] && file_exists( $this->currentFile['filename'] ) ) { + $this->input = file_get_contents( $this->currentFile['filename'] ); + } + } + + /** + * Set a message based on the exception info + */ + public function genMessage() { + if ( $this->currentFile && $this->currentFile['filename'] ) { + $this->message .= ' in '.basename( $this->currentFile['filename'] ); + } + + if ( $this->index !== null ) { + $this->getInput(); + if ( $this->input ) { + $line = self::getLineNumber(); + $this->message .= ' on line '.$line.', column '.self::getColumn(); + + $lines = explode( "\n", $this->input ); + + $count = count( $lines ); + $start_line = max( 0, $line - 3 ); + $last_line = min( $count, $start_line + 6 ); + $num_len = strlen( $last_line ); + for ( $i = $start_line; $i < $last_line; $i++ ) { + $this->message .= "\n".str_pad( $i + 1, $num_len, '0', STR_PAD_LEFT ).'| '.$lines[$i]; + } + } + } + + } + + /** + * Returns the line number the error was encountered + * + * @return integer + */ + public function getLineNumber() { + if ( $this->index ) { + // https://bugs.php.net/bug.php?id=49790 + if ( ini_get( "mbstring.func_overload" ) ) { + return substr_count( substr( $this->input, 0, $this->index ), "\n" ) + 1; + } else { + return substr_count( $this->input, "\n", 0, $this->index ) + 1; + } + } + return 1; + } + + /** + * Returns the column the error was encountered + * + * @return integer + */ + public function getColumn() { + $part = substr( $this->input, 0, $this->index ); + $pos = strrpos( $part, "\n" ); + return $this->index - $pos; + } + +} -- cgit v1.2.3