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
%> 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
ReSharper provides the following:
Language registration -
HtmlLanguageServiceto act as a base class for the PSI Language Service.
HtmlCompoundIncrementalLexerwhich interleaves lexing the custom parts of the language with standard HTML.
WebTreeBuilderbase class to parse the mix of custom and traditional HTML syntax. HTML-like languages use custom written parsers rather than parsers generated with
.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.