Enhanced C#
Language of your choice: library documentation
|
A central class for keeping track of literal parsers and literal printers. More...
A central class for keeping track of literal parsers and literal printers.
Public fields | |
IReadOnlyDictionary< Symbol, Func< UString, Symbol, Either< object, LogMessage > > > | Parsers => _parsers |
A table of parsers indexed by type marker Symbol. The AddParser method is used to add an item to this collection. More... | |
IReadOnlyDictionary< object, Func< ILNode, StringBuilder, Either< Symbol, LogMessage > > > | Printers => _printers |
A table of printers indexed by Type or by type marker Symbol. The AddPrinter methods are used to add an item to this collection. More... | |
Public Member Functions | |
bool | AddParser (bool replaceExisting, Symbol typeMarker, Func< UString, Symbol, Either< object, LogMessage >> parser) |
Adds a parser to the Parsers collection. More... | |
bool | AddPrinter (bool replaceExisting, Symbol type, Func< ILNode, StringBuilder, Either< Symbol, LogMessage >> printer) |
Adds a printer to the Printers collection. More... | |
bool | AddPrinter (bool replaceExisting, Type type, Func< ILNode, StringBuilder, Either< Symbol, LogMessage >> printer) |
bool | CanParse (Symbol typeMarker) |
Returns true if there is a parser function for the given type marker. Never throws. More... | |
bool | CanPrint (Symbol typeMarker) |
Returns true if there is a printer function for the given type marker. Never throws. More... | |
bool | CanPrint (Type type, bool searchBases=true) |
Returns true if there is a printer function for the given type. Never throws. More... | |
Either< object, ILogMessage > | TryParse (UString textValue, Symbol typeMarker) |
Attempts to parse a string with a given type marker. | |
Either< Symbol, ILogMessage > | TryPrint (ILNode literal, StringBuilder sb) |
Searches Printers for a printer for the value and uses it to convert the value to a string. When a printer can be found both by type marker Symbol and by Type, the printer for the matching type marker is used (takes priority). The complete search order is (1) type marker (if any), (2) exact type, (3) base class and base interfaces, in that order, recursively, breadth-first. More... | |
|
inline |
Adds a parser to the Parsers collection.
replaceExisting | If the specified type already has a printer assigned to it, it will be replaced only if this flag is true. |
typeMarker | The parser will be invoked by TryParse when this type marker Symbol matches the literal being parsed. |
parser | A function that converts a UString to a value (object), or returns a LogMessage if an error occurs. The type marker is also provided to the parser. |
type
is null.)bool Loyc.Syntax.LiteralHandlerTable.AddPrinter | ( | bool | replaceExisting, |
Symbol | type, | ||
Func< ILNode, StringBuilder, Either< Symbol, LogMessage >> | printer | ||
) |
Adds a printer to the Printers collection.
replaceExisting | If the specified type already has a printer assigned to it, it will be replaced only if this flag is true. |
type | The printer will be invoked by TryPrint(ILNode) when this Type or type marker Symbol matches the literal being printed. |
printer | A printer function that prints into the provided StringBuilder and returns null on success, or a description of the error that occurred. |
type
is null.)
|
inline |
Returns true if there is a parser function for the given type marker. Never throws.
Implements Loyc.Syntax.ILiteralParser.
References Loyc.Syntax.LiteralHandlerTable.Parsers.
|
inline |
Returns true if there is a printer function for the given type marker. Never throws.
Implements Loyc.Syntax.ILiteralPrinter.
References Loyc.Syntax.LiteralHandlerTable.Printers.
|
inline |
Returns true if there is a printer function for the given type. Never throws.
searchBases | Whether to search for printers among the base types of the given type. |
References Loyc.Syntax.LiteralHandlerTable.Printers.
|
inline |
Searches Printers for a printer for the value and uses it to convert the value to a string. When a printer can be found both by type marker Symbol and by Type, the printer for the matching type marker is used (takes priority). The complete search order is (1) type marker (if any), (2) exact type, (3) base class and base interfaces, in that order, recursively, breadth-first.
literal | A literal that you want to convert to a string. |
If a printer returns an error, this method tries to find other printers that might be able to print the value. If no printer succeeds, the first error that occurred is returned.
When the literal is null and there is no printer associated with literal.TypeMarker, this funtion produces no output and returns literal.TypeMarker.
On success, the return value indicates which type marker is recommended based on the data type of the literal. This is not guaranteed to match the TypeMarker originally stored in the literal. It is recommended that language printers use the type marker stored in the literal (regardless of what this method returns) unless literal.TypeMarker == null
.
Implements Loyc.Syntax.ILiteralPrinter.
References Loyc.Syntax.IUninterpretedLiteral.TypeMarker.
IReadOnlyDictionary<Symbol, Func<UString, Symbol, Either<object, LogMessage> > > Loyc.Syntax.LiteralHandlerTable.Parsers => _parsers |
A table of parsers indexed by type marker Symbol. The AddParser method is used to add an item to this collection.
Referenced by Loyc.Syntax.LiteralHandlerTable.CanParse(), and Loyc.Syntax.LiteralHandlerTable.TryParse().
IReadOnlyDictionary<object, Func<ILNode, StringBuilder, Either<Symbol, LogMessage> > > Loyc.Syntax.LiteralHandlerTable.Printers => _printers |
A table of printers indexed by Type or by type marker Symbol. The AddPrinter methods are used to add an item to this collection.
Referenced by Loyc.Syntax.LiteralHandlerTable.CanPrint().