/// <summary> /// Preprocesses, Lexes and Parses a C# compilation unit. Subscribe to the OnError /// event before calling this method to receive error notifications. /// After calling Parse, the Defines property contains the list of preprocessor /// symbols defined as a result of #define and #undef directives in this /// compilation unit. /// </summary> public CompilationUnitNode Parse(Token[] tokens, LineMap lineMap) { _lineMap = lineMap; CompilationUnitNode parseTree = _parser.Parse(tokens); _lineMap = null; return parseTree; }
/// <summary> /// Preprocesses, Lexes and Parses a C# compilation unit. Subscribe to the OnError /// event before calling this method to receive error notifications. /// After calling Parse, the Defines property contains the list of preprocessor /// symbols defined as a result of #define and #undef directives in this /// compilation unit. /// </summary> public CompilationUnitNode Parse(Token[] tokens, LineMap lineMap) { _lineMap = lineMap; CompilationUnitNode parseTree = _parser.Parse(tokens); _lineMap = null; return(parseTree); }
public CompilationUnitNode BuildCodeModel(IStreamSource source) { _hasErrors = false; string filePath = source.FullName; #if DEBUG if (_options.InternalTestMode) { // This ensures in file paths are just file names in test output. filePath = Path.GetFileName(filePath); } #endif // DEBUG char[] buffer = GetBuffer(source); if (buffer == null) { _errorHandler.ReportError("Unable to read from file " + filePath, filePath); return null; } IDictionary definesTable = new Hashtable(); if ((_options.Defines != null) && (_options.Defines.Count != 0)) { foreach (string s in _options.Defines) { definesTable[s] = null; } } NameTable nameTable = new NameTable(); LineMap lineMap = new LineMap(filePath); FileLexer lexer = new FileLexer(nameTable, filePath); lexer.OnError += new FileErrorEventHandler(OnError); Token[] tokens = lexer.Lex(buffer, definesTable, lineMap, /* includeComments */ false); if (_hasErrors == false) { FileParser parser = new FileParser(nameTable, filePath); parser.OnError += new FileErrorEventHandler(OnError); CompilationUnitNode compilationUnit = parser.Parse(tokens, lineMap); foreach (ParseNode node in compilationUnit.Members) { NamespaceNode namespaceNode = node as NamespaceNode; if (namespaceNode != null) { namespaceNode.IncludeCompilationUnitUsingClauses(); } } if (_hasErrors == false) { return compilationUnit; } } return null; }
/// <summary> /// Lexes a compilation unit. /// </summary> /// <param name="text"> The text to lex. </param> /// <param name="defines"> The set of preprocessor symbols defined in source. /// Is modified to include results of #define/#undef found in this compilation unit. </param> /// <param name="lineMap">The LineMap contains the source text to file/line mapping /// as a result of #line directives. </param> /// <param name="includeComments"> Should comment tokens be generated. </param> /// <returns></returns> public Token[] Lex(char[] text, IDictionary defines, LineMap lineMap, bool includeComments) { // initialize _text = new TextBuffer(text); _defines = defines; _lineMap = lineMap; _includeComments = includeComments; LexFile(); _text = null; _defines = null; _lineMap = null; _includeComments = false; return (Token[])_tokens.ToArray(typeof(Token)); }
/// <summary> /// Lexes a compilation unit. /// </summary> /// <param name="text"> The text to lex. </param> /// <param name="defines"> The set of preprocessor symbols defined in source. /// Is modified to include results of #define/#undef found in this compilation unit. </param> /// <param name="lineMap">The LineMap contains the source text to file/line mapping /// as a result of #line directives. </param> /// <param name="includeComments"> Should comment tokens be generated. </param> /// <returns></returns> public Token[] Lex(char[] text, IDictionary defines, LineMap lineMap, bool includeComments) { // initialize _text = new TextBuffer(text); _defines = defines; _lineMap = lineMap; _includeComments = includeComments; LexFile(); _text = null; _defines = null; _lineMap = null; _includeComments = false; return((Token[])_tokens.ToArray(typeof(Token))); }
internal FileErrorEventArgs(ErrorEventArgs e, LineMap lineMap) : this(e.Error, lineMap.Map(e.Position), e.Args) { }