Path: blob/master/src/infrastructure/lipsum/code/PhutilJavaCodeSnippetContextFreeGrammar.php
12256 views
<?php12final class PhutilJavaCodeSnippetContextFreeGrammar3extends PhutilCLikeCodeSnippetContextFreeGrammar {45protected function buildRuleSet() {6$parent_ruleset = parent::buildRuleSet();7$rulesset = array_merge($parent_ruleset, $this->getClassRuleSets());89$rulesset[] = $this->getTypeNameGrammarSet();10$rulesset[] = $this->getNamespaceDeclGrammarSet();11$rulesset[] = $this->getNamespaceNameGrammarSet();12$rulesset[] = $this->getImportGrammarSet();13$rulesset[] = $this->getMethodReturnTypeGrammarSet();14$rulesset[] = $this->getMethodNameGrammarSet();15$rulesset[] = $this->getVarDeclGrammarSet();16$rulesset[] = $this->getClassDerivGrammarSet();1718return $rulesset;19}2021protected function getStartGrammarSet() {22return $this->buildGrammarSet('start',23array(24'[import, block][nmspdecl, block][classdecl, block]',25));26}2728protected function getClassDeclGrammarSet() {29return $this->buildGrammarSet('classdecl',30array(31'[classinheritancemod] [visibility] class [classname][classderiv] '.32'{[classbody, indent, block]}',33'[visibility] class [classname][classderiv] '.34'{[classbody, indent, block]}',35));36}3738protected function getClassDerivGrammarSet() {39return $this->buildGrammarSet('classderiv',40array(41' extends [classname]',42'',43'',44));45}4647protected function getTypeNameGrammarSet() {48return $this->buildGrammarSet('type',49array(50'int',51'boolean',52'char',53'short',54'long',55'float',56'double',57'[classname]',58'[type][]',59));60}6162protected function getMethodReturnTypeGrammarSet() {63return $this->buildGrammarSet('methodreturn',64array(65'[type]',66'void',67));68}6970protected function getNamespaceDeclGrammarSet() {71return $this->buildGrammarSet('nmspdecl',72array(73'package [nmspname][term]',74));75}7677protected function getNamespaceNameGrammarSet() {78return $this->buildGrammarSet('nmspname',79array(80'java.lang',81'java.io',82'com.example.proj.std',83'derp.example.www',84));85}8687protected function getImportGrammarSet() {88return $this->buildGrammarSet('import',89array(90'import [nmspname][term]',91'import [nmspname].*[term]',92'import [nmspname].[classname][term]',93));94}9596protected function getExprGrammarSet() {97$expr = parent::getExprGrammarSet();9899$expr['expr'][] = 'new [classname]([funccallparam])';100101$expr['expr'][] = '[methodcall]';102$expr['expr'][] = '[methodcall]';103$expr['expr'][] = '[methodcall]';104$expr['expr'][] = '[methodcall]';105106// Add some 'char's107for ($ii = 0; $ii < 2; $ii++) {108$expr['expr'][] = "'".Filesystem::readRandomCharacters(1)."'";109}110111return $expr;112}113114protected function getStmtGrammarSet() {115$stmt = parent::getStmtGrammarSet();116117$stmt['stmt'][] = '[vardecl]';118$stmt['stmt'][] = '[vardecl]';119// `try` to `throw` a `Ball`!120$stmt['stmt'][] = 'throw [classname][term]';121122return $stmt;123}124125protected function getPropDeclGrammarSet() {126return $this->buildGrammarSet('propdecl',127array(128'[visibility] [type] [varname][term]',129));130}131132protected function getVarDeclGrammarSet() {133return $this->buildGrammarSet('vardecl',134array(135'[type] [varname][term]',136'[type] [assignment][term]',137));138}139140protected function getFuncNameGrammarSet() {141return $this->buildGrammarSet('funcname',142array(143'[methodname]',144'[classname].[methodname]',145// This is just silly (too much recursion)146// '[classname].[funcname]',147// Don't do this for now, it just clutters up output (thanks to rec.)148// '[nmspname].[classname].[methodname]',149));150}151152// Renamed from `funcname`153protected function getMethodNameGrammarSet() {154$funcnames = head(parent::getFuncNameGrammarSet());155return $this->buildGrammarSet('methodname', $funcnames);156}157158protected function getMethodFuncDeclGrammarSet() {159return $this->buildGrammarSet('methodfuncdecl',160array(161'[methodreturn] [methodname]([funcparam]) '.162'{[methodbody, indent, block, trim=right]}',163));164}165166protected function getFuncParamGrammarSet() {167return $this->buildGrammarSet('funcparam',168array(169'',170'[type] [varname]',171'[type] [varname], [type] [varname]',172'[type] [varname], [type] [varname], [type] [varname]',173));174}175176protected function getAbstractMethodDeclGrammarSet() {177return $this->buildGrammarSet('abstractmethoddecl',178array(179'abstract [methodreturn] [methodname]([funcparam])[term]',180));181}182183}184185186