void checkOptions(GrammarAST parent, Token optionID, GrammarAST valueAST) {
		Set<String> optionsToCheck = null;
		int parentType = parent.getType();
		switch (parentType) {
			case ANTLRParser.BLOCK:
				optionsToCheck = g.isLexer() ? Grammar.lexerBlockOptions : Grammar.parserBlockOptions;
				break;
			case ANTLRParser.RULE:
				optionsToCheck = g.isLexer() ? Grammar.lexerRuleOptions : Grammar.parseRuleOptions;
				break;
			case ANTLRParser.GRAMMAR:
				optionsToCheck = g.getType() == ANTLRParser.LEXER
						? Grammar.lexerOptions
						: Grammar.parserOptions;
				break;
		}
		String optionName = optionID.getText();
		if (optionsToCheck != null && !optionsToCheck.contains(optionName)) {
			g.tool.errMgr.grammarError(ErrorType.ILLEGAL_OPTION, g.fileName, optionID, optionName);
		}
		else {
			checkCaseInsensitiveOption(optionID, valueAST, parentType);
		}
	}
Check option is appropriate for grammar, rule, subrule
tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java