mirror of
https://github.com/processing/processing4.git
synced 2026-01-26 18:01:07 +01:00
Closes #290: Support detection of mixed modes in preproc.
Make a more friendly error message when the user is mixing modes, allowing for localization of error.
This commit is contained in:
@@ -316,6 +316,23 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
footerResult = prepareFooter(rewriter, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enterWarnMixedModes(ProcessingParser.WarnMixedModesContext ctx) {
|
||||
pdeParseTreeErrorListenerMaybe.ifPresent((listener) -> {
|
||||
Token token = ctx.getStart();
|
||||
int line = token.getLine();
|
||||
int charOffset = token.getCharPositionInLine();
|
||||
|
||||
listener.onError(new PdePreprocessIssue(
|
||||
line,
|
||||
charOffset,
|
||||
PreprocessIssueMessageSimplifier.getLocalStr(
|
||||
"editor.status.bad.mixed_mode"
|
||||
)
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint for ANTLR to call when finished parsing a method invocatino.
|
||||
*
|
||||
@@ -770,7 +787,7 @@ public class PdeParseTreeListener extends ProcessingBaseListener {
|
||||
* @return True if setup and false otherwise.
|
||||
*/
|
||||
protected boolean isMethodSetup(ParserRuleContext declaration) {
|
||||
if (declaration.getChildCount() < 2) {
|
||||
if (declaration == null || declaration.getChildCount() < 2) {
|
||||
return false;
|
||||
}
|
||||
return declaration.getChild(1).getText().equals("setup");
|
||||
|
||||
@@ -23,6 +23,7 @@ processingSketch
|
||||
: javaProcessingSketch
|
||||
| staticProcessingSketch
|
||||
| activeProcessingSketch
|
||||
| warnMixedModes
|
||||
;
|
||||
|
||||
// java mode, is a compilation unit
|
||||
@@ -30,20 +31,26 @@ javaProcessingSketch
|
||||
: packageDeclaration? importDeclaration* typeDeclaration+ EOF
|
||||
;
|
||||
|
||||
// No method declarations, just statements
|
||||
staticProcessingSketch
|
||||
: (importDeclaration | blockStatement)* EOF
|
||||
;
|
||||
|
||||
// active mode, has function definitions
|
||||
activeProcessingSketch
|
||||
: (importDeclaration | classBodyDeclaration)* EOF
|
||||
;
|
||||
: (importDeclaration | classBodyDeclaration)* EOF
|
||||
;
|
||||
|
||||
variableDeclaratorId
|
||||
: warnTypeAsVariableName
|
||||
| IDENTIFIER ('[' ']')*
|
||||
;
|
||||
|
||||
warnMixedModes
|
||||
: (importDeclaration | classBodyDeclaration | blockStatement)* blockStatement classBodyDeclaration (importDeclaration | classBodyDeclaration | blockStatement)*
|
||||
| (importDeclaration | classBodyDeclaration | blockStatement)* classBodyDeclaration blockStatement (importDeclaration | classBodyDeclaration | blockStatement)*
|
||||
;
|
||||
|
||||
// bug #93
|
||||
// https://github.com/processing/processing/issues/93
|
||||
// prevent from types being used as variable names
|
||||
|
||||
@@ -405,4 +405,9 @@ public class ParserTests {
|
||||
expectGood("sizethis");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixing() {
|
||||
expectRunnerException("mixing", 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user