001: /*
002: * xtc - The eXTensible Compiler
003: * Copyright (C) 2006-2007 Robert Grimm
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * version 2 as published by the Free Software Foundation.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
017: * USA.
018: */
019: package xtc.parser;
020:
021: import java.util.List;
022:
023: /**
024: * Definition of node property names.
025: *
026: * @author Robert Grimm
027: * @version $Revision: 1.16 $
028: */
029: public class Properties {
030:
031: // Hide the constructor.
032: private Properties() { /* Nothing to do. */
033: }
034:
035: /**
036: * The cost property. It is associated with productions, has an
037: * integer value, and indicates a production's estimated cost for
038: * inlining.
039: */
040: public static final String COST = "cost";
041:
042: /**
043: * The duplicates property. It is associated with productions, has
044: * a list of strings value, and indicates the names of the original
045: * productions folded into the annotated one.
046: */
047: public static final String DUPLICATES = "duplicates";
048:
049: /**
050: * The empty property. It is associated with productions, has a
051: * boolean value, and indicates whether a production may match the
052: * empty input.
053: */
054: public static final String EMPTY = "empty";
055:
056: /**
057: * The generic property. When associated with a production, it has
058: * a {@link #GENERIC_NODE} value indicating that the production's
059: * semantic value is a generic node with the component values as its
060: * children or a {@link #GENERIC_RECURSION} value indicating that
061: * the production's value is the result of a left-recursive
062: * production. When associated with a grammar, it has boolean value
063: * indicating whether the grammar contains generic nodes.
064: */
065: public static final String GENERIC = "generic";
066:
067: /** The generic node value. */
068: public static final String GENERIC_NODE = "node";
069:
070: /** The generic recursion value. */
071: public static final String GENERIC_RECURSION = "recursion";
072:
073: /**
074: * The input property. It is associated with productions, has a
075: * boolean value, and indicates whether a production may consume the
076: * input.
077: */
078: public static final String INPUT = "input";
079:
080: /**
081: * The formatting property. It is associated with sequences, has a
082: * list of bindings as its value, and indicates that a recursive
083: * alternative in a directly left-recursive generic production has
084: * formatting annotations for the node generated by the promise.
085: */
086: public static final String FORMATTING = "formatting";
087:
088: /**
089: * The lexical property. It is associated with productions, has a
090: * boolean value, and indicates whether a production recognizes
091: * lexical syntax.
092: */
093: public static final String LEXICAL = "lexical";
094:
095: /**
096: * The locatable property. It is associated with a grammar, has a
097: * boolean value, and indicates whether the corresponding parser
098: * uses the locatable interface.
099: */
100: public static final String LOCATABLE = "locatable";
101:
102: /**
103: * The meta-data property. It is associated with productions and
104: * has a {@link MetaData} value containing a production's meta-data.
105: */
106: public static final String META_DATA = "metaData";
107:
108: /**
109: * The option property. It is associated with productions, has a
110: * boolean value, and indicates whether a production represents a
111: * desugared option.
112: */
113: public static final String OPTION = "option";
114:
115: /**
116: * The recursive property. It is associated with grammars, has a
117: * boolean value, and indicates that a grammar contains directly
118: * left-recursive generic productions. It is also associated with
119: * productions and indicates that a production is left-recursive.
120: */
121: public static final String RECURSIVE = "recursive";
122:
123: /**
124: * The redacted property. It is associated with productions, has a
125: * boolean value, and indicates that a production's body has been
126: * removed even though the production really has a body.
127: */
128: public static final String REDACTED = "redacted";
129:
130: /**
131: * The repeated property. It is associated with productions, has a
132: * nonterminal value, and indicates that a production represents a
133: * desguared repetition whose element value is the value of the
134: * nonterminal.
135: */
136: public static final String REPEATED = "repeated";
137:
138: /**
139: * The root property. It is associated with grammars, has a
140: * nonterminal value, and indicates a grammar's real root (i.e., the
141: * single public production that directly or indirectly references
142: * all other public productions).
143: */
144: public static final String ROOT = "root";
145:
146: /**
147: * The split property. It is associated with productions, has a
148: * boolean value, and indicates that the production's alternatives
149: * need to be split. It is also associated with sequences, has a
150: * {@link Annotator.IndexPair} value, and indicates how to split the
151: * sequence.
152: */
153: public static final String SPLIT = "split";
154:
155: /**
156: * The text-only property. It is associated with productions, has a
157: * boolean value, and indicates whether a production is text-only.
158: */
159: public static final String TEXT_ONLY = "textOnly";
160:
161: /**
162: * The token property. It is associated with productions, has a
163: * boolean value, and indicates whether a production represents a
164: * lexical token.
165: */
166: public static final String TOKEN = "token";
167:
168: /**
169: * The transformable property. It is associated with productions,
170: * has a boolean value, and indicates whether a production is a
171: * directly left-recursive production that can be transformed into
172: * an equivalent right-recursive or -iterative production.
173: */
174: public static final String TRANSFORMABLE = "transformable";
175:
176: /**
177: * The voided property. It is associated with productions, has a
178: * boolean value, and indicates whether the production's value has
179: * been eliminated.
180: */
181: public static final String VOIDED = "voided";
182:
183: /**
184: * Get the value of the duplicates property.
185: *
186: * @param p The production.
187: * @return The list of folded productions.
188: */
189: @SuppressWarnings("unchecked")
190: public static List<String> getDuplicates(Production p) {
191: return (List<String>) p.getProperty(DUPLICATES);
192: }
193:
194: /**
195: * Get the value of the formatting property.
196: *
197: * @param s The sequence.
198: * @return The list of bindings.
199: */
200: @SuppressWarnings("unchecked")
201: public static List<Binding> getFormatting(Sequence s) {
202: return (List<Binding>) s.getProperty(FORMATTING);
203: }
204:
205: }
|