Enhanced C#
Language of your choice: library documentation
Public fields | Properties | Public Member Functions | List of all members
Loyc.Ecs.Parser.EcsPreprocessor Class Reference

Handles EC# processor directives. More...


Source file:
Inheritance diagram for Loyc.Ecs.Parser.EcsPreprocessor:
Loyc.Syntax.Lexing.LexerWrapper< Token > Loyc.Syntax.Lexing.ILexer< Token > Loyc.Syntax.IIndexToLine

Remarks

Handles EC# processor directives.

This class not only preprocesses C# source code, it saves preprocessor directives and comments so that any code excluded by the preprocessor can be added back in later, if and when the parsed code is printed out. For example, given input like this:

void foo // see below
#if false
invalid code!
#endif
() { Console.WriteLine("foo()!"); }

EcsPreprocessor removes the #if...#endif region of tokens, creates a single Token of type TokenType.PPFalseBlock to represent that region, and saves it, after the "see below" comment token, in a list.

C# has the following preprocessor directives:

#define Id
#undef Id
#if expr
#elif expr
#else
#endif
#warning {arbitrary text}
#error {arbitrary text}
#region {arbitrary text}
#endregion
#line 123 "filename"
#pragma warning ...
#pragma ... // ignored

Public fields

HashSet< SymbolDefinedSymbols = new HashSet<Symbol>()
 

Properties

bool SaveComments [get, set]
 Controls whether comments and newlines are saved into TriviaList. More...
 
DList< TokenTriviaList [get]
 A list of saved trivia: comments, newlines, preprocessor directives and ignored regions. More...
 
- Properties inherited from Loyc.Syntax.Lexing.LexerWrapper< Token >
ILexer< TokenLexer [get, set]
 
ISourceFile SourceFile [get]
 
virtual IMessageSink ErrorSink [get, set]
 
int IndentLevel [get]
 
UString IndentString [get]
 
int LineNumber [get]
 
int InputPosition [get]
 
string FileName [get]
 
- Properties inherited from Loyc.Syntax.Lexing.ILexer< Token >
ISourceFile SourceFile [get]
 The file being lexed. More...
 
IMessageSink ErrorSink [get, set]
 Event handler for errors. More...
 
int IndentLevel [get]
 Indentation level of the current line. This is updated after scanning the first whitespaces on a new line, and may be reset to zero when NextToken() returns a newline. More...
 
UString IndentString [get]
 Gets a string slice that holds the spaces or tabs that were used to indent the current line. More...
 
int LineNumber [get]
 Current line number (1 for the first line). More...
 
int InputPosition [get]
 Current input position (an index into SourceFile.Text). More...
 
- Properties inherited from Loyc.Syntax.IIndexToLine
string FileName [get]
 Gets the file name used in results returned by IndexToLine(int). More...
 

Public Member Functions

 EcsPreprocessor (ILexer< Token > source, bool saveComments)
 
override Maybe< TokenNextToken ()
 Returns the next (postprocessed) token. This method should set the _current field to the returned value. More...
 
- Public Member Functions inherited from Loyc.Syntax.Lexing.LexerWrapper< Token >
 LexerWrapper (ILexer< Token > sourceLexer)
 
SourcePos IndexToLine (int index)
 Returns the position in a source file of the specified index. More...
 
virtual void Reset ()
 

Additional Inherited Members

- Protected Member Functions inherited from Loyc.Syntax.Lexing.LexerWrapper< Token >
void WriteError (int index, string msg, params object[] args)
 
- Protected fields inherited from Loyc.Syntax.Lexing.LexerWrapper< Token >
Maybe< Token_current
 

Member Function Documentation

override Maybe<Token> Loyc.Ecs.Parser.EcsPreprocessor.NextToken ( )
inlinevirtual

Property Documentation

bool Loyc.Ecs.Parser.EcsPreprocessor.SaveComments
getset

Controls whether comments and newlines are saved into TriviaList.

DList<Token> Loyc.Ecs.Parser.EcsPreprocessor.TriviaList
get

A list of saved trivia: comments, newlines, preprocessor directives and ignored regions.