Beispiel #1
0
        /// <summary>
        /// Creates a new parser from a seekable stream including scanning the BOM or looking for a # coding: comment to detect the appropriate coding.
        /// </summary>
        public static Parser CreateParser(Stream stream, JLanguageVersion version, ParserOptions parserOptions = null)
        {
            var options = parserOptions ?? ParserOptions.Default;

            var reader = GetStreamReaderWithEncoding(stream, JAsciiEncoding.Instance, options.ErrorSink);

            return CreateParser(reader, version, options);
        }
Beispiel #2
0
        public static Parser CreateParser(TextReader reader, JLanguageVersion version, ParserOptions parserOptions)
        {
            if (reader == null) {
                throw new ArgumentNullException("reader");
            }

            var options = parserOptions ?? ParserOptions.Default;

            Tokenizer tokenizer = new Tokenizer(version, options.ErrorSink, (options.Verbatim ? TokenizerOptions.Verbatim : TokenizerOptions.None) | TokenizerOptions.GroupingRecovery);

            tokenizer.Initialize(null, reader, SourceLocation.MinValue);
            tokenizer.IndentationInconsistencySeverity = options.IndentationInconsistencySeverity;

            Parser result = new Parser(tokenizer,
                options.ErrorSink ?? ErrorSink.Null,
                version,
                options.Verbatim,
                options.BindReferences,
                options.PrivatePrefix
            );

            result._sourceReader = reader;
            return result;
        }