01: /*
02: * $Id: NestedParser.java,v 1.10 2002/09/16 08:05:05 jkl Exp $
03: *
04: * Copyright (c) 2002 Njet Communications Ltd. All Rights Reserved.
05: *
06: * Use is subject to license terms, as defined in
07: * Anvil Sofware License, Version 1.1. See LICENSE
08: * file, or http://njet.org/license-1.1.txt
09: */
10: package anvil.script.parser;
11:
12: import anvil.ErrorListener;
13: import anvil.Location;
14: import anvil.script.expression.Expression;
15: import anvil.script.ModuleEnvelope;
16: import java.util.Enumeration;
17:
18: /**
19: * class NestedParser
20: *
21: * @author: Jani Lehtimäki
22: */
23: public class NestedParser extends ParserBase {
24:
25: private ParserBase _parser;
26: private Location _location = null;
27: private int _position;
28:
29: public NestedParser(ParserBase parser, Location location,
30: String expression, int position) {
31: super (new Tokenizer(expression));
32: _parser = parser;
33: _location = location;
34: _position = position;
35: _current = parser.flowPeek();
36: ((Tokenizer) token_source).setParser(this );
37: }
38:
39: public ModuleEnvelope getEnvelope() {
40: return _parser.getEnvelope();
41: }
42:
43: public Location toLocation(Token token) {
44: return new Location(_location.getURL(), _location.getLine()
45: + token.beginLine - 1, _location.getColumn()
46: + _position + token.beginColumn);
47: }
48:
49: public Location toLocation(int line, int column) {
50: return new Location(_location.getURL(), _location.getLine()
51: + line - 1, _location.getColumn() + _position + column);
52: }
53:
54: public void error(Location location, Throwable throwable) {
55: _parser.error(location, throwable);
56: }
57:
58: public void error(Location location, String message) {
59: _parser.error(location, message);
60: }
61:
62: public int errors() {
63: return _parser.errors();
64: }
65:
66: public Enumeration getEvents() {
67: return _parser.getEvents();
68: }
69:
70: public void merge(ErrorListener listener) {
71: _parser.merge(listener);
72: }
73:
74: public Expression parseExpression() {
75: try {
76: TerminalValueExpression();
77: return (Expression) pop();
78: } catch (ParseException e) {
79: error(toLocation(e.currentToken), e.getMessage());
80: }
81: return Expression.NULL;
82: }
83:
84: }
|