Preprocessor and Macros [message #646794] |
Fri, 31 December 2010 10:13 |
No real name Messages: 25 Registered: April 2010 |
Junior Member |
|
|
Hi,
Im almost done with my hacked together grammar, the only thing remaining is how to handle macros.
The problem with macros is, that they can virtually appear anywhere and can contain anything (including operators, etc) therefore are a big pain to include into the parser. Right now, I have them as hidden terminals, but this is only suboptimal as expressions such as these exists:
a = MACRO * MACRO.
Now obviously, if a macro is a hidden terminal, the parser will complain about the multiplication.
Now, I have been thinking to implement a preprocessor myself, by doing the following:
Create a class MyXtextResourceFactory, which implements IResourceFactory and looks like this:
public class MyXtextResourceFactory implements IResourceFactory {
private Provider<MyXtextResource> provider;
@Inject
public XtextResourceFactory(Provider<MyXtextResource> resourceProvider) {
this.provider = resourceProvider;
}
public Resource createResource(URI uri) {
XtextResource xtextResource = provider.get();
xtextResource.setURI(uri);
return xtextResource;
}
}
Additionally, I thought of creating a class called MyXtextResource which would probably extend the lazy linking resource. At that point, I could overwrite the doLoad method and use the preprocessor at this point. This setup would get me the preprocessing done.
Now the problem is that I know little of the backend of xtext, and I would have no idea what consequences this would have. Would it break the syntax highlighting and highlighting in general? Would there be a much better alternative? Ideally, I would like the macros also be covered in the contentassist, but I guess I could implement a preprocessor there as well (e.g. finding all the macros).
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03925 seconds