Package anvil.script.parser

Source Code of anvil.script.parser.ExpressionParser

/*
* $Id: ExpressionParser.java,v 1.17 2002/09/16 08:05:05 jkl Exp $
*
* Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
*
* Use is subject to license terms, as defined in
* Anvil Sofware License, Version 1.1. See LICENSE
* file, or http://njet.org/license-1.1.txt
*/
package anvil.script.parser;

import anvil.ErrorListener;
import anvil.Location;
import anvil.script.Context;
import anvil.script.expression.Node;
import anvil.script.expression.Expression;
import anvil.script.expression.ExpressionList;
import anvil.script.expression.Parent;
import anvil.script.ModuleEnvelope;
import anvil.script.ParameterListDeclaration;
import java.util.Enumeration;

/**
* class ExpressionParser
*
* @author: Jani Lehtim�ki
*/
public class ExpressionParser extends ParserBase
{

  public static final int TYPE_VALUE      = 0;
  public static final int TYPE_STANDALONE = 1;
  public static final int TYPE_ASSIGNMENT = 2;
  public static final int TYPE_ASSIGNABLE = 3;

  private TemplateParser _parser;
  private Location _location = null;


  public ExpressionParser(TemplateParser parser, Location location, String expression)
  {
    super(new Tokenizer(expression));
    _parser = parser;
    _location = location;
    _current = parser.peek();
    ((Tokenizer)token_source).setParser(this);
  }


  public ModuleEnvelope getEnvelope()
  {
    return _parser.getEnvelope();
  }
 

  public Location toLocation(Token token)
  {
    return _location;
 


  public Location toLocation(int line, int column)
  {
    return _location;
 
 

  public void error(Location location, Throwable throwable)
  {
    _parser.error(location, throwable);
  }


  public void error(Location location, String message)
  {
    _parser.error(location, message);
  }


  public int errors()
  {
    return _parser.errors();
  }


  public Enumeration getEvents()
  {
    return _parser.getEvents();
  }


  public void merge(ErrorListener listener)
  {
    _parser.merge(listener);
  }


  public void parseParameterListDeclaration(ParameterListDeclaration parameters)
  {
    try {
      TerminalFunctionParameterList(parameters);
    } catch (ParseException e) {
      error(_location, e.getMessage());
    }
  }
 

  public Parent parseParameterList()
  {
    try {
      TerminalArgumentList();
      return (Parent)pop();
    } catch (ParseException e) {
      error(_location, e.getMessage());
      return new ExpressionList(0);
    }
  }
 

  public ExpressionList parseExpressionList()
  {
    try {
      TerminalList();
      return (ExpressionList)pop();
    } catch (ParseException e) {
      error(_location, e.getMessage());
      return new ExpressionList(0);
    }
  }
 


  public Object[] parseForExpressionList()
  {
    try {
      return TerminalForExpressionList();
    } catch (ParseException e) {
      error(_location, e.getMessage());
      return new Object[3];
    }
  }


  public Expression parseExpression(int type)
  {
    try {

      switch(type) {
      case TYPE_VALUE:
        TerminalValueExpression();
        return (Expression)pop();

      case TYPE_STANDALONE:
        TerminalExpression();
        return (Expression)pop();

      case TYPE_ASSIGNMENT:
        TerminalAssignmentExpression();
        return (Expression)pop();

      case TYPE_ASSIGNABLE:
        TerminalAssignableExpression();
        return (Expression)pop();
      }

    } catch (ParseException e) {
      error(_location, e.getMessage());
    }

    return Expression.NULL;
  }


  public Expression[] parseForeachExpression()
  {
    try {
      return TerminalForeachAssignmentExpression();
    } catch (ParseException e) {
      error(_location, e.getMessage());
    }
    return new Expression[0];
  }
 
}
TOP

Related Classes of anvil.script.parser.ExpressionParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.