public function ReadChar($parseComments = true, $rewind = false) { $this->char = fgetc($this->handle); if ($parseComments && PawnElement\PawnComment::IsPawnElement($this)) { $this->Jump(-1); $pawnComment = new PawnElement\PawnComment($this); $pawnComment->Parse(); // Push the comment to our callback function if (is_callable($this->callback)) { call_user_func($this->callback, $pawnComment); } // Save this comment, so we can possibly connect // it to the next element on the next line. $this->lastComment = $pawnComment; $this->linebreaksSinceLastComment = 0; //$this->Jump(-1); $this->char = fgetc($this->handle); //return $this->char; //return false; } if ($rewind) { $this->Jump(-1); } else { if ($this->char == "\n") { $this->lineNumber++; $this->linebreaksSinceLastComment++; } } return $this->char; }
protected function ParseBody() { $pp = $this->pawnParser; $body = ''; $braceLevel = 0; $inString = false; $stringType = 0; // " = 1, ' = 2 while (($char = $pp->ReadChar(false)) !== false) { if (PawnComment::IsPawnElement($pp)) { $pp->Jump(-1); $comment = new PawnComment($pp); $comment->Parse(); $body .= $comment->GetRaw(); continue; } if ($braceLevel == 0) { if ($char == ';') { break; } } if ($char == '"') { if ($inString) { if ($stringType == 1) { $inString = false; } } else { $inString = true; $stringType = 1; } } else { if ($char == '\'') { if ($inString) { if ($stringType == 2) { $inString = false; } } else { $inString = true; $stringType = 2; } } } if ($char == '{' && !$inString) { if ($braceLevel == 0) { $braceLevel++; $body = ''; $this->bodyLineStart = $pp->GetLine(); continue; } $braceLevel++; } else { if ($char == '}' && !$inString) { $braceLevel--; if ($braceLevel === 0) { break; } } } $body .= $char; } $this->body = $body; $this->lineEnd = $pp->GetLine(); }