Enhanced C#
Language of your choice: library documentation
Namespaces | Classes | Typedefs | Enumerations
Loyc.Syntax Namespace Reference

Loyc.Syntax.dll: contains Loyc trees (Loyc.Syntax.LNode), lexing stuff, LLLPG base classes (BaseParser{T} and BaseLexer), the LES parser and printer, data types related to source code management (e.g. ISourceFile, SourceRange) and other general-purpose code related to the manipulation of syntax. More...

Namespaces

namespace  Les
 Contains classes related to Loyc Expression Syntax (LES), including the parser and printer (reachable through Loyc.Syntax.Les.LesLanguageService).
 
namespace  Lexing
 Contains classes related to lexical analysis, such as the universal token type (Loyc.Syntax.Lexing.Token) and Loyc.Syntax.Lexing.TokensToTree.
 

Classes

class  AbstractTriviaInjector
 Encapsulates an algorithm that consumes trivia (comments and newlines) from a list and adds it as trivia attributes into LNodes. More...
 
class  BaseParser
 An base class designed for parsers that use LLLPG (Loyc LL(k) Parser Generator). Note: this is the old (harder to use) base class design. You should use BaseParserForList<Token,MatchType> instead. More...
 
class  BaseParserForList
 An base class designed for parsers that use LLLPG (Loyc LL(k) Parser Generator) and receive tokens from any IEnumerator<Token>. (Potentially also useful for parsers written by hand.) More...
 
class  BaseParserNoBacktracking
 An base class designed for parsers that use LLLPG (Loyc LL(k) Parser Generator) and receive tokens from any IEnumerator<Token>. More...
 
class  CallNode
 Base class of all nodes that represent calls such as f(x), operator calls such as x + y, braced blocks, and all other things that are not simple symbols and literals. More...
 
class  CodeSymbols
 A list of common symbols that, by convention, have special meaning: operators, built-in data types, keywords, trivia, etc. More...
 
struct  DescendantsFrame
 Helper class used to enumerate LNode.Descendants(). More...
 
class  EmptySourceFile
 A dummy implementation of ISourceFile that has only a filename, no source text. Used as the source file of synthetic syntax nodes. More...
 
