Skip to content

Commit

Permalink
Fix code style and typing to support PHP 8 (#3582)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospassos committed Mar 19, 2022
1 parent b293f98 commit 69b0200
Showing 1 changed file with 37 additions and 37 deletions.
74 changes: 37 additions & 37 deletions tool/resources/org/antlr/v4/tool/templates/codegen/PHP/PHP.stg
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface <file.grammarName>Listener extends ParseTreeListener {
<endif>
* @param $context The parse tree.
*/
public function enter<lname; format="cap">(Context\\<lname; format="cap">Context $context) : void;
public function enter<lname; format="cap">(Context\\<lname; format="cap">Context $context): void;
/**
<if(file.listenerLabelRuleNames.(lname))>
* Exit a parse tree produced by the `<lname>` labeled alternative
Expand All @@ -77,7 +77,7 @@ public function enter<lname; format="cap">(Context\\<lname; format="cap">Context
<endif>
* @param $context The parse tree.
*/
public function exit<lname; format="cap">(Context\\<lname; format="cap">Context $context) : void;}; separator="\n">
public function exit<lname; format="cap">(Context\\<lname; format="cap">Context $context): void;}; separator="\n">
}
>>

Expand Down Expand Up @@ -105,42 +105,42 @@ class <file.grammarName>BaseListener implements <file.grammarName>Listener
*
* The default implementation does nothing.
*/
public function enter<lname; format="cap">(Context\\<lname; format="cap">Context $context) : void {\}
public function enter<lname; format="cap">(Context\\<lname; format="cap">Context $context): void {\}

/**
* {@inheritdoc\}
*
* The default implementation does nothing.
*/
public function exit<lname; format="cap">(Context\\<lname; format="cap">Context $context) : void {\}}; separator="\n">
public function exit<lname; format="cap">(Context\\<lname; format="cap">Context $context): void {\}}; separator="\n">

/**
* {@inheritdoc\}
*
* The default implementation does nothing.
*/
public function enterEveryRule(ParserRuleContext $context) : void {}
public function enterEveryRule(ParserRuleContext $context): void {}

/**
* {@inheritdoc\}
*
* The default implementation does nothing.
*/
public function exitEveryRule(ParserRuleContext $context) : void {}
public function exitEveryRule(ParserRuleContext $context): void {}

/**
* {@inheritdoc\}
*
* The default implementation does nothing.
*/
public function visitTerminal(TerminalNode $node) : void {}
public function visitTerminal(TerminalNode $node): void {}

/**
* {@inheritdoc\}
*
* The default implementation does nothing.
*/
public function visitErrorNode(ErrorNode $node) : void {}
public function visitErrorNode(ErrorNode $node): void {}
}
>>

