Esempio n. 1
0
		public SourceUnitTree CreateAst(string fileName, ITextBuffer fileContent)
		{
			if (scriptEngine == null) {
				scriptEngine = Ruby.CreateEngine();
			}
			
			RubyContext rubyContext = HostingHelpers.GetLanguageContext(scriptEngine) as RubyContext;
			sourceUnit = rubyContext.CreateFileUnit(fileName, fileContent.Text);
			RubyCompilerSink sink = new RubyCompilerSink();
			RubyCompilerOptions compilerOptions = new RubyCompilerOptions((RubyOptions)rubyContext.Options);
			Parser parser = new Parser();
			return parser.Parse(sourceUnit, compilerOptions, sink);
		}
Esempio n. 2
0
        private ResolvedFile GetSourceUnit(string /*!*/ path, string /*!*/ extension, bool extensionAppended)
        {
            Assert.NotNull(path, extension);

            LanguageContext language;

            if (extension.Length == 0 || !DomainManager.TryGetLanguageByFileExtension(extension, out language))
            {
                // Ruby by default:
                language = _context;
            }

            if (!DomainManager.Platform.FileExists(path))
            {
                return(null);
            }

            // TODO: default encoding:
            var sourceUnit = _context.CreateFileUnit(path, BinaryEncoding.Instance, SourceCodeKind.File);

            return(new ResolvedFile(sourceUnit, extensionAppended ? extension : null));
        }
Esempio n. 3
0
        private void DumpFile(string /*!*/ path)
        {
            _log.WriteLine(path);

            try {
                string fullPath   = Path.GetFullPath(path);
                string root       = Path.GetPathRoot(fullPath);
                string outputPath = Path.ChangeExtension(Path.Combine(_targetDir, fullPath.Substring(root.Length).TrimEnd('\'', '/')), ".txt");
                Directory.CreateDirectory(Path.GetDirectoryName(outputPath));

                using (TextWriter output = File.CreateText(outputPath)) {
                    output.WriteLine(fullPath);
                    output.WriteLine();
                    output.WriteLine("Tokens:");
                    output.WriteLine();

                    ErrorLog errors = new ErrorLog();
                    Parser   parser = new Parser();

                    parser.TokenSink = delegate(Tokens token, SourceSpan span) {
                        DumpTokenDetail(output, parser.Tokenizer, token);
                    };

                    if (_logProductions)
                    {
#if DEBUG
                        parser.EnableLogging(new CoverageParserLogger(parser, _parserLog));
#endif
                    }

                    _currentSourceFile = path;

                    SourceUnitTree ast = null;
                    try {
                        ast = parser.Parse(_context.CreateFileUnit(path), new RubyCompilerOptions(), errors);
                    } catch (Exception e) {
                        WriteException(e.ToString());
                    }

                    output.WriteLine();

                    if (errors.ErrorCount + errors.FatalErrorCount + errors.WarningCount > 0)
                    {
                        output.WriteLine();
                        output.WriteLine("Errors:");

                        foreach (string error in errors.Errors)
                        {
                            output.WriteLine(error);
                        }
                    }
                    else
                    {
                        Debug.Assert(ast != null);
                        DumpRegularExpressions(ast);
                    }

                    output.WriteLine(".");
                }
            } catch (Exception e) {
                _log.WriteLine("!{0}", e.Message);
            } finally {
                _currentSourceFile = null;
                _regexLog.Flush();
                _parserLog.Flush();
            }
        }