/** * Compile dictionary to letter transducers * * @param file the address of the XML dictionnary to be read * @param dir the direction of the compilation, 'lr' (leftSide-to-right) or 'rl' * (right-to-leftSide) */ public void parse(String file, String dir) { try { direction = dir; XMLInputFactory factory = XMLInputFactory.newInstance(); if (file.equals("-")) { reader = factory.createXMLStreamReader(System.in); } else { reader = factory.createXMLStreamReader(new FileInputStream(file)); } while (reader.hasNext()) { procNode(); reader.next(); } reader.close(); // Minimize transducers for (TransducerComp transducer : sections.values()) { transducer.minimize(); } } catch (FileNotFoundException e) { throw new RuntimeException("Error: Cannot open '" + file + "'."); } catch (RuntimeException e) { System.err.println("Error (" + e + ") at line " + reader.getLocation().getLineNumber()); throw e; } catch (Throwable ex) { System.err.println("Error (" + ex + ") at line " + reader.getLocation().getLineNumber()); throw new RuntimeException("Error t " + reader.getLocation().getLineNumber(), ex); } }