root/org.axdt.as3/src/org/axdt/as3/imp/parser/AS3ParseController.java @ a106cc373e028ca3bb89023c7e8ee459713ff2c3

Revision a106cc373e028ca3bb89023c7e8ee459713ff2c3, 2.7 KB (checked in by mb0 <mb0@…>, 15 months ago)

changed ast the IName QName and Name are now only Name
using custom message handler adapter

  • Property mode set to 100644
Line 
1package org.axdt.as3.imp.parser;
2
3import org.axdt.as3.AS3Plugin;
4import org.axdt.as3.imp.parser.Ast.ASTNode;
5import org.eclipse.core.runtime.IPath;
6import org.eclipse.core.runtime.IProgressMonitor;
7import org.eclipse.imp.services.ILanguageSyntaxProperties;
8import org.eclipse.imp.model.ISourceProject;
9import org.eclipse.imp.parser.ILexer;
10import org.eclipse.imp.parser.IMessageHandler;
11import org.eclipse.imp.parser.IParseController;
12import org.eclipse.imp.parser.IParser;
13import org.eclipse.imp.parser.ISourcePositionLocator;
14import org.eclipse.imp.parser.MessageHandlerAdapter;
15import org.eclipse.imp.parser.SimpleLPGParseController;
16
17public class AS3ParseController extends SimpleLPGParseController implements IParseController {
18        private AS3Parser parser;
19
20        private AS3Lexer lexer;
21
22        private Object backupAst;
23
24        public AS3ParseController() {
25                super(AS3Plugin.LANGUAGE);
26        }
27
28        /**
29         * @param filePath
30         *            Absolute path of file
31         * @param project
32         *            Project that contains the file
33         * @param handler
34         *            A message handler to receive error messages (or any others)
35         *            from the parser
36         */
37        public void initialize(IPath filePath, ISourceProject project, IMessageHandler handler) {
38                super.initialize(filePath, project, handler);
39        }
40
41        public IParser getParser() {
42                return parser;
43        }
44
45        public ILexer getLexer() {
46                return lexer;
47        }
48
49        public ISourcePositionLocator getNodeLocator() {
50                return new AS3ASTNodeLocator();
51        }
52
53        public ILanguageSyntaxProperties getSyntaxProperties() {
54                return new AS3SyntaxProperties();
55        }
56
57
58        public Object parse(String contents, IProgressMonitor monitor) {
59                return parse(contents, false, monitor);
60        }
61        /**
62         * setFilePath() should be called before calling this method.
63         */
64        public Object parse(String contents, boolean scanOnly, IProgressMonitor monitor) {
65                PMMonitor my_monitor = new PMMonitor(monitor);
66                char[] contentsArray = contents.toCharArray();
67
68                if (lexer == null) {
69                        lexer = new AS3Lexer();
70                }
71                lexer.reset(contentsArray, fFilePath.toPortableString());
72
73                if (parser == null) {
74                        parser = new AS3Parser(lexer.getILexStream());
75                }
76                parser.reset(lexer.getILexStream());
77                parser.getIPrsStream().setMessageHandler(new AS3MessageHandler(handler));
78
79                // Lex the stream to produce the token stream
80                lexer.lexer(my_monitor, parser, true); 
81                // fCurrentAst might (probably will) be
82                // inconsistent wrt the lex stream now
83                if (my_monitor.isCancelled()) return fCurrentAst;
84               
85                if (fCurrentAst != null)
86                        backupAst = fCurrentAst;
87
88                fCurrentAst = parser.parser(my_monitor, -1);
89
90                if (fCurrentAst instanceof ASTNode) {
91                        parser.resolve((ASTNode) fCurrentAst);
92                }
93
94                cacheKeywordsOnce();
95
96                Object result = fCurrentAst;
97                return result;
98        }
99
100        public Object getBackupAst() {
101                return backupAst;
102        }
103}
Note: See TracBrowser for help on using the browser.