//------------------------------------------------------ // // Constructors // //------------------------------------------------------ #region Constructors /// <summary> /// XamlToRtfParser constructor /// </summary> internal XamlToRtfParser(string xaml) { _xaml = xaml; _xamlLexer = new XamlLexer(_xaml); _xamlTagStack = new XamlTagStack(); _xamlAttributes = new XamlAttributes(_xaml); }
/// <summary> /// Get the background error highlights. /// </summary> /// <param name="text">The text to highlight</param> /// <returns>Some colorings</returns> public static IEnumerable <Coloring> GetErrorHighlights(string text) { var lexer = new XamlLexer(new AntlrInputStream(text)); var parser = new XamlParser(new CommonTokenStream(lexer)); var parserListener = new ColoringParserErrorListener(); parser.AddErrorListener(parserListener); parser.document(); return(parserListener.ErrorColorings); }
/// <summary> /// Gets the foreground token-based coloring for the text. /// </summary> /// <param name="text">The text to color</param> /// <returns>Some colorings</returns> public static IEnumerable <Coloring> GetTextColorings(string text) { var lexer = new XamlLexer(new AntlrInputStream(text)); var colorings = new List <Coloring>(); var stream = new CommonTokenStream(lexer); stream.Fill(); foreach (var token in stream.GetTokens()) { switch (token.Type) { case XamlParser.OPEN: case XamlParser.CLOSE: case XamlParser.OPEN_CLOSE: case XamlParser.COMMA: case XamlParser.COLON_NS: case XamlParser.TAG_DOT_PROP: case XamlParser.SLASH_CLOSE: case XamlParser.EXT_BEGIN: case XamlParser.EXT_END: case XamlParser.EXT_DOT: case XamlParser.SUB_EXT_BEGIN: case XamlParser.SUB_EXT_END: case XamlParser.XML_EQUALS: case XamlParser.EXT_COLON: case XamlParser.EXT_EQUALS: colorings.Add(new Coloring(Brushes.SlateGray, token.StartIndex, token.StopIndex)); break; case XamlParser.XML_NAME: colorings.Add(new Coloring(Brushes.Blue, token.StartIndex, token.StopIndex)); break; case XamlParser.TAG_PROP_NAME: colorings.Add(new Coloring(Brushes.MediumAquamarine, token.StartIndex, token.StopIndex)); break; case XamlParser.STR_BEGIN: case XamlLexer.STR_CONTENT: case XamlLexer.STR_END: colorings.Add(new Coloring(Brushes.DarkRed, token.StartIndex, token.StopIndex)); break; case XamlParser.COMMENT: colorings.Add(new Coloring(Brushes.Green, token.StartIndex, token.StopIndex)); break; case XamlParser.EXT_NAME: colorings.Add(new Coloring(Brushes.Orange, token.StartIndex, token.StopIndex)); break; case XamlParser.EXT_PROP_NAME: colorings.Add(new Coloring(Brushes.Peru, token.StartIndex, token.StopIndex)); break; case XamlLexer.ERROR_TOKEN: case XamlLexer.ERROR_TOKEN_EXT: case XamlLexer.ERROR_TOKEN_XML: case XamlLexer.ERR_TOKEN_EXT_PROP: case XamlLexer.ERR_TOKEN_TAG_PROP: case XamlLexer.STR_ERROR_END: colorings.Add(new Coloring(Brushes.Red, token.StartIndex, token.StopIndex)); break; } } return(colorings); }