HTML-Like languages
ReSharper supports HTML files, but it also supports HTML-like languages, such as Razor (.cshtml) or WebForms (.aspx) files. These files contain HTML, but also contain other elements, such as custom tags, or new syntax. Rather than force each language to reimplement HTML parsing, ReSharper provides support that a language can build on, reusing existing and augmenting the existing HTML parsing infrastructure.
For example, a WebForms .aspx file can look like this, with custom <% and %> delimiters marking the ASP.NET specific syntax, and the asp: prefixed tags extending the HTML:
And a Razor .cshtml file uses the @ symbol to delimit C# card that will be executed as the page runs. This C# can even contain HTML blocks.
More languages and language features are also supported. For example, there is also support for the MVC flavour of Razor, which includes @Model markup. There is also support for Angular 2+ (including Angular 4) which augments standard HTML files to add tokens for Angular interpolation expressions. And there is also support for parsing HTML and HTML-like languages inside C# and JavaScript string literals.
ReSharper provides the following:
Language registration -
HtmlLanguageServiceto act as a base class for the PSI Language Service.Lexing -
HtmlCompoundLexerandHtmlCompoundIncrementalLexerwhich interleaves lexing the custom parts of the language with standard HTML.Parsing -
IWebTreeBuilderand theWebTreeBuilderbase class to parse the mix of custom and traditional HTML syntax. HTML-like languages use custom written parsers rather than parsers generated withPsiGenand.psifiles. This also means that the PSI element types are also generated by hand - the syntax of HTML and its derived languages is small and regular enough that this is possible.