summaryrefslogtreecommitdiff
path: root/external/aspnetwebstack/src/System.Web.Razor/Parser/ParserBase.cs
blob: ccf0393cedf223d51943bdbd3852b62cf0d276ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System.Diagnostics;
using System.Web.Razor.Parser.SyntaxTree;
using System.Web.Razor.Resources;
using System.Web.Razor.Text;

namespace System.Web.Razor.Parser
{
    public abstract class ParserBase
    {
        private ParserContext _context;

        public virtual ParserContext Context
        {
            get { return _context; }
            set
            {
                Debug.Assert(_context == null, "Context has already been set for this parser!");
                _context = value;
                _context.AssertOnOwnerTask();
            }
        }

        public virtual bool IsMarkupParser
        {
            get { return false; }
        }

        protected abstract ParserBase OtherParser { get; }

        public abstract void BuildSpan(SpanBuilder span, SourceLocation start, string content);

        public abstract void ParseBlock();

        // Markup Parsers need the ParseDocument and ParseSection methods since the markup parser is the first parser to hit the document 
        // and the logic may be different than the ParseBlock method.
        public virtual void ParseDocument()
        {
            Debug.Assert(IsMarkupParser);
            throw new NotSupportedException(RazorResources.ParserIsNotAMarkupParser);
        }

        public virtual void ParseSection(Tuple<string, string> nestingSequences, bool caseSensitive)
        {
            Debug.Assert(IsMarkupParser);
            throw new NotSupportedException(RazorResources.ParserIsNotAMarkupParser);
        }
    }
}