All Downloads are FREE. Search and download functionalities are using the official Maven repository.

s.wonton.1.29.source-code.wonton.jj Maven / Gradle / Ivy

/*
 * Copyright (C) 2015 fuwjax.org ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
options {
      STATIC = false;
      SUPPORT_CLASS_VISIBILITY_PUBLIC = true;
      ERROR_REPORTING = false;
      JAVA_UNICODE_ESCAPE = true;
      UNICODE_INPUT = true;
      NODE_USES_PARSER = false;
      VISITOR = false;
}

PARSER_BEGIN(WontonParser)
package org.fuwjax.oss.wonton;

public class WontonParser {

    public WontonParser() {
        super();
    }
}

PARSER_END(WontonParser)

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

TOKEN: {
	"null" |
	"true" | "false" |
	"{" | "[" | "<" | "(" | ")" | ">" | "]" | "}" |
	"," | ":" | "="
}

TOKEN: {
    <#DIGIT: ["0" - "9"] > 
    <#NZ_DIGIT: ["1" - "9"] >
     |  )? >
         |   |   |    >
    |   )? (  |  ) >
    |     >
    |     >
    |    )+ >
}

// string literals
TOKEN: {
         )* "\"" >
    |   
}

Object parse() #void:
{
Object o = null;
}
{
    ( o=object() | o=array() )
    {
        return o;

    }
}

Object object() #void:
{
Map m = new LinkedHashMap();
}
{
     ( members(m) )? 
    {
        return m;
    }
}

void members(Map m) #void:
{
}
{
    pair(m) [  members(m) ]
}

void pair(Map m) #void:
{
Token t = null;
Object o;
}
{
    t=  o=value()
    {
        m.put(t.image, o);
    }
}

Object array() #void:
{
List a=new ArrayList();
}
{
     ( elements(a) )? 
    {
        Collections.reverse(a);
        return a;
    }
}

void elements(List a) #void:
{
Object o = null;
}
{
    o=value() [  elements(a) ]
    {
        a.add(o);
    }
}

Object value() #void:
{
Token t = null;
Object o = null;
}
{
    (   o=object()
    |   o=array() 
    |   t= {o = t.image;}
    |   t=
        {
            try {
              o = Integer.valueOf(t.image);

            }
            catch (NumberFormatException nfe1) {
                try {
                    o = Long.valueOf(t.image);
                }
                catch (NumberFormatException nfe2) {
                    try {
                        o = Float.valueOf(t.image);
                    }
                    catch (NumberFormatException nfe3) {
                        try {
                            o = Double.valueOf(t.image);
                        }
                        catch  (NumberFormatException nfe4) {
                            o = Double.NaN;
                        }
                    }
                }

            }
        }
    |    {o = Boolean.TRUE;}
    |    {o = Boolean.FALSE;}
    |    )
    {
        return o;

    }
}