public ScriptParserRuntimeException(SourceSpan span, string message, LogMessageBag parserMessages, Exception innerException) : base(span, message, innerException) { if (parserMessages == null) { throw new ArgumentNullException(nameof(parserMessages)); } ParserMessages = parserMessages; }
private void LogScriptMessages(LogMessageBag logMessages) { foreach (var logMessage in logMessages) { switch (logMessage.Type) { case ParserMessageType.Error: Site.Error(logMessage.Span, logMessage.Message); break; case ParserMessageType.Warning: Site.Warning(logMessage.Span, logMessage.Message); break; default: Site.Info(logMessage.Span, logMessage.Message); break; } } }
public Parser(Lexer lexer, ParserOptions?options = null) { _lexer = lexer ?? throw new ArgumentNullException(nameof(lexer)); _isLiquid = _lexer.Options.Lang == ScriptLang.Liquid; _isScientific = _lexer.Options.Lang == ScriptLang.Scientific; _tokensPreview = new List <Token>(4); Messages = new LogMessageBag(); _trivias = new List <ScriptTrivia>(); Options = options ?? new ParserOptions(); CurrentParsingMode = lexer.Options.Mode; _isKeepTrivia = lexer.Options.KeepTrivia; _pendingStatements = new Queue <ScriptStatement>(2); Blocks = new Stack <ScriptNode>(); // Initialize the iterator _tokenIt = lexer.GetEnumerator(); NextToken(); }
public ScriptParserRuntimeException(SourceSpan span, string message, LogMessageBag parserMessages) : this(span, message, parserMessages, null) { }
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); }
internal void AddMsgFromScribanTemplateParsing(LogMessageBag bag) { hasErrors |= bag.HasErrors; messages.AddRange(bag.Select(x => new MessageItem(x))); }