private ScriptTriviaType GetWhitespaceModeFromTrivia(ScriptNode node, bool before) { if (node.Trivias == null) { return(ScriptTriviaType.Empty); } if (before) { List <ScriptTrivia> trivias = node.Trivias.Before; for (int i = trivias.Count - 1; i >= 0; i--) { ScriptTriviaType type = trivias[i].Type; if (type == ScriptTriviaType.WhitespaceFull || type == ScriptTriviaType.Whitespace) { return(type); } } } else { List <ScriptTrivia> trivias = node.Trivias.After; for (int i = 0; i < trivias.Count; i++) { ScriptTriviaType type = trivias[i].Type; if (type == ScriptTriviaType.WhitespaceFull || type == ScriptTriviaType.Whitespace) { return(type); } } } return(ScriptTriviaType.Empty); }
public static bool IsSpace(this ScriptTriviaType triviaType) { return(triviaType switch { ScriptTriviaType.Whitespace => true, ScriptTriviaType.WhitespaceFull => true, _ => false });
private void WriteEnd(ScriptNode node) { if (_expectEnd) { HandleEos(node); bool triviasHasEnd = node.HasTrivia(ScriptTriviaType.End, false); if (_previousRawStatement != null) { _nextLStrip = GetWhitespaceModeFromTrivia(_previousRawStatement, false); } if (!_isInCode) { WriteEnterCode(); } if (triviasHasEnd) { WriteTrivias(node, false); } else { Write(_isInCode ? "end" : " end "); } if (!_isInCode) { WriteExitCode(); } else { _expectEndOfStatement = true; } _expectEnd = false; } else { WriteTrivias(node, false); } if (node is ScriptPage) { if (_isInCode) { WriteExitCode(); } } }
public static bool HasTrivia(this IScriptTerminal node, ScriptTriviaType triviaType, bool before) { if (node.Trivias == null) { return false; } foreach (var trivia in (before ? node.Trivias.Before : node.Trivias.After)) { if (trivia.Type == triviaType) { return true; } } return false; }
public static bool HasTrivia(this ScriptNode node, ScriptTriviaType triviaType, bool before) { if (node.Trivias == null) { return(false); } foreach (var trivia in (before ? node.Trivias.Before : node.Trivias.After)) { if (trivia.Type == triviaType) { return(true); } } return(false); }
public TemplateRewriterContext WriteEnterCode(int escape = 0) { Write("{"); for (int i = 0; i < escape; i++) { Write("%"); } Write("{"); if (_nextLStrip != ScriptTriviaType.Empty) { Write(_nextLStrip == ScriptTriviaType.Whitespace ? "~" : "-"); _nextLStrip = ScriptTriviaType.Empty; } _expectEndOfStatement = false; _expectEnd = false; _expectSpace = false; _hasEndOfStatement = false; _isInCode = true; return(this); }
private void WriteBegin(ScriptNode node) { var rawStatement = node as ScriptRawStatement; if (!IsBlockOrPage(node)) { if (_isInCode) { if (rawStatement != null) { _nextRStrip = GetWhitespaceModeFromTrivia(rawStatement, true); WriteExitCode(); } } else if (rawStatement == null) { if (_previousRawStatement != null) { _nextLStrip = GetWhitespaceModeFromTrivia(_previousRawStatement, false); } WriteEnterCode(); } } WriteTrivias(node, true); HandleEos(node); // Add a space if this is required and no trivia are providing it if (node.CanHaveLeadingTrivia()) { if (_expectSpace && !_previousHasSpace) { Write(" "); } _expectSpace = false; } }
public ScriptTrivia(SourceSpan span, ScriptTriviaType type, string text) { Span = span; Type = type; Text = text; }
public ScriptTrivia(SourceSpan span, ScriptTriviaType type) { Span = span; Type = type; Text = null; }