/** * 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()); } }
/** * Creates a new exception based on the list of errors. * * @param errors the errors which occurred while processing the user input * @return a new ParseException which can be thrown */ public static ParseException create(List<ParseError> errors) { if (errors.size() == 1) { return new ParseException(errors.get(0).getMessage(), errors); } else if (errors.size() > 1) { return new ParseException(String.format("%d errors occured. First: %s", errors.size(), errors.get(0).getMessage()), errors); } else { return new ParseException("An unknown error occured", errors); } }
/** * Resolves a given name into a template. * <p> * By default the classloader is used to resolve the template. Also .scss or _ are added as post-/prefix * if required. * * @param sheet the name of the file to resolve * @return the resolved stylesheet or <tt>null</tt> if the file is not found */ protected Stylesheet resolve(String sheet) { try { sheet = sheet.replace("\\", "/"); if (!sheet.endsWith(".scss")) { sheet += ".scss"; } try (InputStream is = resolveIntoStream(sheet)) { if (is == null) { warn("Cannot resolve '" + sheet + "'. Skipping import."); return null; } Parser p = new Parser(sheet, new InputStreamReader(is)); return p.parse(); } } catch (ParseException e) { warn(String.format("Error parsing: %s%n%s", sheet, e.toString())); } catch (Exception e) { warn(String.format("Error importing: %s: %s (%s)", sheet, e.getMessage(), e.getClass().getName())); } return null; }
/** * 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()); } }
/** * Creates a new exception based on the list of errors. * * @param errors the errors which occurred while processing the user input * @return a new ParseException which can be thrown */ public static ParseException create(List<ParseError> errors) { if (errors.size() == 1) { return new ParseException(errors.get(0).getMessage(), errors); } else if (errors.size() > 1) { return new ParseException(String.format("%d errors occured. First: %s", errors.size(), errors.get(0).getMessage()), errors); } else { return new ParseException("An unknown error occured", errors); } }
/** * 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()); } } } }
/** * Parses the expression in <tt>input</tt> * * @return the parsed expression * @throws ParseException if the expression contains one or more errors */ protected Expression parse() throws ParseException { Expression result = expression().simplify(); if (tokenizer.current().isNotEnd()) { Token token = tokenizer.consume(); errors.add(ParseError.error(token, String.format("Unexpected token: '%s'. Expected an expression.", token.getSource()))); } if (!errors.isEmpty()) { throw ParseException.create(errors); } return result; }
/** * Parses the expression in <tt>input</tt> * * @return the parsed expression * @throws ParseException if the expression contains one or more errors */ protected Expression parse() throws ParseException { Expression result = expression().simplify(); if (tokenizer.current().isNotEnd()) { Token token = tokenizer.consume(); errors.add(ParseError.error(token, String.format("Unexpected token: '%s'. Expected an expression.", token.getSource()))); } if (!errors.isEmpty()) { throw ParseException.create(errors); } return result; }
throw ParseException.create(tokenizer.getProblemCollector());