Enhanced C#
Language of your choice: library documentation
|
Encapsulates the code for printing an LNode to EC# source code. More...
Encapsulates the code for printing an LNode to EC# source code.
To print EC# code, you not use this class directly. Instead, call EcsLanguageService.Print(LNode, StringBuilder, IMessageSink, ParsingMode, ILNodePrinterOptions) via EcsLanguageService.WithPlainCSharpPrinter or via EcsLanguageService.Value. This class does have some static methods like PrintLiteral(object, NodeStyle) and PrintId that are useful for printing tokens efficiently.
This class is designed to faithfully preserve most Loyc trees; almost any Loyc tree that can be represented as EC# source code will be represented properly by this class, so that it is possible to parse the output text back into a Loyc tree equivalent to the one that was printed. Originally this class was meant to provide round-tripping from Loyc trees to text and back, but Enhanced C# is syntactically very complicated and as a result this printer may contain bugs or (for the sake of practicality) minor intentional limitations that cause round-tripping not to work in rare cases. If you need perfect round-tripping, use LES instead (LesLanguageService).
Only the attributes, head (LiteralNode.Value, IdNode.Name or CallNode.Target), and arguments of nodes are round-trippable. Superficial properties such as original source code locations and the LNode.Style are, in general, lost, although the printer can faithfully reproduce some (not all) NodeStyles (this caveat applies equally to LES). Also, any attribute whose Name starts with the trivia marker % may be dropped, because these attributes are considered extensions of the NodeStyle. However, the style indicated by the % attribute will be used if the printer recognizes it.
For round-tripping to work, there are a couple of restrictions on the input tree:
Public Types | |
enum | Ambiguity { Ambiguity.AllowUnassignedVarDecl = 0x0001, Ambiguity.CastRhs = 0x0002, Ambiguity.IsCallTarget = 0x0004, Ambiguity.NoBracedBlock = 0x0008, Ambiguity.FinalStmt = 0x0010, Ambiguity.TypeContext = 0x0020, Ambiguity.InDefinitionName = 0x0040, Ambiguity.InOf = 0x0080, Ambiguity.AllowPointer = 0x0100, Ambiguity.UseBacktick = 0x0400, Ambiguity.ForEachInitializer = 0x1000, Ambiguity.ElseClause = 0x2000, Ambiguity.NoParentheses = 0x4000, Ambiguity.AllowThisAsCallTarget = 0x8000, Ambiguity.NoIfWithoutElse = 0x10000, Ambiguity.ForceAttributeList = 0x40000, Ambiguity.NewlineBeforeChildStmt = 0x80000 } |
Internal enum (marked public for an obscure technical reason). These are flags that represent special situations in EC# syntax. More... | |
enum | IdPrintMode { Normal, Symbol, Operator, Verbatim } |
Properties | |
INodePrinterWriter | Writer [get, set] |
IMessageSink?? | ErrorSink [get, set] |
Any error that occurs during printing is printed to this object. More... | |
EcsPrinterOptions | Options [get] |
Public Member Functions | |
void | SetOptions (ILNodePrinterOptions options) |
Static Public Member Functions | |
static void | PrintPlainCSharp (LNode node, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options=null) |
Prints a node while avoiding syntax specific to Enhanced C#. More... | |
static void | PrintECSharp (LNode node, StringBuilder target, IMessageSink sink, ParsingMode mode, ILNodePrinterOptions options=null) |
Prints a node as EC# code. More... | |
static string | PrintId (Symbol name, IdPrintMode mode=IdPrintMode.Normal) |
static string | PrintSymbolLiteral (Symbol name) |
static string | PrintLiteral (object value, NodeStyle style) |
static string | PrintString (string value, char quoteType, bool verbatim=false, bool includeAtSign=true) |
|
strong |
Internal enum (marked public for an obscure technical reason). These are flags that represent special situations in EC# syntax.
|
inlinestatic |
Prints a node as EC# code.
Referenced by Loyc.Ecs.EcsLanguageService.Print().
|
inlinestatic |
Prints a node while avoiding syntax specific to Enhanced C#.
This does not perform a conversion from EC# to C#. If the syntax tree contains code that has no direct C# representation, the EC# representation will be printed.
Referenced by Loyc.Ecs.EcsLanguageService.Print().
|
getset |
Any error that occurs during printing is printed to this object.
The most common error is an unprintable literal.