options { /* JAVA_UNICODE_ESCAPE=true; UNICODE_INPUT=true;*/ LOOKAHEAD=2; IGNORE_CASE=true; KEEP_LINE_COLUMN=true; STATIC=false; } PARSER_BEGIN(ValuesFile) package org.biolegato.database; /* * ValuesFile.jj * * Created on January 30, 2008, 11:58 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ import java.io.BufferedReader; import javax.swing.filechooser.FileFilter; import java.io.File; import java.io.IOException; import java.io.Reader; import java.util.Map; import java.util.HashMap; import java.util.Collections; import org.biopcd.widgets.Widget; import org.biolegato.main.DataCanvas; /** * File format parser for a PCD values file ** * @author Graham Alvare * @author Brian Fristensky */ public class ValuesFile { public static void readValues(Reader currentFile, Map widgets) throws IOException { try { // TODO: implement overwrite feature ValuesFile parser = new ValuesFile(currentFile); parser.parse(widgets); } catch (ParseException pe) { pe.printStackTrace(System.err); } } } PARSER_END(ValuesFile) void parse(Map widgets) : { } { parseRow(widgets) ( parseRow(widgets) )* [ ] } void parseRow(Map results) : { String key; String value; } { key = parseColumn() value = parseColumn() { results.get(key).setValue(value); } } String parseColumn() : { Token t; String result = ""; } { ( t= { result = t.image; } | t= { result = t.image; } | t= { result = t.image; } )? { return result; } } TOKEN: { < SQSTART: "'" > : SQUOTE | < DQSTART: "\"" > : DQUOTE | < CDELIM: ( [":","="] ) > | < RDELIM: ( "\r\n" | "\n" | "\r" )+ > | < CHAR: ( ~["=",":"," ","'","\"","\t","\n"] )+ > } TOKEN: { < SQEND: "'" > : DEFAULT | < SCHAR: ( ~["'"] | "''" )+ > } TOKEN: { < DQEND: "\"" > : DEFAULT | < DCHAR: ( ~["\""] | "\"\"" )+ > } SKIP: { < WSP: ( [" ","\t"] ) > }