Package processing.mode.java.preproc
Class PreprocessIssueMessageSimplifier
java.lang.Object
processing.mode.java.preproc.PreprocessIssueMessageSimplifier
Utility class that generates localized error messages for incorrect sketch syntax.
Utility that interprets error messages from ANTLR in an attempt to generate an improved error message when describing grammatically incorrect input. This is distinct from compiler errors caused after generating an AST. This is required to produce the localized error messages.
Note that this is distinct from the {CompileErrorMessageSimplifier}. This operates on issues caused in parsing and services all users whereas the {CompileErrorMessageSimplifier} only operates on issues generated after preprocessing has been successful.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classSingleton with fallback error localizations.protected static classDefault strategy to use if other message simplification strategies have failed.protected static classStrategy to check to make sure that the number of occurrences of a token are even.protected static interfaceInterface for strategies that improve preprocess error messages before showing them to the user.static classSimple automaton that reads backwards from a position in source to find the prior token.protected static classStrategy that cleans up errors based on a regex matching the error message.protected static classTemplate class for checking that two tokens appear in pairs. -
Method Summary
Modifier and TypeMethodDescriptionStrategy for invalid parameter.Strategy to handle extraneous input messages.Strategy for invalid assignment.Strategy for invalid generic.Strategy for invalid identifier.Strategy to handle missing token messages.Strategy for missing method name.Strategy to explain a mismatched input issue.Strategy for missing class name.Strategy to catch a missing curly at a semicolon.Strategy to catch a missing curly that got caught by ANTLR at the start of a statement.Strategy to detect uneven double quotes.Strategy to check for an error indicating that an identifier was expected but not given.Strategy to detect uneven single quotes.createRegexStrategyUsingLocalStr(String regex, String localStr) Shortcut to create a regex matcher with a localized error message.Strategy for unbalanced chevrons.Strategy for unbalanced curly braces.Strategy for unbalanced parens.Strategy for invalid variable declaration.get()Get a shared instance of this singleton.static StringgetLocalStr(String stringName) Get a localized template string.protected static StringgetOffendingArea(String area) Get the snippet of "offending code" from an error message if given.Attempt to improve an error message.
-
Method Details
-
get
Get a shared instance of this singleton.- Returns:
- Shared instance of this singleton, creating that shared instance if one did not exist previously.
-
getLocalStr
Get a localized template string.- Parameters:
stringName- Name of the template.- Returns:
- The template's contents prior to rendering.
-
simplify
Attempt to improve an error message.- Parameters:
originalMessage- Error message generated from ANTLR.- Returns:
- An improved error message or the originalMessage if no improvements could be made.
-
getOffendingArea
Get the snippet of "offending code" from an error message if given.- Parameters:
area- The area from which to extract the offending code.- Returns:
- The offending code described in the error message or the original message if the subset describing the offending code could not be found.
-
createMissingSingleQuoteStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createMissingSingleQuoteStrategy()Strategy to detect uneven single quotes. -
createMissingDoubleQuoteStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createMissingDoubleQuoteStrategy()Strategy to detect uneven double quotes. -
createUnbalancedCurlyStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createUnbalancedCurlyStrategy()Strategy for unbalanced curly braces. -
createUnbalancedChevStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createUnbalancedChevStrategy()Strategy for unbalanced chevrons. -
createUnbalancedParenStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createUnbalancedParenStrategy()Strategy for unbalanced parens. -
createRegexStrategyUsingLocalStr
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createRegexStrategyUsingLocalStr(String regex, String localStr) Shortcut to create a regex matcher with a localized error message.- Parameters:
regex- The regex to match.localStr- The localized string identifier to use when the regex matches.- Returns:
- Newly created simplifier strategy.
-
createErrorOnParameterStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createErrorOnParameterStrategy()Strategy for invalid parameter. -
createMethodMissingNameStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createMethodMissingNameStrategy()Strategy for missing method name. -
createMissingClassNameStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createMissingClassNameStrategy()Strategy for missing class name. -
createInvalidIdentifierStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createInvalidIdentifierStrategy()Strategy for invalid identifier. -
createVariableDeclarationMissingTypeStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createVariableDeclarationMissingTypeStrategy()Strategy for invalid variable declaration. -
createInvalidAssignmentStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createInvalidAssignmentStrategy()Strategy for invalid assignment. -
createInvalidGenericDefinitionStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createInvalidGenericDefinitionStrategy()Strategy for invalid generic. -
createMissingCurlyAtStartSimplifierStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createMissingCurlyAtStartSimplifierStrategy()Strategy to catch a missing curly that got caught by ANTLR at the start of a statement. -
createMissingCurlyAtSemicolonSimplifierStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createMissingCurlyAtSemicolonSimplifierStrategy()Strategy to catch a missing curly at a semicolon. -
createMissingIdentifierSimplifierStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createMissingIdentifierSimplifierStrategy()Strategy to check for an error indicating that an identifier was expected but not given. -
createKnownMissingSimplifierStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createKnownMissingSimplifierStrategy()Strategy to handle missing token messages. -
createExtraneousInputSimplifierStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createExtraneousInputSimplifierStrategy()Strategy to handle extraneous input messages. -
createMismatchedInputSimplifierStrategy
protected PreprocessIssueMessageSimplifier.PreprocIssueMessageSimplifierStrategy createMismatchedInputSimplifierStrategy()Strategy to explain a mismatched input issue.
-