| Summary: | [client] [textmatestyler] Tolerate references to external grammars/rules | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [ECD] Orion | Reporter: | Mark Macdonald <mamacdon> | ||||||
| Component: | Editor | Assignee: | Mark Macdonald <mamacdon> | ||||||
| Status: | RESOLVED FIXED | QA Contact: | |||||||
| Severity: | normal | ||||||||
| Priority: | P3 | CC: | karol | ||||||
| Version: | 0.2 | ||||||||
| Target Milestone: | 0.3 M1 | ||||||||
| Hardware: | PC | ||||||||
| OS: | Windows 7 | ||||||||
| Whiteboard: | |||||||||
| Attachments: |
|
||||||||
(In reply to comment #0) Are the references to external grammars planned to be supported in more distant future (i.e. to create a rule you mentioned in comment)? (In reply to comment #1) > Are the references to external grammars planned to be supported in more distant > future (i.e. to create a rule you mentioned in comment)? At the moment nothing is planned. I'll take another look at them after 0.2 has shipped. I was experimenting with references to external grammars in TextMateStyler to get multi-mode syntax highlighting (PHP in HTML). I tried to mimic the TextMate way of solving this problem - in case of .php files, HtmlGrammar is loaded (instead of PhpGrammar) which is referencing the latter for highlighting anything inside the PHP tags. It is working surprisingly well despite just few modifications. You can see it on my Orion test installation: http://bit.ly/pKSEPn I'm attaching a patch with language-agnostic changes (textMateStyler.js and setup.js), and (just for the record) a second patch with modifications that were required in webEditingPlugin and phpEditingPlugin to get this working. Maybe it'll come in useful. Created attachment 200901 [details]
Multi-mode syntax highlighting in TextMateStyler
Created attachment 200902 [details]
Example of PHP in HTML syntax highlight
Cool, thanks for the patch! This will be good to have. As usual, can I get you to confirm that you wrote all the code and you have the rights to contribute it to Orion under the Eclipse.org website terms of use? I wrote all this code and have the rights to contribute it to Eclipse under the eclipse.org web site terms of use. (In reply to comment #3) > I'm attaching a patch with language-agnostic changes (textMateStyler.js and > setup.js), and (just for the record) a second patch with modifications that > were required in webEditingPlugin and phpEditingPlugin to get this working. > Maybe it'll come in useful. FYI, you can associate .php files with the Orion Web Editor by registering an additional service in your PHP tooling plugin -- see [1]. (So you don't actually have to change webEditingPlugin.html as Attachment 200902 [details] does). [1] http://wiki.eclipse.org/Orion/Documentation/Developer_Guide/Plugging_into_the_navigator#orion.navigate.openWith http://git.eclipse.org/c/orion/org.eclipse.orion.client.git/commit/?id=6d70ced180fa542a008685a95d77b965be68d441 Changes made: - TextMateStyler can be used without the service registry, so it shouldn't know about the highlightProvider extension point. Instead the glue code that creates TextMateStyler will feed it all grammar objects to use for resolving references. - TextMateStyler will ignore unresolved references rather than throw an error. So Grammar A can refer to Grammar B, and if B is not installed, A will still work (but may be less useful). I believe this is how TextMate behaves. > (In reply to comment #3)
> FYI, you can associate .php files with the Orion Web Editor by registering an
> additional service in your PHP tooling plugin [...]
I know, the change in webEditingPlugin.html is to get PHP highlighting in HTML (so the .php files are actually handled by HtmlGrammar). Could I do it differently?
|
In TextMate, a grammar can reference another grammar, or rules from another grammar, by name. For example, an HTML grammar might call the top-level JavaScript grammar (named "source.javascript") to handle stuff inside <script>..</script> tags: > { "begin": "<script>", > "end": "</script>", > "patterns": [ > { include: "source.javascript" } > ] > } TextMateStyler does not support this: it expects all your rules to be in one grammar. Currently it throws an error when it sees a reference to something outside your grammar. But for compatibility's sake, we should probably ignore these and continue. It's better than blowing up.