/**
 *     Caption: Zaval Java Resource Editor
 *     $Revision: 0.37 $
 *     $Date: 2002/03/28 9:24:42 $
 *
 *     @author:     Victor Krapivin
 *     @version:    1.0
 *
 * Zaval JRC Editor is a visual editor which allows you to manipulate 
 * localization strings for all Java based software with appropriate 
 * support embedded.
 * 
 * For more info on this product read Zaval Java Resource Editor User's Guide
 * (It comes within this package).
 * The latest product version is always available from the product's homepage:
 * http://www.zaval.org/products/jrc-editor/
 * and from the SourceForge:
 * http://sourceforge.net/projects/zaval0002/
 *
 * Contacts:
 *   Support : support@zaval.org
 *   Change Requests : change-request@zaval.org
 *   Feedback : feedback@zaval.org
 *   Other : info@zaval.org
 * 
 * Copyright (C) 2001-2002  Zaval Creative Engineering Group (http://www.zaval.org)
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * (version 2) as published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 * 
 */
options {
  JAVA_UNICODE_ESCAPE = true;
  STATIC = false;
  ERROR_REPORTING = true;
  UNICODE_INPUT = true;
}

PARSER_BEGIN(UtfParser)

package org.zaval.tools.i18n.translator;

import java.io.*;
import java.util.*;

public class UtfParser
{
    private String key = "default";
    private Hashtable ask;

    public Hashtable parse()
    throws ParseException
    {
        ask = new Hashtable();
        parseMain();
        return ask;
    }
}

PARSER_END(UtfParser)


/* WHITE SPACE */

SKIP :
{
  " "
| "\t"
| "\r"
| "\f"
| "\n"
}

/* COMMENTS */

MORE :
{
  "#" : IN_SINGLE_LINE_COMMENT
}

<IN_SINGLE_LINE_COMMENT> SPECIAL_TOKEN :
{
  <SINGLE_LINE_COMMENT: "\n" | "\r" | "\r\n" > : DEFAULT
}

<IN_SINGLE_LINE_COMMENT> MORE :
{
  < ~[] >
}

/* RESERVED WORDS AND LITERALS */

TOKEN :
{
  < KEY: "KEY" >
| < EQ : "=" >
| < DBC: ":" >
}

/* LITERALS */

TOKEN :
{
  < STRING_LITERAL_1:
      "\""
      (   (~["\"","\\"])
        | ("\\" ( ["\\","'","\""]) )
      )*
      "\""
  >
  |
  < STRING_LITERAL_2:
      "\'"
      (   (~["\"","\\"])
        | ("\\" ( ["\\","'","\""]) )
      )*
      "\'"
  >
}

void parseMain() :
{}
{
  ( 
    keyDef(){}
    ( langPair(){} )+{} 
  )+{}
  <EOF>
}

void keyDef() :
{
    String name;
}
{   
    <KEY> <EQ> name = string(){ key = name; } <DBC>
}

void langPair() :
{
    String lang, val;
}
{
    lang = string(){} <EQ> val=string(){
        ask.put(key + "!" + lang, val);
    }
}

String string() :
{
    Token tok;
}
{
    (
        tok = <STRING_LITERAL_1>
        |
        tok = <STRING_LITERAL_2>
    ){
        return tok.image.substring(1, tok.image.length()-1);
    }
}
