Ejemplo n.º 1
0
        public ScriptPage Run()
        {
            Messages    = new LogMessageBag();
            HasErrors   = false;
            _blockLevel = 0;
            _isExpressionDepthLimitReached = false;
            Blocks.Clear();

            var page        = Open <ScriptPage>();
            var parsingMode = CurrentParsingMode;

            switch (parsingMode)
            {
            case ScriptMode.FrontMatterAndContent:
            case ScriptMode.FrontMatterOnly:
                if (Current.Type != TokenType.FrontMatterMarker)
                {
                    LogError($"When `{CurrentParsingMode}` is enabled, expecting a `{_lexer.Options.FrontMatterMarker}` at the beginning of the text instead of `{Current.GetText(_lexer.Text)}`");
                    return(null);
                }

                _inFrontMatter = true;
                _inCodeSection = true;

                _frontmatter = Open <ScriptFrontMatter>();

                // Parse the frontmatter start=-marker
                ExpectAndParseTokenTo(_frontmatter.StartMarker, TokenType.FrontMatterMarker);

                // Parse front-marker statements
                _frontmatter.Statements = ParseBlockStatement(_frontmatter);

                // We should not be in a frontmatter after parsing the statements
                if (_inFrontMatter)
                {
                    LogError($"End of frontmatter `{_lexer.Options.FrontMatterMarker}` not found");
                }

                page.FrontMatter = _frontmatter;
                page.Span        = _frontmatter.Span;

                if (parsingMode == ScriptMode.FrontMatterOnly)
                {
                    return(page);
                }
                break;

            case ScriptMode.ScriptOnly:
                _inCodeSection = true;
                break;
            }

            page.Body = ParseBlockStatement(page);
            if (page.Body != null)
            {
                page.Span = page.Body.Span;
            }

            // Flush any pending trivias
            if (_isKeepTrivia && _lastTerminalWithTrivias != null)
            {
                FlushTriviasToLastTerminal();
            }

            if (page.FrontMatter != null)
            {
                FixRawStatementAfterFrontMatter(page);
            }

            if (_lexer.HasErrors)
            {
                foreach (var lexerError in _lexer.Errors)
                {
                    Log(lexerError);
                }
            }

            return(page);
        }
Ejemplo n.º 2
0
 public ScribanFrontMatter(ScriptFrontMatter frontmatter)
 {
     Value = frontmatter;
 }