/** * Throws a {@link ParseException} if an error or warning occurred while parsing the input * * @throws ParseException if an error or warning occurred while parsing. */ public void throwOnErrorOrWarning() throws ParseException { if (!getProblemCollector().isEmpty()) { throw ParseException.create(getProblemCollector()); } }
/** * Throws a {@link ParseException} if an error or warning occurred while parsing the input * * @throws ParseException if an error or warning occurred while parsing. */ public void throwOnErrorOrWarning() throws ParseException { if (!getProblemCollector().isEmpty()) { throw ParseException.create(getProblemCollector()); } }
/** * Adds a warning to the internal problem collector. * <p> * A warning indicates an anomaly which might lead to an error but still, the parser can continue to complete its * work. * * @param pos the position of the warning. Note that {@link Token} implements {@link Position}. * Therefore the current token is often a good choice for this parameter. * @param message the message to describe the earning. Can contain formatting parameters like %s or %d as * defined by {@link String#format(String, Object...)} * @param parameters Contains the parameters used to format the given message */ public void addWarning(Position pos, String message, Object... parameters) { getProblemCollector().add(ParseError.warning(pos, String.format(message, parameters))); }
/** * Throws a {@link ParseException} if an error occurred while parsing the input. * <p> * All warnings which occurred will be ignored. * * @throws ParseException if an error occurred while parsing. */ public void throwOnError() throws ParseException { for (ParseError e : getProblemCollector()) { if (e.getSeverity() == ParseError.Severity.ERROR) { throw ParseException.create(getProblemCollector()); } } } }
/** * Throws a {@link ParseException} if an error occurred while parsing the input. * <p> * All warnings which occurred will be ignored. * * @throws ParseException if an error occurred while parsing. */ public void throwOnError() throws ParseException { for (ParseError e : getProblemCollector()) { if (e.getSeverity() == ParseError.Severity.ERROR) { throw ParseException.create(getProblemCollector()); } } } }
/** * Adds a parse error to the internal problem collector. * <p> * It is preferred to collect as much errors as possible and then fail with an exception instead of failing * at the first problem. Often syntax errors can be worked out by the parser and we can report a set of * errors at once. * * @param pos the position of the error. Note that {@link Token} implements {@link Position}. Therefore the * current token is often a good choice for this parameter. * @param message the message to describe the error. Can contain formatting parameters like %s or %d as defined * by {@link String#format(String, Object...)} * @param parameters Contains the parameters used to format the given message */ public void addError(Position pos, String message, Object... parameters) { getProblemCollector().add(ParseError.error(pos, String.format(message, parameters))); }
/** * Adds a warning to the internal problem collector. * <p> * A warning indicates an anomaly which might lead to an error but still, the parser can continue to complete its * work. * * @param pos the position of the warning. Note that {@link Token} implements {@link Position}. * Therefore the current token is often a good choice for this parameter. * @param message the message to describe the earning. Can contain formatting parameters like %s or %d as * defined by {@link String#format(String, Object...)} * @param parameters Contains the parameters used to format the given message */ public void addWarning(Position pos, String message, Object... parameters) { getProblemCollector().add(ParseError.warning(pos, String.format(message, parameters))); }
/** * Adds a parse error to the internal problem collector. * <p> * It is preferred to collect as much errors as possible and then fail with an exception instead of failing * at the first problem. Often syntax errors can be worked out by the parser and we can report a set of * errors at once. * * @param pos the position of the error. Note that {@link Token} implements {@link Position}. Therefore the * current token is often a good choice for this parameter. * @param message the message to describe the error. Can contain formatting parameters like %s or %d as defined * by {@link String#format(String, Object...)} * @param parameters Contains the parameters used to format the given message */ public void addError(Position pos, String message, Object... parameters) { getProblemCollector().add(ParseError.error(pos, String.format(message, parameters))); }