Expand Down Expand Up @@ -267,7 +267,7 @@ namespace<if(file.genPackage)> <file.genPackage><endif> {

<parser:(ctor)()>

private static function initialize() : void
private static function initialize(): void
{
if (self::$atn !== null) {
return;
Expand All @@ -287,27 +287,27 @@ namespace<if(file.genPackage)> <file.genPackage><endif> {
self::$sharedContextCache = new PredictionContextCache();
}

public function getGrammarFileName() : string
public function getGrammarFileName(): string
{
return "<parser.grammarFileName>";
}

public function getRuleNames() : array
public function getRuleNames(): array
{
return self::RULE_NAMES;
}

public function getSerializedATN() : array
public function getSerializedATN(): array
{
return self::SERIALIZED_ATN;
}

public function getATN() : ATN
public function getATN(): ATN
{
return self::$atn;
}

public function getVocabulary() : Vocabulary
public function getVocabulary(): Vocabulary
{
static $vocabulary;

Expand All @@ -319,7 +319,7 @@ namespace<if(file.genPackage)> <file.genPackage><endif> {
<endif>
<if(sempredFuncs)>

public function sempred(?RuleContext $localContext, int $ruleIndex, int $predicateIndex) : bool
public function sempred(?RuleContext $localContext, int $ruleIndex, int $predicateIndex): bool
{
switch ($ruleIndex) {
<parser.sempredFuncs.values:{f|
Expand Down Expand Up @@ -372,7 +372,7 @@ private const SYMBOLIC_NAMES = [
dumpActions(recog, argFuncs, actionFuncs, sempredFuncs) ::= <<
<if(actionFuncs)>

public function action(?RuleContext $localContext, int $ruleIndex, int $actionIndex) : void
public function action(?RuleContext $localContext, int $ruleIndex, int $actionIndex): void
{
switch ($ruleIndex) {
<recog.actionFuncs.values:{f|
Expand All @@ -386,7 +386,7 @@ public function action(?RuleContext $localContext, int $ruleIndex, int $actionIn
<endif>
<if(sempredFuncs)>

public function sempred(?RuleContext $localContext, int $ruleIndex, int $predicateIndex) : bool
public function sempred(?RuleContext $localContext, int $ruleIndex, int $predicateIndex): bool
{
switch ($ruleIndex) {
<recog.sempredFuncs.values:{f|
Expand Down Expand Up @@ -416,7 +416,7 @@ public function __construct(TokenStream $input)
* an overriding implementation impossible to maintain.
*/
RuleActionFunction(r, actions) ::= <<
private function action<r.name; format="cap">(?<r.ctxType> $localContext, int $actionIndex) : void
private function action<r.name; format="cap">(?<r.ctxType> $localContext, int $actionIndex): void
{
switch ($actionIndex) {
<actions:{index|
Expand All @@ -433,7 +433,7 @@ private function action<r.name; format="cap">(?<r.ctxType> $localContext, int $a
* an overriding implementation impossible to maintain.
*/
RuleSempredFunction(r, actions) ::= <<
private function sempred<r.name; format="cap">(?Context\\<r.ctxType> $localContext, int $predicateIndex) : bool
private function sempred<r.name; format="cap">(?Context\\<r.ctxType> $localContext, int $predicateIndex): bool
{
switch ($predicateIndex) {
<actions:{index|
Expand All @@ -449,7 +449,7 @@ RuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,namedActions,fina
/**
* @throws RecognitionException
*/
<if(currentRule.modifiers)><currentRule.modifiers:{f | <f> }><endif>public function <currentRule.name>(<args; separator=",">) : Context\\<currentRule.ctxType>
<if(currentRule.modifiers)><currentRule.modifiers:{f | <f> }><endif>public function <currentRule.name>(<args; separator=",">): Context\\<currentRule.ctxType>
{
$localContext = new Context\\<currentRule.ctxType>($this->ctx, $this->getState()<currentRule.args:{a | , $<a.name>}>);

Expand Down Expand Up @@ -478,15 +478,15 @@ LeftRecursiveRuleFunction(currentRule,args,code,locals,ruleCtx,altLabelCtxs,name
/**
* @throws RecognitionException
*/
<if(currentRule.modifiers)><currentRule.modifiers:{f | <f> }><endif>public function <currentRule.name>(<args; separator=", ">) : Context\\<currentRule.ctxType>
<if(currentRule.modifiers)><currentRule.modifiers:{f | <f> }><endif>public function <currentRule.name>(<args; separator=", ">): Context\\<currentRule.ctxType>
{
return $this->recursive<currentRule.name; format="cap">(0<currentRule.args:{a | , <a.name>}>);
}

/**
* @throws RecognitionException
*/
private function recursive<currentRule.name; format="cap">(int $precedence<args:{a | , <a>}>) : Context\\<currentRule.ctxType>
private function recursive<currentRule.name; format="cap">(int $precedence<args:{a | , <a>}>): Context\\<currentRule.ctxType>
{
$parentContext = $this->ctx;
$parentState = $this->getState();
Expand Down Expand Up @@ -863,7 +863,7 @@ public $<d.name><if(d.initValue)> = <d.initValue><endif>;}; separator="\n\n">
>>

ContextTokenGetterDecl(t) ::= <<
public function <t.name>() : ?TerminalNode
public function <t.name>(): ?TerminalNode
{
return $this->getToken(<parser.name>::<t.name>, 0);
}
Expand All @@ -887,7 +887,7 @@ public function <t.name>(?int $index = null)
>>

ContextRuleGetterDecl(r) ::= <<
public function <r.name>() : ?<r.ctxName>
public function <r.name>(): ?<r.ctxName>
{
return $this->getTypedRuleContext(<r.ctxName>::class, 0);
}
Expand Down Expand Up @@ -938,7 +938,7 @@ class <struct.name> extends <if(contextSuperClass)><contextSuperClass><else>Pars
<endif>
}

public function getRuleIndex() : int
public function getRuleIndex(): int
{
return <parser.name>::RULE_<struct.derivedFromName>;
}
Expand All @@ -947,7 +947,7 @@ class <struct.name> extends <if(contextSuperClass)><contextSuperClass><else>Pars
<getters:{g | <g>}; separator="\n\n">
<endif>
<if(struct.provideCopyFrom)> <! don't need copy unless we have subclasses !>
public function copyFrom(ParserRuleContext $context) : void
public function copyFrom(ParserRuleContext $context): void
{
parent::copyFrom($context);

Expand Down Expand Up @@ -987,7 +987,7 @@ class <struct.name> extends <struct.parentRule; format="cap">Context
>>

ListenerDispatchMethod(method) ::= <<
public function <if(method.isEnter)>enter<else>exit<endif>Rule(ParseTreeListener $listener) : void
public function <if(method.isEnter)>enter<else>exit<endif>Rule(ParseTreeListener $listener): void
{
if ($listener instanceof <parser.grammarName>Listener) {
$listener-><if(method.isEnter)>enter<else>exit<endif><struct.derivedFromName; format="cap">($this);
Expand All @@ -996,7 +996,7 @@ public function <if(method.isEnter)>enter<else>exit<endif>Rule(ParseTreeListener
>>

VisitorDispatchMethod(method) ::= <<
public function accept(ParseTreeVisitor $visitor)
public function accept(ParseTreeVisitor $visitor): mixed
{
if ($visitor instanceof <parser.grammarName>Visitor) {
return $visitor->visit<struct.derivedFromName; format="cap">($this);
Expand Down Expand Up @@ -1136,7 +1136,7 @@ namespace<if(lexerFile.genPackage)> <lexerFile.genPackage><endif> {
$this->interp = new LexerATNSimulator($this, self::$atn, self::$decisionToDFA, self::$sharedContextCache);
}

private static function initialize() : void
private static function initialize(): void
{
if (self::$atn !== null) {
return;
Expand All @@ -1156,50 +1156,50 @@ namespace<if(lexerFile.genPackage)> <lexerFile.genPackage><endif> {
self::$sharedContextCache = new PredictionContextCache();
}

public static function vocabulary() : Vocabulary
public static function vocabulary(): Vocabulary
{
static $vocabulary;

return $vocabulary = $vocabulary ?? new VocabularyImpl(self::LITERAL_NAMES, self::SYMBOLIC_NAMES);
}

public function getGrammarFileName() : string
public function getGrammarFileName(): string
{
return '<lexer.grammarFileName>';
}

public function getRuleNames() : array
public function getRuleNames(): array
{
return self::RULE_NAMES;
}

public function getSerializedATN() : array
public function getSerializedATN(): array
{
return self::SERIALIZED_ATN;
}

/**
* @return array\<string>
*/
public function getChannelNames() : array
public function getChannelNames(): array
{
return self::CHANNEL_NAMES;
}

/**
* @return array\<string>
*/
public function getModeNames() : array
public function getModeNames(): array
{
return self::MODE_NAMES;
}

public function getATN() : ATN
public function getATN(): ATN
{
return self::$atn;
}

public function getVocabulary() : Vocabulary
public function getVocabulary(): Vocabulary
{
return self::vocabulary();
}
Expand Down

0 comments on commit 69b0200

Please sign in to comment.