/// <summary> /// Creates the lexer from XML file used by the Notepad++ software. /// </summary> /// <param name="scintilla">The <see cref="Scintilla"/> which lexer style to set.</param> /// <param name="lexerType">Type of the lexer.</param> /// <param name="fileName">A file name to get the lexer type from.</param> /// <param name="useGlobalOverride">A flag indicating whether the style "Global override" should be set for the lexer from the XML document.</param> /// <param name="font">A flag indicating whether to use the defined font name from the XML document or not.</param> /// <param name="useWhiteSpace">A flag indicating whether to color the white space symbol.</param> /// <param name="useSelectionColors">A flag indicating whether to color the selection.</param> /// <param name="useMarginColors">A flag indicating whether to color the margin.</param> /// <returns><c>true</c> if the operation was successful, <c>false</c> otherwise.</returns> public static bool CreateLexerFromFile(Scintilla scintilla, LexerType lexerType, string fileName, bool useGlobalOverride, bool font, bool useWhiteSpace, bool useSelectionColors, bool useMarginColors) { try { XDocument document = XDocument.Load(fileName); ScintillaNotepadPlusPlusStyles.SetGlobalDefaultStyles(document, scintilla, useGlobalOverride, font); ScintillaNotepadPlusPlusStyles.LoadScintillaStyleFromNotepadPlusXml(document, scintilla, useWhiteSpace, useSelectionColors, useMarginColors); ScintillaNotepadPlusPlusStyles.LoadLexerStyleFromNotepadPlusXml(document, scintilla, lexerType); // TODO::Font? scintilla.Lexer = LexerTypeName.GetLexerByLexerType(lexerType); ScintillaKeyWords.SetKeywords(scintilla, lexerType); LexerFoldProperties.SetFoldProperties(scintilla, lexerType); ScintillaNotepadPlusPlusStyles.SetFolding(document, scintilla); System.Diagnostics.Debug.WriteLine(scintilla.DescribeKeywordSets()); return(true); } catch { return(false); } }
public Lexer(ReadOnlySpan <char> text, int offset, int length, LexerType lexerType) { _text = text; _offset = offset; Length = length; LexerType = lexerType; }
public Lexer(string text) { _text = text.AsSpan(); _offset = 0; Length = 0; LexerType = LexerType.None; }
public void ShouldBe(LexerType lexerType) { if (LexerType != lexerType) { throw new Exception($"[{GetCurrentPosition()}] expected: {lexerType}, but was {LexerType}"); } }
/// <summary> /// A helper method to be used with HTML including scripts. /// </summary> /// <param name="lexerType">Type of the lexer to embed into the HTML lexer.</param> /// <param name="scintilla">An instance to a scintilla to which to append the script lexer.</param> /// <param name="lexerColors">A <see cref="LexerColors"/> class instance for the lexer coloring.</param> public static void SetScriptedHtml(LexerType lexerType, Scintilla scintilla, LexerColors.LexerColors lexerColors) { if (lexerType == LexerType.PHP || lexerType == LexerType.HTML) { SetHtmlStyles(scintilla, lexerColors); if (lexerType == LexerType.PHP) { var keyWords = ScintillaKeyWords.KeyWordList.FirstOrDefault(f => f.LexerType == LexerType.HTML); if (keyWords != null) { scintilla.SetKeywords(1, keyWords.KeyWords); } } else if (lexerType == LexerType.HTML) { var keyWords = ScintillaKeyWords.KeyWordList.FirstOrDefault(f => f.LexerType == LexerType.PHP); if (keyWords != null) { scintilla.SetKeywords(1, keyWords.KeyWords); } } LexerFoldProperties.SetScintillaProperties(scintilla, LexerFoldProperties.HyperTextFolding); SetHtmlStyles(scintilla, lexerColors); } }
public Lexer Skip(LexerType type) { if (LexerType != type) { throw new Exception($"[{GetCurrentPosition()}]expected {type} but found {LexerType}"); } return(Next()); }
public Lexer SkipUntil(LexerType type) { var next = this; while ((next = next.Next()).LexerType != type) { } return(next); }
/// <summary> /// Finds and checks the menu item(s) with the given <see cref="LexerType"/>. /// </summary> /// <param name="lexerType">Type of the lexer of which corresponding menu item(s) to check.</param> public void CheckLanguage(LexerType lexerType) { ToolStripMenuItem checkMainMenuItem = null; foreach (ToolStripMenuItem menuItem in menuStrip.DropDownItems) { foreach (ToolStripMenuItem subMenuItem in menuItem.DropDownItems) { // check or un-check the menu item.. if (subMenuItem.Tag != null && subMenuItem.Tag.GetType() == typeof(LexerType)) { var menuLexerType = (LexerType)subMenuItem.Tag; subMenuItem.Checked = menuLexerType == lexerType; if (menuLexerType == lexerType) { // this gets unchecked in drop down styled menu, so save it for later.. checkMainMenuItem = menuItem; } } else { subMenuItem.Checked = false; } } // check or un-check the menu item.. if (menuItem.Tag != null && menuItem.Tag.GetType() == typeof(LexerType)) { var menuLexerType = (LexerType)menuItem.Tag; menuItem.Checked = menuLexerType == lexerType; } else { menuItem.Checked = false; } } // if a menu item was assigned to be checked.. if (checkMainMenuItem != null) { // ..check it.. checkMainMenuItem.Checked = true; } }
//Получить следущую лексему private Lexeme Next_token() { var lex = new Lexeme(); str_val = ""; cur_Type = LexerType.S; while (cur_Type != LexerType.D) { Next_char(); } lex.Type = lex_type; lex.val = str_val; lex.line = last_lex_start_line_pos; lex.char_pos = last_lex_start_col_pos; lexemes.Add(lex); return(lex); }
//Обработать следущий символ private void Next_char() { CharType charType = CharType.Non_lang_symb; if (char_count >= src_code.Length) { charType = CharType.Eof; } else { char c = src_code[char_count]; last_char = c; if (char.IsLetter(c)) { charType = CharType.Character; } if (char.IsNumber(c)) { charType = CharType.Numeric; } if (c == '<') { charType = CharType.Less; } if (c == '=') { charType = CharType.Equal; } if (c == '>') { charType = CharType.More; } if (symbols.ContainsKey(c)) { charType = CharType.Symbol; } if (skip_chars.Contains(c)) { charType = CharType.Skip; } } char_count++; cur_col++; conversion_table[cur_Type][charType].Item2(this); cur_Type = conversion_table[cur_Type][charType].Item1; }
/// <summary> /// Sets the fold properties to a given lexer type. /// </summary> /// <param name="scintilla">The <see cref="Scintilla"/> of which fold properties to set.</param> /// <param name="lexerType">Type of the lexer.</param> public static void SetFoldProperties(Scintilla scintilla, LexerType lexerType) { switch (lexerType) { case LexerType.HTML: SetScintillaProperties(scintilla, HyperTextFolding); break; case LexerType.SQL: SetScintillaProperties(scintilla, SqlFolding); break; case LexerType.Xml: SetScintillaProperties(scintilla, XmlFolding); break; default: SetScintillaProperties(scintilla, DefaultFolding); break; } }
/// <summary> /// Gets or sets the <see cref="System.String"/> with the specified lexer type. /// </summary> /// <param name="lexerType">Type of the lexer.</param> /// <returns>System.String.</returns> public string this[LexerType lexerType] { // no need to validate anything.. get => LexersList.FirstOrDefault(f => f.lexerType == lexerType).programmingLanguageName;
/// <summary> /// Creates the lexer from XML file used by the Notepad++ software. /// </summary> /// <param name="scintilla">The <see cref="Scintilla"/> which lexer style to set.</param> /// <param name="lexerType">Type of the lexer.</param> /// <param name="fileName">A file name to get the lexer type from.</param> /// <returns><c>true</c> if the operation was successful, <c>false</c> otherwise.</returns> public static bool CreateLexerFromFile(Scintilla scintilla, LexerType lexerType, string fileName) { return(CreateLexerFromFile(scintilla, lexerType, fileName, true, true, true, true, true)); }
/// <summary> /// Creates the lexer for a given Scintilla class instance with a given language type enumeration. /// </summary> /// <param name="scintilla">A Scintilla class instance to set the lexer style for.</param> /// <param name="lexerType">Type of the lexer / programming language.</param> /// <returns>True if the given lexer was found; otherwise false (a work in progress).</returns> public static bool CreateLexer(Scintilla scintilla, LexerType lexerType) { if (lexerType == LexerType.Cs) { return(CreateLexerCs.CreateCsLexer(scintilla, LexerColors)); } if (lexerType == LexerType.Xml) { return(CreateLexerXml.CreateXmlLexer(scintilla, LexerColors)); } if (lexerType == LexerType.Cpp) { return(CreateLexerCpp.CreateCppLexer(scintilla, LexerColors)); } if (lexerType == LexerType.Text || lexerType == LexerType.Unknown) { return(CreateLexerNull.CreateNullLexer(scintilla)); } if (lexerType == LexerType.Nsis) { return(CreateLexerNsis.CreateNsisLexer(scintilla, LexerColors)); } if (lexerType == LexerType.InnoSetup) { return(CreateLexerInnoSetup.CreateInnoSetupLexer(scintilla, LexerColors)); } if (lexerType == LexerType.SQL) { return(CreateLexerSql.CreateSqlLexer(scintilla, LexerColors)); } if (lexerType == LexerType.Batch) { return(CreateLexerBatch.CreateBatchLexer(scintilla, LexerColors)); } if (lexerType == LexerType.Pascal) { return(CreateLexerPascal.CreatePascalLexer(scintilla, LexerColors)); } if (lexerType == LexerType.PHP) { return(CreateLexerPhp.CreatePhpLexer(scintilla, LexerColors)); } if (lexerType == LexerType.HTML) { return(CreateLexerHtml.CreateHtmlLexer(scintilla, LexerColors)); } if (lexerType == LexerType.WindowsPowerShell) { return(CreateLexerPowerShell.CreatePowerShellLexer(scintilla, LexerColors)); } if (lexerType == LexerType.INI) { return(CreateLexerIni.CreateIniLexer(scintilla, LexerColors)); } if (lexerType == LexerType.Python) { return(CreateLexerPython.CreatePythonLexer(scintilla, LexerColors)); } if (lexerType == LexerType.YAML) { return(CreateLexerYaml.CreateYamlLexer(scintilla, LexerColors)); } if (lexerType == LexerType.Java) { return(CreateLexerJava.CreateJavaLexer(scintilla, LexerColors)); } if (lexerType == LexerType.JavaScript) { return(CreateLexerJavaScript.CreateJavaScriptLexer(scintilla, LexerColors)); } if (lexerType == LexerType.Css) { return(CreateLexerCss.CreateCssLexer(scintilla, LexerColors)); } // a lexer wasn't found.. return(false); }
/// <summary> /// Creates the lexer from XML file used by the Notepad++ software. /// </summary> /// <param name="scintilla">The <see cref="Scintilla"/> which lexer style to set.</param> /// <param name="lexerType">Type of the lexer.</param> /// <param name="fileName">A file name to get the lexer type from.</param> /// <param name="useGlobalOverride">A flag indicating whether the style "Global override" should be set for the lexer from the XML document.</param> /// <param name="font">A flag indicating whether to use the defined font name from the XML document or not.</param> /// <returns><c>true</c> if the operation was successful, <c>false</c> otherwise.</returns> public static bool CreateLexerFromFile(Scintilla scintilla, LexerType lexerType, string fileName, bool useGlobalOverride, bool font) { return(CreateLexerFromFile(scintilla, lexerType, fileName, useGlobalOverride, font, true, true, true)); }
public Lexeme(string value, LexerType type) { this.value = value; this.type = type; }