NestedParser.java :  » Web-Framework » anvil » anvil » script » parser » Java Open Source

Java Open Source » Web Framework » anvil 
anvil » anvil » script » parser » NestedParser.java
/*
 * $Id: NestedParser.java,v 1.10 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.expression.Expression;
import anvil.script.ModuleEnvelope;
import java.util.Enumeration;

/**
 * class NestedParser
 *
 * @author: Jani Lehtimki
 */
public class NestedParser extends ParserBase
{

  private ParserBase _parser;
  private Location _location = null;
  private int _position;


  public NestedParser(ParserBase parser, Location location, String expression, int position)
  {
    super(new Tokenizer(expression));
    _parser = parser;
    _location = location;
    _position = position;
    _current = parser.flowPeek();
    ((Tokenizer)token_source).setParser(this);
  }
  

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

  public Location toLocation(Token token)
  {
    return new Location(_location.getURL(),
      _location.getLine() + token.beginLine - 1,
      _location.getColumn() + _position + token.beginColumn);
  }  

  
  public Location toLocation(int line, int column)
  { 
    return new Location(_location.getURL(),
      _location.getLine() + line - 1,
      _location.getColumn() + _position + column);
  }
  


  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 Expression parseExpression() 
  {
    try {
      TerminalValueExpression();
      return (Expression)pop();
    } catch (ParseException e) {
      error(toLocation(e.currentToken), e.getMessage());
    }
    return Expression.NULL;
  }

  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.