Example #1
0
        public Scanner(Parsers.Position initialPosition, TextReader /*!*/ reader, SourceUnit /*!*/ sourceUnit,
                       ErrorSink /*!*/ errors, ICommentsSink commentsSink, LanguageFeatures features)
            : base(reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (sourceUnit == null)
            {
                throw new ArgumentNullException("sourceUnit");
            }
            if (errors == null)
            {
                throw new ArgumentNullException("errors");
            }

            this.lineShift   = initialPosition.FirstLine;
            this.columnShift = initialPosition.FirstColumn;
            this.offsetShift = initialPosition.FirstOffset;

            this.errors       = errors;
            this.commentsSink = commentsSink ?? new _NullCommentsSink();
            this.features     = features;
            this.sourceUnit   = sourceUnit;

            this.streamOffset = 0;
            this.pure         = sourceUnit.CompilationUnit.IsPure;
            this.encoding     = sourceUnit.Encoding;

            AllowAspTags   = (features & LanguageFeatures.AspTags) != 0;
            AllowShortTags = (features & LanguageFeatures.ShortOpenTags) != 0;
        }
Example #2
0
        /// <summary>
        /// Keeps stream open.
        /// </summary>
        /// <exception cref="InvalidSourceException">Source file cannot be opened for reading.</exception>
        public override void Parse(ErrorSink /*!*/ errors, IReductionsSink /*!*/ reductionsSink,
                                   Parsers.Position initialPosition, LanguageFeatures features)
        {
            Parser       parser = new Parser();
            StreamReader source_reader;

            try
            {
                stream        = new FileStream(sourceFile.FullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                source_reader = new StreamReader(stream, encoding, true);

                // if the file contains a byte-order-mark, we must advance the offset in order to
                // get correct token positions in lexer (unfortunately, StreamReader skips BOM without
                // a possibility to detect it from outside, so we have to do that manually):

                // TODO:

                // initialPosition.FirstOffset += FileSystemUtils.GetByteOrderMarkLength(stream);
            }
            catch (Exception e)
            {
                throw new InvalidSourceException(sourceFile.FullPath, e);
            }

            ast = parser.Parse(this, source_reader, errors, reductionsSink, initialPosition,
                               Lexer.LexicalStates.INITIAL, features);
        }
Example #3
0
        public GlobalCode Parse(SourceUnit /*!*/ sourceUnit, TextReader /*!*/ reader, ErrorSink /*!*/ errors,
                                IReductionsSink reductionsSink, Parsers.Position initialPosition, Lexer.LexicalStates initialLexicalState,
                                LanguageFeatures features)
        {
            Debug.Assert(reader != null && errors != null);

            // initialization:
            this.sourceUnit     = sourceUnit;
            this.errors         = errors;
            this.features       = features;
            this.reader         = reader;
            this.reductionsSink = reductionsSink ?? NullReductionSink;
            InitializeFields();

            this.scanner = new Scanner(initialPosition, reader, sourceUnit, errors, reductionsSink as ICommentsSink, features);
            this.scanner.CurrentLexicalState = initialLexicalState;
            this.currentScope = new Scope(1);             // starts assigning scopes from 2 (1 is reserved for prepended inclusion)

            this.unicodeSemantics = (features & LanguageFeatures.UnicodeSemantics) != 0;


            base.Scanner = this.scanner;
            base.Parse();

            GlobalCode result = astRoot;

            // clean and let GC collect unused AST and other stuff:
            ClearFields();

            return(result);
        }
Example #4
0
 public void OnCloseTag(Scanner scanner, Parsers.Position position)
 {
 }
Example #5
0
 public void OnOpenTag(Scanner scanner, Parsers.Position position)
 {
 }
Example #6
0
 public void OnComment(Scanner scanner, Parsers.Position position)
 {
 }
Example #7
0
 public abstract void Parse(ErrorSink /*!*/ errors, IReductionsSink /*!*/ reductionsSink,
                            Parsers.Position initialPosition, LanguageFeatures features);