Enhanced C#
Language of your choice: library documentation
Namespaces | Classes | 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 have special meaning somewhere in Loyc or EC#: 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  IIndexPositionMapper
 This interface is for classes that can convert indexes to SourcePos structures and back. More...
 
interface  IIndexToLine
 Contains IndexToLine method. 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  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  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  IToLNode
 An interface for objects that can be converted to LNode. More...
 
class  LineAndCol
 Holds a line number (Line) and a position in the line (PosInLine). This class isn't really needed in Loyc but is separated from SourcePos in case anyone might want position without a filename. 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  LiteralNode
 Base class of all nodes that represent literal values such as 123 and "foo". 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...
 
class  LNodePrinter
 Standard extension methods for ILNodePrinter. More...
 
class  LNodePrinterOptions
 A concrete class that users can pass to an LNodePrinter. More...
 
class  LNodeTests
 
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  ParsingService
 Standard extension methods for IParsingService. More...
 
struct  Precedence
 A four-byte tuple that represents the precedence and miscibility of an operator. 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
 Holds a filename (FileName), a line number (Line) and a position in the line (PosInLine), representing a position in a source code file. More...
 
class  SourcePosAndIndex
 A SourcePos that also includes the original index from which the Line and PosInLine were derived. 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  StandardTriviaInjector
 Encapsulates an algorithm that consumes trivia (comments and newlines) from a list and adds it as trivia attributes into LNodes. 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...
 

Enumerations

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 ParseHelpers.EscapeCStyle(UString, EscapeC). 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(UString, out ulong, int, ParseNumberFlag) 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  LNodeKind { Id, Literal, Call }
 The three kinds of nodes in a Loyc tree More...
 
enum  NodeStyle : byte {
  NodeStyle.Default = 0, NodeStyle.Operator = 1, NodeStyle.Statement = 2,
  NodeStyle.Special = 3, NodeStyle.PrefixNotation = 4, NodeStyle.Expression = 5,
  NodeStyle.Reserved = 6, NodeStyle.OldStyle = 7, NodeStyle.BaseStyleMask = 7,
  NodeStyle.BinaryLiteral = 5, NodeStyle.HexLiteral = 6, NodeStyle.OctalLiteral = 7,
  NodeStyle.VerbatimStringLiteral = 5, NodeStyle.TQStringLiteral = 6, NodeStyle.TDQStringLiteral = 7,
  NodeStyle.Alternate = 16, NodeStyle.InjectedTrivia = 32, NodeStyle.OneLiner = 64,
  NodeStyle.Handled = 128
}
 Suggests a printing style when serializing a Loyc tree to text. More...
 
enum  OperatorShape {
  Suffix = -1, Nullary = 0, Prefix = 1,
  Infix = 2, Ternary = 3, Other = 4
}
 An enum of common operator formats. 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

enum Loyc.Syntax.EscapeC
strong

Flags to control ParseHelpers.EscapeCStyle(UString, EscapeC).

Enumerator
Minimal 

Only ,
, \0 and backslash are escaped.

Default 

Default option for escaping

NonAscii 

Escape ALL characters with codes above 127 as or

BackslashX 

Use instead of for characters 1-31 and 127-255

Control 

Escape all characters with codes below 32, including

ABFV 

Use and (rather than or )

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 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 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

enum Loyc.Syntax.LNodeKind
strong

The three kinds of nodes in a Loyc tree

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

TODO code review

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 string "#trivia_"; 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.

Statement 

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 LESv3, the parser puts this style on block call nodes (e.g. if (...) {...}) and 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 @`'+`(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.

Reserved 

Unassigned.

OldStyle 

Use an older or backward-compatible notation.

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

BaseStyleMask 

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

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.

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""".

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.

InjectedTrivia 

Injected trivia (see AbstractTriviaInjector<Trivia>) will have this bit set.

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 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 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. Remember that 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.

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.

Flags that can be used with ParseHelpers.TryParseUInt(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.