Parser xref
1 /**
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package net.sourceforge.pmd.lang;
5
6 import java.io.Reader;
7 import java.util.Map;
8
9 import net.sourceforge.pmd.lang.ast.Node;
10 import net.sourceforge.pmd.lang.ast.ParseException;
11
12 /**
13 * Common interface for calling tree-building parsers or source files.
14 *
15 * @author Pieter_Van_Raemdonck - Application Engineers NV/SA - www.ae.be
16 */
17 public interface Parser {
18 /**
19 * Get the ParserOptions used by this Parser.
20 */
21 ParserOptions getParserOptions();
22
23 /**
24 * Get a TokenManager for the given source.
25 * @param fileName The file name being parsed (may be <code>null</code>).
26 * @param source Reader that provides the source code to tokenize.
27 * @return A TokenManager for reading token.
28 */
29 TokenManager getTokenManager(String fileName, Reader source);
30
31 /**
32 * Indicates if this parser can actual parse, or if it can only tokenize.
33 */
34 boolean canParse();
35
36 /**
37 * Parse source code and return the root node of the AST.
38 *
39 * @param fileName The file name being parsed (may be <code>null</code>).
40 * @param source Reader that provides the source code of a compilation unit
41 * @return the root node of the AST that is built from the source code
42 * @throws ParseException In case the source code could not be parsed, probably
43 * due to syntactical errors.
44 */
45 Node parse(String fileName, Reader source) throws ParseException;
46
47 // TODO Document
48 Map<Integer, String> getSuppressMap();
49 }