Skip to content

Commit

Permalink
jflex: add %suppress and %warn directives
Browse files Browse the repository at this point in the history
  • Loading branch information
lsf37 committed Jan 5, 2023
1 parent cd9bbd5 commit c1648cf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
5 changes: 3 additions & 2 deletions jflex/src/main/java/jflex/l10n/ErrorMessages.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ public enum ErrorMessages {
DOUBLE_CHARSET,
NOT_CHARCLASS,
MACRO_UNUSED,
UNKNOWN_WARNING;
UNKNOWN_WARNING,
NOT_A_WARNING_ID;

private static Set<ErrorMessages> configurableWarnings =
private static final Set<ErrorMessages> configurableWarnings =
new HashSet<>(
Arrays.asList(
NEVER_MATCH, EMPTY_MATCH, CTOR_DEBUG, NOT_AT_BOL, MACRO_UNUSED, CUPSYM_AFTER_CUP));
Expand Down
2 changes: 1 addition & 1 deletion jflex/src/main/java/jflex/option/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class Options {

/** Warnings that should not be printed. */
private static Set<ErrorMessages> suppressedWarnings = new HashSet<>();
private static final Set<ErrorMessages> suppressedWarnings = new HashSet<>();

/** output directory */
public static File directory;
Expand Down
16 changes: 16 additions & 0 deletions jflex/src/main/jflex/LexScan.flex
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ ArrType = ({GenParam} {WSP}*)? {QClassT} ({WSP}* {Array})*
IdentStart = [:jletter:]
IdentPart = [:jletterdigit:]

WarningIdent = [a-zA-Z_\-]+

JFlexCommentChar = [^*/]|"/"+[^*/]|"*"+[^*/]
JFlexComment = {JFlexCommentChar}+

Expand Down Expand Up @@ -265,6 +267,20 @@ DottedVersion = [1-9][0-9]*(\.[0-9]+){0,2}
"%scanerror" {WSP}+ {QualIdent} {WSP}* { scanErrorException = yytext().substring(11).trim(); }
"%scanerror" {WSP}+ {NNL}* { throw new ScannerException(file,ErrorMessages.QUIL_SCANERROR, yyline); }

// Java-ish style
"%suppress" {WSP}+ "all" {WSP}* { OptionUtils.suppressAllWarnings(); }
"%suppress" {WSP}+ {WarningIdent} {WSP}* { OptionUtils.suppressWarning(yytext().substring(10).trim()); }
"%suppress" {WSP}+ {NNL}* { throw new ScannerException(file, ErrorMessages.NOT_A_WARNING_ID, yyline); }

// CLI style
"%no-warn" {WSP}+ "all" {WSP}* { OptionUtils.suppressAllWarnings(); }
"%no-warn" {WSP}+ {WarningIdent} {WSP}* { OptionUtils.suppressWarning(yytext().substring(9).trim()); }
"%no-warn" {WSP}+ {NNL}* { throw new ScannerException(file, ErrorMessages.NOT_A_WARNING_ID, yyline); }

"%warn" {WSP}+ "all" {WSP}* { OptionUtils.enableAllWarnings(); }
"%warn" {WSP}+ {WarningIdent} {WSP}* { OptionUtils.enableWarning(yytext().substring(6).trim()); }
"%warn" {WSP}+ {NNL}* { throw new ScannerException(file, ErrorMessages.NOT_A_WARNING_ID, yyline); }

{Ident} { return symbol(IDENT, yytext()); }
"="{WSP}* { yybegin(REGEXP);
return symbol(EQUALS);
Expand Down
1 change: 1 addition & 0 deletions jflex/src/main/resources/jflex/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ DOUBLE_CHARSET = Character set already declared.
NOT_CHARCLASS = Expression inside [..] must expand to a character class.
MACRO_UNUSED = Macro "{0}" has been declared but never used.
UNKNOWN_WARNING = Warning type "{0}" unknown or not configurable.
NOT_A_WARNING_ID = Warning type unknown.

0 comments on commit c1648cf

Please sign in to comment.