public IReadOnlyList <StyledSpan <TextStyle> > Highlight(string commandLine) { if (commandLine == null) { throw new ArgumentNullException(nameof(commandLine)); } if (commandLine.Length == 0) { return(Array.Empty <StyledSpan <TextStyle> >()); } if (String.IsNullOrWhiteSpace(commandLine)) { return(GetDefaultForAll(commandLine)); } var syntax = _parser.Parse(commandLine); var highlights = new List <StyledSpan <TextStyle> >(); var visitorParams = new CommandLineHighlightingVisitorParams <TextStyle>( highlights, _highlightingOptions.Palette); syntax.Accept(_highlightingVisitor, visitorParams); return(highlights); }
public bool VisitCommandName(CommandNameSyntax commandName, CommandLineHighlightingVisitorParams <TStyle> param) { var spans = param.Spans; var palette = param.Palette; foreach (var namePart in commandName.NameParts) { AddSpans(spans, namePart, CommandLineStyleName.CommandName, palette); } return(false); }
public bool VisitOption(OptionSyntax option, CommandLineHighlightingVisitorParams <TStyle> param) { var spans = param.Spans; var palette = param.Palette; if (option.NameMarker != null) { AddSpans(spans, option.NameMarker, CommandLineStyleName.OptionNameMarker, palette); } AddSpans(spans, option.Name, CommandLineStyleName.OptionName, palette); if (option.ValueMarker != null) { AddSpans(spans, option.ValueMarker, CommandLineStyleName.OptionValueMarker, palette); } if (option.Value != null) { AddSpans(spans, option.Value, CommandLineStyleName.OptionValue, palette); } return(false); }
public bool VisitCommandLine(CommandLineSyntax commandLine, CommandLineHighlightingVisitorParams <TStyle> param) { return(true); }
public bool VisitValue(ValueSyntax value, CommandLineHighlightingVisitorParams <TStyle> param) { return(false); }
public bool VisitOperand(OperandSyntax operand, CommandLineHighlightingVisitorParams <TStyle> param) { AddSpans(param.Spans, operand.Value, CommandLineStyleName.Operand, param.Palette); return(false); }
public bool VisitEndOfOptions(EndOfOptionsSyntax endOfOptions, CommandLineHighlightingVisitorParams <TStyle> param) { AddSpans(param.Spans, endOfOptions.Token, CommandLineStyleName.EndOfOptions, param.Palette); return(false); }
public bool VisitArgumentsSection(ArgumentsSectionSyntax argumentsSection, CommandLineHighlightingVisitorParams <TStyle> param) { return(true); }