class  IdNode
 Base class of all nodes that represent simple identifiers (including special symbols such as #foo). More...
 
interface  IHasFileName
 
interface  IIndexPositionMapper
 This interface is for classes that can convert indexes to SourcePos structures and back. More...
 
interface  IIndexToLine
 Contains IndexToLine method. More...
 
interface  ILineAndColumn
 A line/column pair representing a location in a text file. Numbering starts at one for both Line and Column. More...
 
interface  ILineColumnFile
 
interface  ILiteralParser
 This interface for parsing text into objects is implemented by LiteralHandlerTable. More...
 
interface  ILiteralPrinter
 This interface for converting literals to text is implemented by LiteralHandlerTable. More...
 
interface  ILiteralValue
 Bundles the optional original text of a value with an optional in-memory form of it. More...
 
interface  ILiteralValueProvider
 The intention of this interface is that a struct implementing it can be embedded inside a LiteralNode in order to lazily obtain the text of a literal, or even parse it lazily. More...
 
interface  ILNode
 A read-only interface for objects that act as Loyc trees. More...
 
interface  ILNodePrinter
 This interface allows serializing LNode objects into the syntax of a particular programming language. More...
 
interface  ILNodePrinterOptions
 A set of relatively universal printing options that LNodePrinters should understand. More...
 
interface  ILNodeVisitor
 Interface for people that want to implement the visitor pattern with LNode. If your visitor does not need a base class, use LNodeVisitor as the base class. More...
 
class  IndexPositionMapper
 Helper class for mapping from indexes to SourcePos and back. More...
 
interface  IParsingOptions
 A set of relatively universal parsing options that IParsingServices should understand. More...
 
interface  IParsingService
 An interface that encapsulates the lexer and parser of a programming language, or a non-programming language that can be represented by Loyc trees. More...
 
interface  ISerializedLiteral
 
interface  ISourceFile
 Represents a text file with a file name and its textual content, plus the data necessary to convert between line-column positions and 0-based integer indexes. More...
 
interface  ISourceRange
 Represents a (contiguous) region of text in a source file. More...
 
interface  IUninterpretedLiteral
 Represents the text form of a literal value, without its parsed value. More...
 
class  LineAndCol
 Please use the new name of this class: LineAndColumn. Holds a line number (Line) and a position in the line (Column). This class isn't really needed in Loyc but is separated from SourcePos in case anyone might want position without a filename. More...
 
class  LineAndColumn
 This is the new (and recommended) name for LineAndCol. It holds a line number (Line) and a position in the line (Column). Numbering starts at one for both Line and Column. More...
 
class  LineColumnFile
 This is the new (and recommended) name for SourcePos. It's named after what it contains: a line number, column number and file name. Numbering starts at one for both Line and Column. More...
 
class  LineColumnFileAndIndex
 This is a tuple of a FileName, Line, Column, and OriginalIndex. More...
 
class  LineRemapper
 A small helper class for languages such as C# and C++ that permit the locations reported by error messages to be remapped. This class stores and applies such commands (#line in C#/C++) More...
 
class  LiteralHandlerTable
 A central class for keeping track of literal parsers and literal printers. More...
 
class  LiteralNode
 Base class of all nodes that represent literal values such as 123 and "foo". More...
 
struct  LiteralValue
 Bundles the optional original text of a value with an optional in-memory form of it; see remarks at ILiteralValue. This struct can also be turned into an LNode by calling LNode.Literal<LiteralValue>(SourceRange, LiteralValue, NodeStyle). More...
 
class  LNode
 All nodes in a Loyc syntax tree share this base class. More...
 
class  LNodeExt
 Standard extension methods for LNode. More...
 
class  LNodeFactory
 Contains helper methods for creating LNodes. An LNodeFactory holds a reference to the current source file (File) so that it does not need to be repeated every time you create a node. More...
 
struct  LNodeList
 A list of non-null references to LNode. More...
 
class  LNodePrinter
 Standard extension methods for ILNodePrinter. More...
 
class  LNodePrinterOptions
 A concrete class that users can pass to an LNodePrinter. More...
 
class  LNodeVisitor
 Base class for people that want to implement the visitor pattern with LNode. More...
 
class  ParseHelpers
 Static methods that help with common parsing jobs, such as parsing integers, floats, and strings with C escape sequences. More...
 
class  ParserSource
 An implementation of the LLLPG Parser API, used with the LLLPG options inputSource and inputClass. More...
 
class  ParsingMode
 Standard parsing modes used with IParsingService and ILNodePrinterOptions. More...
 
class  ParsingOptions
 A simple implementation of IParsingOptions. More...
 
class  ParsingService
 Standard extension methods for IParsingService. More...
 
struct  Precedence
 A four-byte tuple that represents the precedence and miscibility of an operator. More...
 
class  PrintHelpers
 Static methods that help to print literals, such as EscapeCStyle which escapes special characters with backslashes. More...
 
class  SourceFile
 A default implementation of ISourceFile based on IndexPositionMapper. More...
 
class  SourceFileWithLineRemaps
 An wrapper around ISourceFile that applies line remapping information (if the source file uses it). More...
 
class  SourcePos
 Please use the new name of this class: LineColumnFile. Holds a filename (FileName), a line number (Line) and a position in the line (Column), representing a position in a source code file. More...
 
class  SourcePosAndIndex
 Please use the new name of this class, LineColumnFile. This is a LineColumnFile that also includes the original index from which the Line and PosInLine were derived. More...
 
class  SourcePosIsObsolete
 This just helps end-users to discover the name change SourcePos.PosInLine => ILineAndColumn.Column during upgrades More...
 
struct  SourceRange
 Holds a reference to a source file (ISourceFile<char>) and the beginning and end indices of a range in that file. More...
 
class  SourceRangeExt
 Standard extension methods for ISourceRange. More...
 
class  StandardLiteralHandlers
 A LiteralHandlerTable that is preinitialized with all standard literal parsers and printers. More...
 
class  StandardTriviaInjector
 Encapsulates an algorithm that consumes trivia (comments and newlines) from a list and adds it as trivia attributes into LNodes. This makes it possible to preserve comments and newlines independently of the language parser, so that the parser need not be specifically designed to preserve them. More...
 
class  StreamCharSource
 Exposes a stream as an ICharSource, as though it were an array of characters. The stream must support seeking, and if a text decoder is specified, it must meet certain constraints. More...
 
struct  UninterpretedLiteral
 A simple implementation of IUninterpretedLiteral which can also be turned into an LNode by calling LNode.Literal<UninterpretedLiteral>(SourceRange, UninterpretedLiteral, NodeStyle). More...
 

Typedefs

using ParseFunc = Func< UString, Symbol, Either< object, LogMessage > >
 
using PrintFunc = Func< object, Symbol, Either< UString, LogMessage > >
 

Enumerations

enum  LNodeKind { Id, Literal, Call }
 The three kinds of nodes in a Loyc tree More...
 
enum  NodeStyle : byte {
  NodeStyle.Default = 0, NodeStyle.Operator = 1, Statement = StatementBlock,
  NodeStyle.StatementBlock = 2, NodeStyle.Special = 3, NodeStyle.PrefixNotation = 4,
  NodeStyle.Expression = 5, NodeStyle.Compact = 6, NodeStyle.OldStyle = 7,
  NodeStyle.VerbatimId = 8, NodeStyle.BinaryLiteral = 9, NodeStyle.HexLiteral = 10,
  NodeStyle.OctalLiteral = 11, NodeStyle.VerbatimStringLiteral = 12, NodeStyle.TQStringLiteral = 13,
  NodeStyle.TDQStringLiteral = 14, NodeStyle.BaseStyleMask = 15, NodeStyle.Alternate = 32,
  NodeStyle.InternalFlag = 64, NodeStyle.OneLiner = 64, NodeStyle.Handled = 128
}
 Suggests a printing style when serializing a Loyc tree to text. More...
 
enum  EscapeC {
  EscapeC.Minimal = 0, EscapeC.Default = Control | DoubleQuotes | UnicodeNonCharacters | UnicodePrivateUse, EscapeC.NonAscii = 1,
  EscapeC.BackslashX = 2, EscapeC.Control = 4, EscapeC.ABFV = 8,
  EscapeC.DoubleQuotes = 16, EscapeC.SingleQuotes = 32, EscapeC.Quotes = 48,
  EscapeC.UnicodeNonCharacters = 64, EscapeC.UnicodePrivateUse = 128, EscapeC.HasEscapes = 0x100,
  EscapeC.Unrecognized = 0x200, EscapeC.HasLongEscape = 0x400, EscapeC.HasInvalid6DigitEscape = 0x800
}
 Flags to control

See also
PrintHelpers.EscapeCStyle(UString, EscapeC)

and the reverse operation in ParseHelpers. More...

 
enum  NodeScanMode {
  YieldSelf = 1, YieldLocalAttrs = 2, YieldLocalHead = 4,
  YieldLocalArgsOnly = 8, YieldLocalNonAttrs = YieldLocalArgsOnly | YieldLocalHead, YieldLocal = YieldLocalAttrs | YieldLocalNonAttrs,
  YieldDeepAttrs = 16, YieldDeepHeads = 32, YieldDeepArgsOnly = 64,
  YieldDeepNonAttrs = YieldDeepArgsOnly | YieldDeepHeads, YieldDeep = YieldDeepAttrs | YieldDeepNonAttrs, YieldAttrs = YieldLocalAttrs | YieldDeepAttrs,
  YieldHeads = YieldLocalHead | YieldDeepHeads, YieldArgsOnly = YieldLocalArgsOnly | YieldDeepArgsOnly, YieldNonAttrs = YieldLocalNonAttrs | YieldDeepNonAttrs,
  YieldAllChildren = YieldAttrs | YieldNonAttrs, YieldAll = YieldAllChildren | YieldSelf, ScanAttrs = 128,
  ScanHeads = 256, ScanArgsOnly = 512, ScanNonAttrs = ScanHeads | ScanArgsOnly,
  ScanAll = ScanAttrs | ScanNonAttrs
}
 Specifies which children to enumerate when calling LNode.Descendants(). More...
 
enum  OperatorShape {
  Suffix = -1, Nullary = 0, Prefix = 1,
  Infix = 2, Ternary = 3, Other = 4
}
 An enum of common operator formats. More...
 
enum  ParseNumberFlag {
  ParseNumberFlag.SkipSpacesInFront = 1, ParseNumberFlag.SkipSpacesInsideNumber = 2, ParseNumberFlag.StopBeforeOverflow = 4,
  ParseNumberFlag.SkipUnderscores = 8, ParseNumberFlag.SkipSingleQuotes = 16, ParseNumberFlag.AllowCommaDecimalPoint = 32
}
 Flags that can be used with ParseHelpers.TryParseUInt(ref UString, out ulong, int, ParseNumberFlag) More...
 

Detailed Description

Loyc.Syntax.dll: contains Loyc trees (Loyc.Syntax.LNode), lexing stuff, LLLPG base classes (BaseParser{T} and BaseLexer), the LES parser and printer, data types related to source code management (e.g. ISourceFile, SourceRange) and other general-purpose code related to the manipulation of syntax.

Enumeration Type Documentation

◆ EscapeC

enum Loyc.Syntax.EscapeC
strong

Flags to control

See also
PrintHelpers.EscapeCStyle(UString, EscapeC)

and the reverse operation in ParseHelpers.

Enumerator
Minimal 

Only \r,
, \0 and backslash are escaped.

Default 

Default option for escaping

NonAscii 

Escape ALL characters with codes above 127 as \xNN or \uNNNN

BackslashX 

Use \xNN instead of \u00NN for characters 1-31 and 127-255

Control 

Escape all characters with codes below 32, including \t

ABFV 

Use \f and \v (rather than \xNN or \xNN)

DoubleQuotes 

Escape double quotes as "

SingleQuotes 

Escape single quotes as \'

Quotes 

Escape single and double quotes

UnicodeNonCharacters 

Escape non-character unicode code points such as the Byte Order Mark and unpaired surrogate pair characters.

UnicodePrivateUse 

Escape unicode private-use code points.

HasEscapes 

While unescaping, a backslash was encountered.

Unrecognized 

While unescaping, an unrecognized escape was encountered .

HasLongEscape 

While unescaping, a valid \U escape was encountered with more than 4 digits. To detect whether the value was above 0xFFFF, however, one must check the output.

HasInvalid6DigitEscape 

While unescaping, a valid \U escape was encountered with 6 digits, but the number was more than 0x10FFFF and had to be treated as 5 digits to make it valid.

Always appears with HasLongEscape | HasEscapes

◆ LNodeKind

enum Loyc.Syntax.LNodeKind
strong

The three kinds of nodes in a Loyc tree

◆ NodeScanMode

Specifies which children to enumerate when calling LNode.Descendants().

TODO code review

◆ NodeStyle

enum Loyc.Syntax.NodeStyle : byte
strong

Suggests a printing style when serializing a Loyc tree to text.

See LNode.Style.

TODO: review, rethink.

A printer should not throw exceptions unless specifically requested. It should ignore printing styles that it does not allow, rather than throwing.

Styles may be used in different ways by different parsers, different printers and different people. Be careful how you rely on them; they are intended to affect only the appearance of a node when it is printed, not its semantics.

Please note that language-specific printing styles can be denoted by attaching special attributes recognized by the printer for that language. These attributes should have Names starting with the % character; printers are programmed to ignore trivia attributes that they do not understand.

Enumerator
Default 

No style category is specified; the printer should choose a style automatically.

Operator 

Indicates that a node was parsed as an operator (infix, prefix, suffix, or other operator), or that it should be printed with operator notation if possible.

StatementBlock 

The node's immediate children (and/or the node itself) should be printed in statement notation, if possible in the context in which it is located.

Used to mark braced blocks. In LES, marks a call in which ';' is used as the argument separator.

Special 

A language-specific special notation should be used for this node. In LES3, the parser puts this style on keyword expressions (e.g. #if x {...}).

PrefixNotation 

The node should be printed in prefix notation (even if it is not the natural notation to use). An example in EC# notation is &lsquo;’+`(X, Y) instead of X + Y.

Expression 

The node(s) should be printed as a normal expression, rather than using a special or statement notation.

In EC#, braced initializer blocks have this style. The EC# node printer will refuse to print a node with this style as a statement.

Compact 

The node's children should have a compact notation. In LES3, the Julia-style list or call notation has this style: [. a b c 2+2]. When combined with NodeStyle.Alternate, this requests expression-tree notation like [' ...], which can only be used if the Loyc tree meets certain constraints.

OldStyle 

Use an older or backward-compatible notation.

In EC#: prints lambda as delegate; forces old cast notation in EC#.

VerbatimId 

Indicates that an identifier was marked in the standard way used to indicate that it contained special characters or matched a keyword (e.g. @int in C#)

Indicates the presence of the marking (e.g. @ sigil in C#) regardless of whether the marking is necessary. Node printers must ensure their output is valid even when this style is not present.

BinaryLiteral 

Used for a binary (base-2) literal like 0b11111.

HexLiteral 

Used for a hexadecimal (base-16) literal like 0x1F.

OctalLiteral 

Used for an octal (base-7) literal like 0o37.

Octal literals are not natively supported in LES.

VerbatimStringLiteral 

Used for an EC# verbatim string literal like "foo".

TQStringLiteral 

Used for a triple-quoted string literal like '''foo'''.

TDQStringLiteral 

Used for a triple-double-quoted string literal like """foo""".

BaseStyleMask 

If s is a NodeStyle, (s & NodeStyle.BaseStyleMask) is the base style (Default, Operator, Statement, Special, PrefixNotation, Expression or OldStyle).

Alternate 

If this node has two styles in which it can be printed, this selects the second (the less common style, or less-well-supported style). In EC#, it denotes x(->int) as opposed to (int)x, and x (as Y) as opposed to (x as Y). In C#, delegate(X) {Y;} is considered to be the alternate style for X => Y; it forces parens and braces as a side-effect.

InternalFlag 

Reserved for use by specific compilers/languages.

OneLiner 

Indicates that the there is no comment or newline trivia associated with the children of this node, and therefore when printing this node, automatic newlines can be suppressed.

Handled 

Indicates that some part of a compiler, or a macro, has seen the node and done something with it.

The motivation for this flag relates to compilers that allow user-defined attributes for plug-ins or macros that add functionality. For example, internationalization plug-in might notice a language marker:

MessageBox.Show([en] "Hello, World!");

If an attribute is not used by any plug-in, the compiler should print a warning that the attribute is unused. This leads to the question, how can a compiler tell if an attribute was ever used? The Handled flag is one possible mechanism; when any part of the compiler or its plug- ins use an attribute, the Handled flag could be set to disable the compiler warning.

Remember that the same node can theoretically appear in multiple places in a syntax tree, which typically happens when a statement or expression is duplicated by a macro, without being changed. When a style is changed on such a node, the change is visible at all locations where the same node is used. However, style flags are not synchronized between copies of a node.

◆ OperatorShape

An enum of common operator formats.

It is intentional that the absolute value of each OperatorShape (except Other) is the arity of (number of arguments to) that shape.

◆ ParseNumberFlag

Flags that can be used with ParseHelpers.TryParseUInt(ref UString, out ulong, int, ParseNumberFlag)

Enumerator
SkipSpacesInFront 

Skip spaces before the number. Without this flag, initial spaces make parsing fail.

SkipSpacesInsideNumber 

Skip spaces inside the number. Without this flag, spaces make parsing stop.

StopBeforeOverflow 

Changes overflow handling behavior when parsing an integer, so that the result does not overflow (wrap), and the digit(s) at the end of the string, that would have caused overflow, are ignored. In this case, the return value is still false.

SkipUnderscores 

Skip underscores inside number. Without this flag, underscores make parsing stop.

SkipSingleQuotes 

Skip single quotes inside number. Without this flag, single quotes make parsing stop.

AllowCommaDecimalPoint 

Whether to treat comma as a decimal point when parsing a float. The dot '.' is always treated as a decimal point.