Revision: 5266 http://geany.svn.sourceforge.net/geany/?rev=5266&view=rev Author: ntrel Date: 2010-09-30 16:59:22 +0000 (Thu, 30 Sep 2010)
Log Message: ----------- Add Forth filetype (patch by Thomas Huth, thanks).
Modified Paths: -------------- trunk/ChangeLog trunk/THANKS trunk/data/filetype_extensions.conf trunk/scintilla/KeyWords.cxx trunk/scintilla/Makefile.am trunk/scintilla/makefile.win32 trunk/src/about.c trunk/src/filetypes.c trunk/src/filetypes.h trunk/src/highlighting.c trunk/wscript
Added Paths: ----------- trunk/data/filetypes.forth trunk/scintilla/LexForth.cxx
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/ChangeLog 2010-09-30 16:59:22 UTC (rev 5266) @@ -14,6 +14,12 @@ * src/document.c: Avoid delay and redrawing when automatically opening a new document after closing one. + * scintilla/LexForth.cxx, scintilla/makefile.win32, + scintilla/KeyWords.cxx, scintilla/Makefile.am, src/highlighting.c, + src/about.c, src/filetypes.c, src/filetypes.h, THANKS, + data/filetypes.forth, data/filetype_extensions.conf, ChangeLog, + wscript: + Add Forth filetype (patch by Thomas Huth, thanks).
2010-09-25 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/THANKS =================================================================== --- trunk/THANKS 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/THANKS 2010-09-30 16:59:22 UTC (rev 5266) @@ -82,6 +82,7 @@ Daniel Marjamaki <danielm77(at)spray(dot)se> - Small improvements Jiří Techet <techet(at)gmail(dot)com> - Various patches Erik de Castro Lopo <mle+tools(at)mega-nerd(dot)com> - Various patches +Thomas Huth <th(dot)huth(at)googlemail(dot)com> - Forth filetype
Translators: ------------
Modified: trunk/data/filetype_extensions.conf =================================================================== --- trunk/data/filetype_extensions.conf 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/data/filetype_extensions.conf 2010-09-30 16:59:22 UTC (rev 5266) @@ -37,6 +37,7 @@ Tcl=*.tcl;*.tk;*.wish; CSS=*.css; Docbook=*.docbook; +Forth=*.fs;*.fth; HTML=*.htm;*.html;*.shtml;*.hta;*.htd;*.htt;*.cfm; XML=*.xml;*.sgml;*.xsl;*.xslt;*.xsd;*.xhtml; CMake=CMakeLists.txt;*.cmake;*.ctest;
Added: trunk/data/filetypes.forth =================================================================== --- trunk/data/filetypes.forth (rev 0) +++ trunk/data/filetypes.forth 2010-09-30 16:59:22 UTC (rev 5266) @@ -0,0 +1,45 @@ +# For complete documentation of this file, please see Geany's main documentation +[styling] +# foreground;background;bold;italic +default=default +comment=commentdoc +commentml=comment +identifier=default +control=0x301010;0xffffff;true;false +keyword=0x301060;0xffffff;true;false +defword=0x000080;;false;true +preword1=0x000000;0xe0c0e0;false;false +preword2=0xaaaaaa;0xffffff;false;true +number=0x007f00;0xffffff;false;false +string=string +locale=0xff0000;0xffffff;false;true + +[keywords] +# all items must be in one line +primary=ABORT EXIT DO LOOP UNLOOP BEGIN UNTIL WHILE REPEAT EXIT IF ELSE THEN CASE ENDCASE OF ENDOF + + +[settings] +# default extension used when saving files +#extension=fs + +# the following characters are these which a "word" can contains, see documentation +#wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 + +# if only single comment char is supported like # in this file, leave comment_close blank +comment_open=( +comment_close= ) + +# comment_open=\ +# comment_close= + +# set to false if a comment character/string should start at column 0 of a line, true uses any +# indentation of the line, e.g. setting to true causes the following on pressing CTRL+d + #command_example(); +# setting to false would generate this +# command_example(); +# This setting works only for single line comments +comment_use_indent=true + +# context action command (please see Geany's main documentation for details) +context_action_cmd=
Property changes on: trunk/data/filetypes.forth ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native
Modified: trunk/scintilla/KeyWords.cxx =================================================================== --- trunk/scintilla/KeyWords.cxx 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/scintilla/KeyWords.cxx 2010-09-30 16:59:22 UTC (rev 5266) @@ -338,6 +338,7 @@ LINK_LEXER(lmD); LINK_LEXER(lmDiff); LINK_LEXER(lmF77); + LINK_LEXER(lmForth); LINK_LEXER(lmFortran); LINK_LEXER(lmFreeBasic); LINK_LEXER(lmHaskell);
Added: trunk/scintilla/LexForth.cxx =================================================================== --- trunk/scintilla/LexForth.cxx (rev 0) +++ trunk/scintilla/LexForth.cxx 2010-09-30 16:59:22 UTC (rev 5266) @@ -0,0 +1,176 @@ +// Scintilla source code edit control +/** @file LexForth.cxx + ** Lexer for FORTH + **/ +// Copyright 1998-2003 by Neil Hodgson neilh@scintilla.org +// The License.txt file describes the conditions under which this software may be distributed. + +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <stdio.h> +#include <stdarg.h> + +#include "Platform.h" + +#include "PropSet.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "KeyWords.h" +#include "Scintilla.h" +#include "SciLexer.h" + +#ifdef SCI_NAMESPACE +using namespace Scintilla; +#endif + +static inline bool IsAWordChar(int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '.' || + ch == '_' || ch == '?' || ch == '"' || ch == '@' || + ch == '!' || ch == '[' || ch == ']' || ch == '/' || + ch == '+' || ch == '-' || ch == '*' || ch == '<' || + ch == '>' || ch == '=' || ch == ';' || ch == '(' || + ch == ')' ); +} + +static inline bool IsAWordStart(int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.'); +} + +static inline bool IsANumChar(int ch) { + return (ch < 0x80) && (isxdigit(ch) || ch == '.' || ch == 'e' || ch == 'E' ); +} + +static inline bool IsASpaceChar(int ch) { + return (ch < 0x80) && isspace(ch); +} + +static void ColouriseForthDoc(unsigned int startPos, int length, int initStyle, WordList *keywordLists[], + Accessor &styler) { + + WordList &control = *keywordLists[0]; + WordList &keyword = *keywordLists[1]; + WordList &defword = *keywordLists[2]; + WordList &preword1 = *keywordLists[3]; + WordList &preword2 = *keywordLists[4]; + WordList &strings = *keywordLists[5]; + + StyleContext sc(startPos, length, initStyle, styler); + + for (; sc.More(); sc.Forward()) + { + // Determine if the current state should terminate. + if (sc.state == SCE_FORTH_COMMENT) { + if (sc.atLineEnd) { + sc.SetState(SCE_FORTH_DEFAULT); + } + }else if (sc.state == SCE_FORTH_COMMENT_ML) { + if (sc.ch == ')') { + sc.ForwardSetState(SCE_FORTH_DEFAULT); + } + }else if (sc.state == SCE_FORTH_IDENTIFIER || sc.state == SCE_FORTH_NUMBER) { + // handle numbers here too, because what we thought was a number might + // turn out to be a keyword e.g. 2DUP + if (IsASpaceChar(sc.ch) ) { + char s[100]; + sc.GetCurrentLowered(s, sizeof(s)); + int newState = sc.state == SCE_FORTH_NUMBER ? SCE_FORTH_NUMBER : SCE_FORTH_DEFAULT; + if (control.InList(s)) { + sc.ChangeState(SCE_FORTH_CONTROL); + } else if (keyword.InList(s)) { + sc.ChangeState(SCE_FORTH_KEYWORD); + } else if (defword.InList(s)) { + sc.ChangeState(SCE_FORTH_DEFWORD); + } else if (preword1.InList(s)) { + sc.ChangeState(SCE_FORTH_PREWORD1); + } else if (preword2.InList(s)) { + sc.ChangeState(SCE_FORTH_PREWORD2); + } else if (strings.InList(s)) { + sc.ChangeState(SCE_FORTH_STRING); + newState = SCE_FORTH_STRING; + } + sc.SetState(newState); + } + if (sc.state == SCE_FORTH_NUMBER) { + if (IsASpaceChar(sc.ch)) { + sc.SetState(SCE_FORTH_DEFAULT); + } else if (!IsANumChar(sc.ch)) { + sc.ChangeState(SCE_FORTH_IDENTIFIER); + } + } + }else if (sc.state == SCE_FORTH_STRING) { + if (sc.ch == '"') { + sc.ForwardSetState(SCE_FORTH_DEFAULT); + } + }else if (sc.state == SCE_FORTH_LOCALE) { + if (sc.ch == '}') { + sc.ForwardSetState(SCE_FORTH_DEFAULT); + } + }else if (sc.state == SCE_FORTH_DEFWORD) { + if (IsASpaceChar(sc.ch)) { + sc.SetState(SCE_FORTH_DEFAULT); + } + } + + // Determine if a new state should be entered. + if (sc.state == SCE_FORTH_DEFAULT) { + if (sc.ch == '\'){ + sc.SetState(SCE_FORTH_COMMENT); + } else if (sc.ch == '(' && + (sc.atLineStart || IsASpaceChar(sc.chPrev)) && + (sc.atLineEnd || IsASpaceChar(sc.chNext))) { + sc.SetState(SCE_FORTH_COMMENT_ML); + } else if ( (sc.ch == '$' && (isascii(sc.chNext) && isxdigit(sc.chNext))) ) { + // number starting with $ is a hex number + sc.SetState(SCE_FORTH_NUMBER); + while(sc.More() && isascii(sc.chNext) && isxdigit(sc.chNext)) + sc.Forward(); + } else if ( (sc.ch == '%' && (isascii(sc.chNext) && (sc.chNext == '0' || sc.chNext == '1'))) ) { + // number starting with % is binary + sc.SetState(SCE_FORTH_NUMBER); + while(sc.More() && isascii(sc.chNext) && (sc.chNext == '0' || sc.chNext == '1')) + sc.Forward(); + } else if ( isascii(sc.ch) && + (isxdigit(sc.ch) || ((sc.ch == '.' || sc.ch == '-') && isascii(sc.chNext) && isxdigit(sc.chNext)) ) + ){ + sc.SetState(SCE_FORTH_NUMBER); + } else if (IsAWordStart(sc.ch)) { + sc.SetState(SCE_FORTH_IDENTIFIER); + } else if (sc.ch == '{') { + sc.SetState(SCE_FORTH_LOCALE); + } else if (sc.ch == ':' && isascii(sc.chNext) && isspace(sc.chNext)) { + // highlight word definitions e.g. : GCD ( n n -- n ) ..... ; + // ^ ^^^ + sc.SetState(SCE_FORTH_DEFWORD); + while(sc.More() && isascii(sc.chNext) && isspace(sc.chNext)) + sc.Forward(); + } else if (sc.ch == ';' && + (sc.atLineStart || IsASpaceChar(sc.chPrev)) && + (sc.atLineEnd || IsASpaceChar(sc.chNext)) ) { + // mark the ';' that ends a word + sc.SetState(SCE_FORTH_DEFWORD); + sc.ForwardSetState(SCE_FORTH_DEFAULT); + } + } + + } + sc.Complete(); +} + +static void FoldForthDoc(unsigned int, int, int, WordList *[], + Accessor &) { +} + +static const char * const forthWordLists[] = { + "control keywords", + "keywords", + "definition words", + "prewords with one argument", + "prewords with two arguments", + "string definition keywords", + 0, + }; + +LexerModule lmForth(SCLEX_FORTH, ColouriseForthDoc, "forth", FoldForthDoc, forthWordLists); + +
Property changes on: trunk/scintilla/LexForth.cxx ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native
Modified: trunk/scintilla/Makefile.am =================================================================== --- trunk/scintilla/Makefile.am 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/scintilla/Makefile.am 2010-09-30 16:59:22 UTC (rev 5266) @@ -15,6 +15,7 @@ LexCmake.cxx \ LexCSS.cxx \ LexD.cxx \ +LexForth.cxx \ LexFortran.cxx \ LexHaskell.cxx \ LexHTML.cxx \
Modified: trunk/scintilla/makefile.win32 =================================================================== --- trunk/scintilla/makefile.win32 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/scintilla/makefile.win32 2010-09-30 16:59:22 UTC (rev 5266) @@ -61,7 +61,8 @@ #**LEXOBJS=\\n(*.o ) LEXOBJS=\ LexAda.o LexBash.o LexAsm.o LexCSS.o LexCPP.o LexHTML.o LexOthers.o LexPascal.o \ -LexPerl.o LexPython.o LexSQL.o LexCaml.o LexTCL.o LexTxt2tags.o LexRuby.o LexFortran.o LexVHDL.o LexVerilog.o\ +LexPerl.o LexPython.o LexSQL.o LexCaml.o LexTCL.o LexTxt2tags.o LexRuby.o \ +LexForth.o LexFortran.o LexVHDL.o LexVerilog.o \ LexMarkdown.o LexMatlab.o \ LexD.o LexLua.o LexHaskell.o LexBasic.o LexR.o LexYAML.o LexCmake.o LexNsis.o #--Autogenerated -- end of automatically generated section
Modified: trunk/src/about.c =================================================================== --- trunk/src/about.c 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/src/about.c 2010-09-30 16:59:22 UTC (rev 5266) @@ -95,7 +95,7 @@ "Jörn Reder, Kelvin Gardiner, Kevin Ellwood, Kristoffer A. Tjernås, Lex Trotman, Marko Peric, Matti Mårds, " "Moritz Barsnick, Ondrej Donek, Peter Strand, Philipp Gildein, Pierre Joye, Rob van der Linde, " "Robert McGinley, Roland Baudin, Ross McKay, S Jagannathan, Saleem Abdulrasool, " -"Sebastian Kraft, Shiv, Slava Semushin, Stefan Oltmanns, Tamim, Thomas Martitz, Tomás Vírseda, " +"Sebastian Kraft, Shiv, Slava Semushin, Stefan Oltmanns, Tamim, Thomas Huth, Thomas Martitz, Tomás Vírseda, " "Tyler Mulligan, Walery Studennikov, Yura Siamashka";
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/src/filetypes.c 2010-09-30 16:59:22 UTC (rev 5266) @@ -628,6 +628,17 @@ ft->comment_open = g_strdup("--"); ft->comment_close = NULL; ft->group = GEANY_FILETYPE_GROUP_COMPILED; + +#define FORTH + ft = filetypes[GEANY_FILETYPES_FORTH]; + ft->lang = -2; + ft->name = g_strdup("Forth"); + filetype_make_title(ft, TITLE_SOURCE_FILE); + ft->extension = g_strdup("fs"); + ft->pattern = utils_strv_new("*.fs", "*.fth", NULL); + ft->comment_open = g_strdup("\"); + ft->comment_close = NULL; + ft->group = GEANY_FILETYPE_GROUP_SCRIPT; }
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/src/filetypes.h 2010-09-30 16:59:22 UTC (rev 5266) @@ -84,6 +84,7 @@ GEANY_FILETYPES_TXT2TAGS, GEANY_FILETYPES_ABC, GEANY_FILETYPES_VERILOG, + GEANY_FILETYPES_FORTH, /* ^ append items here */ GEANY_MAX_BUILT_IN_FILETYPES /* Don't use this, use filetypes_array->len instead */ }
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/src/highlighting.c 2010-09-30 16:59:22 UTC (rev 5266) @@ -2202,6 +2202,52 @@ }
+static void styleset_forth_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) +{ + new_styleset(ft_id, 12); + + get_keyfile_style(config, config_home, "default", &style_sets[ft_id].styling[0]); + get_keyfile_style(config, config_home, "comment", &style_sets[ft_id].styling[1]); + get_keyfile_style(config, config_home, "commentml", &style_sets[ft_id].styling[2]); + get_keyfile_style(config, config_home, "identifier", &style_sets[ft_id].styling[3]); + get_keyfile_style(config, config_home, "control", &style_sets[ft_id].styling[4]); + get_keyfile_style(config, config_home, "keyword", &style_sets[ft_id].styling[5]); + get_keyfile_style(config, config_home, "defword", &style_sets[ft_id].styling[6]); + get_keyfile_style(config, config_home, "preword1", &style_sets[ft_id].styling[7]); + get_keyfile_style(config, config_home, "preword2", &style_sets[ft_id].styling[8]); + get_keyfile_style(config, config_home, "number", &style_sets[ft_id].styling[9]); + get_keyfile_style(config, config_home, "string", &style_sets[ft_id].styling[10]); + get_keyfile_style(config, config_home, "locale", &style_sets[ft_id].styling[11]); + + style_sets[ft_id].keywords = g_new(gchar*, 2); + get_keyfile_keywords(config, config_home, "primary", ft_id, 0); + style_sets[ft_id].keywords[1] = NULL; + +} + + +static void styleset_forth(ScintillaObject *sci, gint ft_id) +{ + apply_filetype_properties(sci, SCLEX_FORTH, ft_id); + + sci_set_keywords(sci, 0, style_sets[ft_id].keywords[0]); + + set_sci_style(sci, STYLE_DEFAULT, ft_id, 0); + set_sci_style(sci, SCE_FORTH_DEFAULT, ft_id, 0); + set_sci_style(sci, SCE_FORTH_COMMENT, ft_id, 1); + set_sci_style(sci, SCE_FORTH_COMMENT_ML, ft_id, 2); + set_sci_style(sci, SCE_FORTH_IDENTIFIER, ft_id, 3); + set_sci_style(sci, SCE_FORTH_CONTROL, ft_id, 4); + set_sci_style(sci, SCE_FORTH_KEYWORD, ft_id, 5); + set_sci_style(sci, SCE_FORTH_DEFWORD, ft_id, 6); + set_sci_style(sci, SCE_FORTH_PREWORD1, ft_id, 7); + set_sci_style(sci, SCE_FORTH_PREWORD2, ft_id, 8); + set_sci_style(sci, SCE_FORTH_NUMBER, ft_id, 9); + set_sci_style(sci, SCE_FORTH_STRING, ft_id, 10); + set_sci_style(sci, SCE_FORTH_LOCALE, ft_id, 11); +} + + static void styleset_fortran_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { new_styleset(ft_id, 15); @@ -3233,6 +3279,7 @@ init_styleset_case(GEANY_FILETYPES_DOCBOOK, styleset_docbook_init); init_styleset_case(GEANY_FILETYPES_FERITE, styleset_ferite_init); init_styleset_case(GEANY_FILETYPES_F77, styleset_f77_init); + init_styleset_case(GEANY_FILETYPES_FORTH, styleset_forth_init); init_styleset_case(GEANY_FILETYPES_FORTRAN, styleset_fortran_init); init_styleset_case(GEANY_FILETYPES_HASKELL, styleset_haskell_init); init_styleset_case(GEANY_FILETYPES_HAXE, styleset_haxe_init); @@ -3302,6 +3349,7 @@ styleset_case(GEANY_FILETYPES_DOCBOOK, styleset_docbook); styleset_case(GEANY_FILETYPES_FERITE, styleset_ferite); styleset_case(GEANY_FILETYPES_F77, styleset_f77); + styleset_case(GEANY_FILETYPES_FORTH, styleset_forth); styleset_case(GEANY_FILETYPES_FORTRAN, styleset_fortran); styleset_case(GEANY_FILETYPES_HASKELL, styleset_haskell); styleset_case(GEANY_FILETYPES_HAXE, styleset_haxe);
Modified: trunk/wscript =================================================================== --- trunk/wscript 2010-09-30 14:49:54 UTC (rev 5265) +++ trunk/wscript 2010-09-30 16:59:22 UTC (rev 5266) @@ -87,7 +87,7 @@ 'scintilla/KeyWords.cxx', 'scintilla/LexAda.cxx', 'scintilla/LexAsm.cxx', 'scintilla/LexBash.cxx', 'scintilla/LexBasic.cxx', 'scintilla/LexCaml.cxx', 'scintilla/LexCmake.cxx', 'scintilla/LexCPP.cxx', - 'scintilla/LexCSS.cxx', 'scintilla/LexD.cxx', + 'scintilla/LexCSS.cxx', 'scintilla/LexD.cxx', 'scintilla/LexForth.cxx', 'scintilla/LexFortran.cxx', 'scintilla/LexHaskell.cxx', 'scintilla/LexHTML.cxx', 'scintilla/LexLua.cxx', 'scintilla/LexMarkdown.cxx', 'scintilla/LexMatlab.cxx', 'scintilla/LexNsis.cxx', 'scintilla/LexOthers.cxx',
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.