diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -177,7 +177,9 @@ 'PhutilInRequestKeyValueCache' => 'cache/PhutilInRequestKeyValueCache.php', 'PhutilInfrastructureTestCase' => '__tests__/PhutilInfrastructureTestCase.php', 'PhutilInteractiveEditor' => 'console/PhutilInteractiveEditor.php', + 'PhutilInvalidRuleParserGeneratorException' => 'parser/generator/exception/PhutilInvalidRuleParserGeneratorException.php', 'PhutilInvisibleSyntaxHighlighter' => 'markup/syntax/highlighter/PhutilInvisibleSyntaxHighlighter.php', + 'PhutilIrreducibleRuleParserGeneratorException' => 'parser/generator/exception/PhutilIrreducibleRuleParserGeneratorException.php', 'PhutilJIRAAuthAdapter' => 'auth/PhutilJIRAAuthAdapter.php', 'PhutilJSON' => 'parser/PhutilJSON.php', 'PhutilJSONParser' => 'parser/PhutilJSONParser.php', @@ -231,12 +233,7 @@ 'PhutilPHPObjectProtocolChannelTestCase' => 'channel/__tests__/PhutilPHPObjectProtocolChannelTestCase.php', 'PhutilParserGenerator' => 'parser/PhutilParserGenerator.php', 'PhutilParserGeneratorException' => 'parser/generator/exception/PhutilParserGeneratorException.php', - 'PhutilParserGeneratorInvalidRuleException' => 'parser/generator/exception/PhutilParserGeneratorInvalidRuleException.php', - 'PhutilParserGeneratorIrreducibleRuleException' => 'parser/generator/exception/PhutilParserGeneratorIrreducibleRuleException.php', 'PhutilParserGeneratorTestCase' => 'parser/__tests__/PhutilParserGeneratorTestCase.php', - 'PhutilParserGeneratorUnknownSymbolException' => 'parser/generator/exception/PhutilParserGeneratorUnknownSymbolException.php', - 'PhutilParserGeneratorUnreachableRuleException' => 'parser/generator/exception/PhutilParserGeneratorUnreachableRuleException.php', - 'PhutilParserGeneratorUnreachableTerminalException' => 'parser/generator/exception/PhutilParserGeneratorUnreachableTerminalException.php', 'PhutilPayPalAPIFuture' => 'future/paypal/PhutilPayPalAPIFuture.php', 'PhutilPerson' => 'internationalization/PhutilPerson.php', 'PhutilPersonTest' => 'internationalization/__tests__/PhutilPersonTest.php', @@ -322,6 +319,9 @@ 'PhutilURITestCase' => 'parser/__tests__/PhutilURITestCase.php', 'PhutilUTF8StringTruncator' => 'utils/PhutilUTF8StringTruncator.php', 'PhutilUTF8TestCase' => 'utils/__tests__/PhutilUTF8TestCase.php', + 'PhutilUnknownSymbolParserGeneratorException' => 'parser/generator/exception/PhutilUnknownSymbolParserGeneratorException.php', + 'PhutilUnreachableRuleParserGeneratorException' => 'parser/generator/exception/PhutilUnreachableRuleParserGeneratorException.php', + 'PhutilUnreachableTerminalParserGeneratorException' => 'parser/generator/exception/PhutilUnreachableTerminalParserGeneratorException.php', 'PhutilUrisprintfTestCase' => 'xsprintf/__tests__/PhutilUrisprintfTestCase.php', 'PhutilUtilsTestCase' => 'utils/__tests__/PhutilUtilsTestCase.php', 'PhutilWordPressAuthAdapter' => 'auth/PhutilWordPressAuthAdapter.php', @@ -595,6 +595,8 @@ 'PhutilHgsprintfTestCase' => 'PhutilTestCase', 'PhutilInRequestKeyValueCache' => 'PhutilKeyValueCache', 'PhutilInfrastructureTestCase' => 'PhutilTestCase', + 'PhutilInvalidRuleParserGeneratorException' => 'PhutilParserGeneratorException', + 'PhutilIrreducibleRuleParserGeneratorException' => 'PhutilParserGeneratorException', 'PhutilJIRAAuthAdapter' => 'PhutilOAuth1AuthAdapter', 'PhutilJSONParserException' => 'Exception', 'PhutilJSONParserTestCase' => 'PhutilTestCase', @@ -635,12 +637,7 @@ 'PhutilPHPObjectProtocolChannel' => 'PhutilProtocolChannel', 'PhutilPHPObjectProtocolChannelTestCase' => 'PhutilTestCase', 'PhutilParserGeneratorException' => 'Exception', - 'PhutilParserGeneratorInvalidRuleException' => 'PhutilParserGeneratorException', - 'PhutilParserGeneratorIrreducibleRuleException' => 'PhutilParserGeneratorException', 'PhutilParserGeneratorTestCase' => 'PhutilTestCase', - 'PhutilParserGeneratorUnknownSymbolException' => 'PhutilParserGeneratorException', - 'PhutilParserGeneratorUnreachableRuleException' => 'PhutilParserGeneratorException', - 'PhutilParserGeneratorUnreachableTerminalException' => 'PhutilParserGeneratorException', 'PhutilPayPalAPIFuture' => 'FutureProxy', 'PhutilPersonTest' => 'PhutilPerson', 'PhutilPersonaAuthAdapter' => 'PhutilAuthAdapter', @@ -704,6 +701,9 @@ 'PhutilURITestCase' => 'PhutilTestCase', 'PhutilUTF8StringTruncator' => 'Phobject', 'PhutilUTF8TestCase' => 'PhutilTestCase', + 'PhutilUnknownSymbolParserGeneratorException' => 'PhutilParserGeneratorException', + 'PhutilUnreachableRuleParserGeneratorException' => 'PhutilParserGeneratorException', + 'PhutilUnreachableTerminalParserGeneratorException' => 'PhutilParserGeneratorException', 'PhutilUrisprintfTestCase' => 'PhutilTestCase', 'PhutilUtilsTestCase' => 'PhutilTestCase', 'PhutilWordPressAuthAdapter' => 'PhutilOAuthAuthAdapter', diff --git a/src/parser/PhutilParserGenerator.php b/src/parser/PhutilParserGenerator.php --- a/src/parser/PhutilParserGenerator.php +++ b/src/parser/PhutilParserGenerator.php @@ -207,7 +207,7 @@ } else { foreach ($variant as $symbol) { if (($symbol === null) && count($variant) > 1) { - throw new PhutilParserGeneratorInvalidRuleException( + throw new PhutilInvalidRuleParserGeneratorException( "Rule '{$rule_name}' contains a production '{$vkey}' which ". "is nonempty but has a null in it. A rule with other symbols ". "may not contain null."); @@ -237,7 +237,7 @@ continue; } $production_string = implode(' ', $production); - throw new PhutilParserGeneratorUnknownSymbolException( + throw new PhutilUnknownSymbolParserGeneratorException( "Symbol '{$symbol}' in production '{$production_name}' ". "('{$production_string}') of rule '{$rule}' does not name a rule ". "or terminal. Did you misspell a symbol, fail to specify a ". @@ -254,7 +254,7 @@ private function validateStartRule() { $start_rule = $this->getStartRule(); if (!$this->isRule($start_rule)) { - throw new PhutilParserGeneratorUnknownSymbolException( + throw new PhutilUnknownSymbolParserGeneratorException( "Start rule '{$start_rule}' does not appear in the rules for the ". "grammar. Use setStartRule() to choose a different start rule, or ". "add a rule named '{$start_rule}'."); @@ -318,7 +318,7 @@ if ($missing) { $missing_terminals = array_keys($missing); $missing_terminals = implode(', ', $missing_terminals); - throw new PhutilParserGeneratorUnreachableTerminalException( + throw new PhutilUnreachableTerminalParserGeneratorException( 'Some terminals do not appear in any rule: '. $missing_terminals); } @@ -338,7 +338,7 @@ if ($missing) { $missing_rules = array_keys($missing); $missing_rules = implode(', ', $missing_rules); - throw new PhutilParserGeneratorUnreachableRuleException( + throw new PhutilUnreachableRuleParserGeneratorException( 'Some rules can never be reached from any production: '. $missing_rules); } @@ -375,7 +375,7 @@ $reducible = array(); foreach ($this->rules as $rule => $productions) { if (!$this->isRuleReducible($rule, $reducible)) { - throw new PhutilParserGeneratorIrreducibleRuleException( + throw new PhutilIrreducibleRuleParserGeneratorException( "Rule '{$rule}' can never be reduced: it recurses indefinitely ". "and reaches no production of terminals."); } diff --git a/src/parser/__tests__/PhutilParserGeneratorTestCase.php b/src/parser/__tests__/PhutilParserGeneratorTestCase.php --- a/src/parser/__tests__/PhutilParserGeneratorTestCase.php +++ b/src/parser/__tests__/PhutilParserGeneratorTestCase.php @@ -15,7 +15,7 @@ try { // Expect "b is not a rule or terminal". $generator->processGrammar(); - } catch (PhutilParserGeneratorUnknownSymbolException $ex) { + } catch (PhutilUnknownSymbolParserGeneratorException $ex) { $caught = $ex; } @@ -35,7 +35,7 @@ try { // Expect "no start rule Q". $generator->processGrammar(); - } catch (PhutilParserGeneratorUnknownSymbolException $ex) { + } catch (PhutilUnknownSymbolParserGeneratorException $ex) { $caught = $ex; } @@ -107,7 +107,7 @@ $caught = null; try { $generator->processGrammar(); - } catch (PhutilParserGeneratorUnreachableTerminalException $ex) { + } catch (PhutilUnreachableTerminalParserGeneratorException $ex) { $caught = $ex; } @@ -128,7 +128,7 @@ $caught = null; try { $generator->processGrammar(); - } catch (PhutilParserGeneratorUnreachableRuleException $ex) { + } catch (PhutilUnreachableRuleParserGeneratorException $ex) { $caught = $ex; } @@ -180,7 +180,7 @@ $caught = null; try { $generator->processGrammar(); - } catch (PhutilParserGeneratorIrreducibleRuleException $ex) { + } catch (PhutilIrreducibleRuleParserGeneratorException $ex) { $caught = $ex; } diff --git a/src/parser/generator/exception/PhutilInvalidRuleParserGeneratorException.php b/src/parser/generator/exception/PhutilInvalidRuleParserGeneratorException.php new file mode 100644 --- /dev/null +++ b/src/parser/generator/exception/PhutilInvalidRuleParserGeneratorException.php @@ -0,0 +1,4 @@ +