Revision: 3190 http://geany.svn.sourceforge.net/geany/?rev=3190&view=rev Author: eht16 Date: 2008-11-07 14:39:45 +0000 (Fri, 07 Nov 2008)
Log Message: ----------- Add new filetype 'Matlab' (closes #1938631, patch by Roland Baudin, thanks).
Modified Paths: -------------- trunk/THANKS trunk/data/filetype_extensions.conf trunk/scintilla/KeyWords.cxx trunk/scintilla/Makefile.am trunk/scintilla/makefile.win32 trunk/src/editor.c trunk/src/filetypes.c trunk/src/filetypes.h trunk/src/highlighting.c trunk/src/plugindata.h trunk/src/symbols.c trunk/src/templates.c trunk/tagmanager/Makefile.am trunk/tagmanager/makefile.win32 trunk/tagmanager/parsers.h trunk/wscript
Added Paths: ----------- trunk/data/filetypes.matlab trunk/scintilla/LexMatlab.cxx trunk/tagmanager/matlab.c
Modified: trunk/THANKS =================================================================== --- trunk/THANKS 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/THANKS 2008-11-07 14:39:45 UTC (rev 3190) @@ -50,6 +50,7 @@ Jason Oster <parasytic(at)users(dot)sourceforge(dot)net> - various patches Andrew Rowland <weibullguy(at)charter(dot)net> - R filetype patch Bronisław Białek <after89(at)gmail(dot)com> - CSS parser update +Roland Baudin <roland(dot)baudin(at)thalesaleniaspace(dot)com> - Matlab filetype patch
Translators: ------------
Modified: trunk/data/filetype_extensions.conf =================================================================== --- trunk/data/filetype_extensions.conf 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/data/filetype_extensions.conf 2008-11-07 14:39:45 UTC (rev 3190) @@ -23,6 +23,7 @@ Javascript=*.js; Lua=*.lua; Make=*.mak;*.mk;GNUmakefile;makefile;Makefile;makefile.*;Makefile.*; +Matlab=*.m; O-Matrix=*.oms; Perl=*.pl;*.perl;*.pm;*.agi;*.pod; PHP=*.php;*.php3;*.php4;*.php5;*.phtml;
Added: trunk/data/filetypes.matlab =================================================================== --- trunk/data/filetypes.matlab (rev 0) +++ trunk/data/filetypes.matlab 2008-11-07 14:39:45 UTC (rev 3190) @@ -0,0 +1,38 @@ +# For complete documentation of this file, please see Geany's main documentation +[styling] +# foreground;background;bold;italic +default=0x000000;0xffffff;false;false +comment=0x808080;0xffffff;false;false +command=0x111199;0xffffff;true;false +number=0x007f00;0xffffff;false;false +keyword=0x001a7f;0xffffff;true;false +string=0xff901e;0xffffff;false;false +operator=0x301010;0xffffff;false;false +identifier=0x000000;0xffffff;false;false +doublequotedstring=0xff901e;0xffffff;false;false + +[keywords] +# all items must be in one line +primary=break case catch continue else elseif end for function global if otherwise persistent return switch try while + +[settings] +# default extension used when saving files +#extension=m + +# 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= + +# 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=
Modified: trunk/scintilla/KeyWords.cxx =================================================================== --- trunk/scintilla/KeyWords.cxx 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/scintilla/KeyWords.cxx 2008-11-07 14:39:45 UTC (rev 3190) @@ -160,6 +160,7 @@ LINK_LEXER(lmLatex); LINK_LEXER(lmLua); LINK_LEXER(lmMake); + LINK_LEXER(lmMatlab); LINK_LEXER(lmNncrontab); LINK_LEXER(lmNull); LINK_LEXER(lmOMS);
Added: trunk/scintilla/LexMatlab.cxx =================================================================== --- trunk/scintilla/LexMatlab.cxx (rev 0) +++ trunk/scintilla/LexMatlab.cxx 2008-11-07 14:39:45 UTC (rev 3190) @@ -0,0 +1,236 @@ +// Scintilla source code edit control +/** @file LexMatlab.cxx + ** Lexer for Matlab. + ** Written by Jos\xE9 Fonseca + ** + ** Changes by Christoph Dalitz 2003/12/04: + ** - added support for Octave + ** - Strings can now be included both in single or double quotes + **/ +// Copyright 1998-2001 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 bool IsMatlabCommentChar(int c) { + return (c == '%') ; +} + +static bool IsOctaveCommentChar(int c) { + return (c == '%' || c == '#') ; +} + +static bool IsMatlabComment(Accessor &styler, int pos, int len) { + return len > 0 && IsMatlabCommentChar(styler[pos]) ; +} + +static bool IsOctaveComment(Accessor &styler, int pos, int len) { + return len > 0 && IsOctaveCommentChar(styler[pos]) ; +} + +static inline bool IsAWordChar(const int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '_'); +} + +static inline bool IsAWordStart(const int ch) { + return (ch < 0x80) && (isalnum(ch) || ch == '_'); +} + +static void ColouriseMatlabOctaveDoc( + unsigned int startPos, int length, int initStyle, + WordList *keywordlists[], Accessor &styler, + bool (*IsCommentChar)(int)) { + + WordList &keywords = *keywordlists[0]; + + styler.StartAt(startPos); + + bool transpose = false; + + StyleContext sc(startPos, length, initStyle, styler); + + for (; sc.More(); sc.Forward()) { + + if (sc.state == SCE_MATLAB_OPERATOR) { + if (sc.chPrev == '.') { + if (sc.ch == '*' || sc.ch == '/' || sc.ch == '\' || sc.ch == '^') { + sc.ForwardSetState(SCE_MATLAB_DEFAULT); + transpose = false; + } else if (sc.ch == ''') { + sc.ForwardSetState(SCE_MATLAB_DEFAULT); + transpose = true; + } else { + sc.SetState(SCE_MATLAB_DEFAULT); + } + } else { + sc.SetState(SCE_MATLAB_DEFAULT); + } + } else if (sc.state == SCE_MATLAB_KEYWORD) { + if (!isalnum(sc.ch) && sc.ch != '_') { + char s[100]; + sc.GetCurrentLowered(s, sizeof(s)); + if (keywords.InList(s)) { + sc.SetState(SCE_MATLAB_DEFAULT); + transpose = false; + } else { + sc.ChangeState(SCE_MATLAB_IDENTIFIER); + sc.SetState(SCE_MATLAB_DEFAULT); + transpose = true; + } + } + } else if (sc.state == SCE_MATLAB_NUMBER) { + if (!isdigit(sc.ch) && sc.ch != '.' + && !(sc.ch == 'e' || sc.ch == 'E') + && !((sc.ch == '+' || sc.ch == '-') && (sc.chPrev == 'e' || sc.chPrev == 'E'))) { + sc.SetState(SCE_MATLAB_DEFAULT); + transpose = true; + } + } else if (sc.state == SCE_MATLAB_STRING) { + if (sc.ch == '\') { + if (sc.chNext == '"' || sc.chNext == ''' || sc.chNext == '\') { + sc.Forward(); + } + } else if (sc.ch == ''') { + sc.ForwardSetState(SCE_MATLAB_DEFAULT); + } + } else if (sc.state == SCE_MATLAB_DOUBLEQUOTESTRING) { + if (sc.ch == '\') { + if (sc.chNext == '"' || sc.chNext == ''' || sc.chNext == '\') { + sc.Forward(); + } + } else if (sc.ch == '"') { + sc.ForwardSetState(SCE_MATLAB_DEFAULT); + } + } else if (sc.state == SCE_MATLAB_COMMENT || sc.state == SCE_MATLAB_COMMAND) { + if (sc.atLineEnd) { + sc.SetState(SCE_MATLAB_DEFAULT); + transpose = false; + } + } + + if (sc.state == SCE_MATLAB_DEFAULT) { + if (IsCommentChar(sc.ch)) { + sc.SetState(SCE_MATLAB_COMMENT); + } else if (sc.ch == '!' && sc.chNext != '=' ) { + sc.SetState(SCE_MATLAB_COMMAND); + } else if (sc.ch == ''') { + if (transpose) { + sc.SetState(SCE_MATLAB_OPERATOR); + } else { + sc.SetState(SCE_MATLAB_STRING); + } + } else if (sc.ch == '"') { + sc.SetState(SCE_MATLAB_DOUBLEQUOTESTRING); + } else if (isdigit(sc.ch) || (sc.ch == '.' && isdigit(sc.chNext))) { + sc.SetState(SCE_MATLAB_NUMBER); + } else if (isalpha(sc.ch)) { + sc.SetState(SCE_MATLAB_KEYWORD); + } else if (isoperator(static_cast<char>(sc.ch)) || sc.ch == '@' || sc.ch == '\') { + if (sc.ch == ')' || sc.ch == ']') { + transpose = true; + } else { + transpose = false; + } + sc.SetState(SCE_MATLAB_OPERATOR); + } else { + transpose = false; + } + } + } + sc.Complete(); +} + +static void ColouriseMatlabDoc(unsigned int startPos, int length, int initStyle, + WordList *keywordlists[], Accessor &styler) { + ColouriseMatlabOctaveDoc(startPos, length, initStyle, keywordlists, styler, IsMatlabCommentChar); +} + +static void ColouriseOctaveDoc(unsigned int startPos, int length, int initStyle, + WordList *keywordlists[], Accessor &styler) { + ColouriseMatlabOctaveDoc(startPos, length, initStyle, keywordlists, styler, IsOctaveCommentChar); +} + +static void FoldMatlabOctaveDoc(unsigned int startPos, int length, int, + WordList *[], Accessor &styler, + bool (*IsComment)(Accessor&, int, int)) { + + int endPos = startPos + length; + + // Backtrack to previous line in case need to fix its fold status + int lineCurrent = styler.GetLine(startPos); + if (startPos > 0) { + if (lineCurrent > 0) { + lineCurrent--; + startPos = styler.LineStart(lineCurrent); + } + } + int spaceFlags = 0; + int indentCurrent = styler.IndentAmount(lineCurrent, &spaceFlags, IsComment); + char chNext = styler[startPos]; + for (int i = startPos; i < endPos; i++) { + char ch = chNext; + chNext = styler.SafeGetCharAt(i + 1); + + if ((ch == '\r' && chNext != '\n') || (ch == '\n') || (i == endPos)) { + int lev = indentCurrent; + int indentNext = styler.IndentAmount(lineCurrent + 1, &spaceFlags, IsComment); + if (!(indentCurrent & SC_FOLDLEVELWHITEFLAG)) { + // Only non whitespace lines can be headers + if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext & SC_FOLDLEVELNUMBERMASK)) { + lev |= SC_FOLDLEVELHEADERFLAG; + } else if (indentNext & SC_FOLDLEVELWHITEFLAG) { + // Line after is blank so check the next - maybe should continue further? + int spaceFlags2 = 0; + int indentNext2 = styler.IndentAmount(lineCurrent + 2, &spaceFlags2, IsComment); + if ((indentCurrent & SC_FOLDLEVELNUMBERMASK) < (indentNext2 & SC_FOLDLEVELNUMBERMASK)) { + lev |= SC_FOLDLEVELHEADERFLAG; + } + } + } + indentCurrent = indentNext; + styler.SetLevel(lineCurrent, lev); + lineCurrent++; + } + } +} + +static void FoldMatlabDoc(unsigned int startPos, int length, int initStyle, + WordList *keywordlists[], Accessor &styler) { + FoldMatlabOctaveDoc(startPos, length, initStyle, keywordlists, styler, IsMatlabComment); +} + +static void FoldOctaveDoc(unsigned int startPos, int length, int initStyle, + WordList *keywordlists[], Accessor &styler) { + FoldMatlabOctaveDoc(startPos, length, initStyle, keywordlists, styler, IsOctaveComment); +} + +static const char * const matlabWordListDesc[] = { + "Keywords", + 0 +}; + +static const char * const octaveWordListDesc[] = { + "Keywords", + 0 +}; + +LexerModule lmMatlab(SCLEX_MATLAB, ColouriseMatlabDoc, "matlab", FoldMatlabDoc, matlabWordListDesc); + +LexerModule lmOctave(SCLEX_OCTAVE, ColouriseOctaveDoc, "octave", FoldOctaveDoc, octaveWordListDesc);
Modified: trunk/scintilla/Makefile.am =================================================================== --- trunk/scintilla/Makefile.am 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/scintilla/Makefile.am 2008-11-07 14:39:45 UTC (rev 3190) @@ -19,6 +19,7 @@ LexHTML.cxx \ LexLua.cxx \ LexOMS.cxx \ +LexMatlab.cxx \ LexOthers.cxx \ LexPascal.cxx \ LexPerl.cxx \
Modified: trunk/scintilla/makefile.win32 =================================================================== --- trunk/scintilla/makefile.win32 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/scintilla/makefile.win32 2008-11-07 14:39:45 UTC (rev 3190) @@ -61,7 +61,7 @@ #**LEXOBJS=\\n(*.o ) LEXOBJS=\ LexBash.o LexAsm.o LexCSS.o LexCPP.o LexCrontab.o LexHTML.o LexOthers.o LexPascal.o \ -LexPerl.o LexPython.o LexSQL.o LexCaml.o LexOMS.o LexTCL.o LexRuby.o LexFortran.o LexVHDL.o \ +LexPerl.o LexPython.o LexSQL.o LexCaml.o LexOMS.o LexTCL.o LexRuby.o LexFortran.o LexVHDL.o LexMatlab.o \ LexD.o LexLua.o LexHaskell.o LexBasic.o LexR.o #--Autogenerated -- end of automatically generated section
Modified: trunk/src/editor.c =================================================================== --- trunk/src/editor.c 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/src/editor.c 2008-11-07 14:39:45 UTC (rev 3190) @@ -2763,6 +2763,10 @@ case SCLEX_FREEBASIC: return (style == SCE_B_STRING);
+ case SCLEX_MATLAB: + return (style == SCE_MATLAB_STRING || + style == SCE_MATLAB_DOUBLEQUOTESTRING); + case SCLEX_HTML: return (style == SCE_HPHP_SIMPLESTRING || style == SCE_HPHP_HSTRING || /* HSTRING is a heredoc */ @@ -2846,6 +2850,9 @@ style == SCE_TCL_COMMENT_BOX || style == SCE_TCL_BLOCK_COMMENT);
+ case SCLEX_MATLAB: + return (style == SCE_MATLAB_COMMENT); + case SCLEX_LUA: return (style == SCE_LUA_COMMENT || style == SCE_LUA_COMMENTLINE || @@ -4095,6 +4102,7 @@ case SCLEX_FREEBASIC: case SCLEX_D: case SCLEX_OMS: + case SCLEX_MATLAB: mode = SC_IV_LOOKBOTH; break;
Modified: trunk/src/filetypes.c =================================================================== --- trunk/src/filetypes.c 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/src/filetypes.c 2008-11-07 14:39:45 UTC (rev 3190) @@ -495,6 +495,17 @@ ft->comment_close = NULL; ft->group = GEANY_FILETYPE_GROUP_MISC;
+#define MATLAB + ft = filetypes[GEANY_FILETYPES_MATLAB]; + ft->lang = 32; + ft->name = g_strdup("Matlab"); + ft->title = g_strdup_printf(_("%s source file"), "Matlab"); + ft->extension = g_strdup("m"); + ft->pattern = utils_strv_new("*.m", NULL); + ft->comment_open = g_strdup("%"); + ft->comment_close = NULL; + ft->group = GEANY_FILETYPE_GROUP_SCRIPT; + #define ALL ft = filetypes[GEANY_FILETYPES_NONE]; ft->lang = -2;
Modified: trunk/src/filetypes.h =================================================================== --- trunk/src/filetypes.h 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/src/filetypes.h 2008-11-07 14:39:45 UTC (rev 3190) @@ -57,6 +57,7 @@ GEANY_FILETYPES_JS, GEANY_FILETYPES_LUA, GEANY_FILETYPES_MAKE, + GEANY_FILETYPES_MATLAB, GEANY_FILETYPES_OMS, GEANY_FILETYPES_PERL, GEANY_FILETYPES_PHP,
Modified: trunk/src/highlighting.c =================================================================== --- trunk/src/highlighting.c 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/src/highlighting.c 2008-11-07 14:39:45 UTC (rev 3190) @@ -2579,6 +2579,52 @@ set_sci_style(sci, SCE_TCL_WORD5, GEANY_FILETYPES_TCL, 15); }
+ +static void styleset_matlab_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) +{ + new_style_array(GEANY_FILETYPES_MATLAB, 9); + get_keyfile_hex(config, config_home, "styling", "default", "0x000000", "0xffffff", "false", &style_sets[GEANY_FILETYPES_MATLAB].styling[0]); + get_keyfile_hex(config, config_home, "styling", "comment", "0x808080", "0xffffff", "false", &style_sets[GEANY_FILETYPES_MATLAB].styling[1]); + get_keyfile_hex(config, config_home, "styling", "command", "0x111199", "0xffffff", "true", &style_sets[GEANY_FILETYPES_MATLAB].styling[2]); + get_keyfile_hex(config, config_home, "styling", "number", "0x007f00", "0xffffff", "false", &style_sets[GEANY_FILETYPES_MATLAB].styling[3]); + get_keyfile_hex(config, config_home, "styling", "keyword", "0x001a7f", "0xffffff", "true", &style_sets[GEANY_FILETYPES_MATLAB].styling[4]); + get_keyfile_hex(config, config_home, "styling", "string", "0xff901e", "0xffffff", "false", &style_sets[GEANY_FILETYPES_MATLAB].styling[5]); + get_keyfile_hex(config, config_home, "styling", "operator", "0x301010", "0xffffff", "false", &style_sets[GEANY_FILETYPES_MATLAB].styling[6]); + get_keyfile_hex(config, config_home, "styling", "identifier", "0x000000", "0xffffff", "false", &style_sets[GEANY_FILETYPES_MATLAB].styling[7]); + get_keyfile_hex(config, config_home, "styling", "doublequotedstring", "0xff901e", "0xffffff", "false", &style_sets[GEANY_FILETYPES_MATLAB].styling[8]); + + style_sets[GEANY_FILETYPES_MATLAB].keywords = g_new(gchar*, 2); + get_keyfile_keywords(config, config_home, "keywords", "primary", GEANY_FILETYPES_MATLAB, 0, "break case catch continue else elseif end for function global if otherwise persistent return switch try while"); + style_sets[GEANY_FILETYPES_MATLAB].keywords[1] = NULL; + + get_keyfile_wordchars(config, config_home, + &style_sets[GEANY_FILETYPES_MATLAB].wordchars); +} + + +static void styleset_matlab(ScintillaObject *sci) +{ + const filetype_id ft_id = GEANY_FILETYPES_MATLAB; + + styleset_common(sci); + + apply_filetype_properties(sci, SCLEX_MATLAB, ft_id); + + SSM(sci, SCI_SETKEYWORDS, 0, (sptr_t) style_sets[GEANY_FILETYPES_MATLAB].keywords[0]); + + set_sci_style(sci, STYLE_DEFAULT, GEANY_FILETYPES_MATLAB, 0); + set_sci_style(sci, SCE_MATLAB_DEFAULT, GEANY_FILETYPES_MATLAB, 0); + set_sci_style(sci, SCE_MATLAB_COMMENT, GEANY_FILETYPES_MATLAB, 1); + set_sci_style(sci, SCE_MATLAB_COMMAND, GEANY_FILETYPES_MATLAB, 2); + set_sci_style(sci, SCE_MATLAB_NUMBER, GEANY_FILETYPES_MATLAB, 3); + set_sci_style(sci, SCE_MATLAB_KEYWORD, GEANY_FILETYPES_MATLAB, 4); + set_sci_style(sci, SCE_MATLAB_STRING, GEANY_FILETYPES_MATLAB, 5); + set_sci_style(sci, SCE_MATLAB_OPERATOR, GEANY_FILETYPES_MATLAB, 6); + set_sci_style(sci, SCE_MATLAB_IDENTIFIER, GEANY_FILETYPES_MATLAB, 7); + set_sci_style(sci, SCE_MATLAB_DOUBLEQUOTESTRING, GEANY_FILETYPES_MATLAB, 8); +} + + static void styleset_d_init(gint ft_id, GKeyFile *config, GKeyFile *config_home) { new_style_array(GEANY_FILETYPES_D, 18); @@ -3087,6 +3133,7 @@ init_styleset_case(GEANY_FILETYPES_LATEX, latex); init_styleset_case(GEANY_FILETYPES_LUA, lua); init_styleset_case(GEANY_FILETYPES_MAKE, makefile); + init_styleset_case(GEANY_FILETYPES_MATLAB, matlab); init_styleset_case(GEANY_FILETYPES_OMS, oms); init_styleset_case(GEANY_FILETYPES_PASCAL, pascal); init_styleset_case(GEANY_FILETYPES_PERL, perl); @@ -3143,6 +3190,7 @@ styleset_case(GEANY_FILETYPES_LATEX, latex); styleset_case(GEANY_FILETYPES_LUA, lua); styleset_case(GEANY_FILETYPES_MAKE, makefile); + styleset_case(GEANY_FILETYPES_MATLAB, matlab); styleset_case(GEANY_FILETYPES_OMS, oms); styleset_case(GEANY_FILETYPES_PASCAL, pascal); styleset_case(GEANY_FILETYPES_PERL, perl);
Modified: trunk/src/plugindata.h =================================================================== --- trunk/src/plugindata.h 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/src/plugindata.h 2008-11-07 14:39:45 UTC (rev 3190) @@ -41,13 +41,13 @@ enum { /** The Application Programming Interface (API) version, incremented * whenever any plugin data types are modified or appended to. */ - GEANY_API_VERSION = 104, + GEANY_API_VERSION = 105,
/** The Application Binary Interface (ABI) version, incremented whenever * existing fields in the plugin data types have to be changed or reordered. */ /* This should usually stay the same if fields are only appended, assuming only pointers to * structs and not structs themselves are declared by plugins. */ - GEANY_ABI_VERSION = 47 + GEANY_ABI_VERSION = 48 };
/** Check the plugin can be loaded by Geany.
Modified: trunk/src/symbols.c =================================================================== --- trunk/src/symbols.c 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/src/symbols.c 2008-11-07 14:39:45 UTC (rev 3190) @@ -623,6 +623,14 @@ NULL); break; } + case GEANY_FILETYPES_MATLAB: + { + tag_list_add_groups(tag_store, + &(tv_iters.tag_function), _("Functions"), "classviewer-method", + &(tv_iters.tag_struct), _("Structures"), "classviewer-struct", + NULL); + break; + } case GEANY_FILETYPES_PERL: { tag_list_add_groups(tag_store,
Modified: trunk/src/templates.c =================================================================== --- trunk/src/templates.c 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/src/templates.c 2008-11-07 14:39:45 UTC (rev 3190) @@ -548,6 +548,7 @@ }
case GEANY_FILETYPES_LATEX: + case GEANY_FILETYPES_MATLAB: { line_prefix = "%"; break;
Modified: trunk/tagmanager/Makefile.am =================================================================== --- trunk/tagmanager/Makefile.am 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/tagmanager/Makefile.am 2008-11-07 14:39:45 UTC (rev 3190) @@ -49,6 +49,7 @@ asm.c\ latex.c\ lregex.c\ + matlab.c\ pascal.c\ perl.c\ rest.c\
Modified: trunk/tagmanager/makefile.win32 =================================================================== --- trunk/tagmanager/makefile.win32 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/tagmanager/makefile.win32 2008-11-07 14:39:45 UTC (rev 3190) @@ -41,7 +41,7 @@
$(COMPLIB): args.o c.o fortran.o make.o conf.o pascal.o perl.o php.o diff.o vhdl.o lua.o js.o \ haskell.o haxe.o html.o python.o lregex.o rest.o sh.o ctags.o entry.o get.o keyword.o options.o \ -parse.o basic.o read.o sort.o strlist.o latex.o docbook.o tcl.o ruby.o asm.o sql.o css.o \ +parse.o basic.o read.o sort.o strlist.o latex.o matlab.o docbook.o tcl.o ruby.o asm.o sql.o css.o \ vstring.o regex.o tm_workspace.o tm_work_object.o tm_source_file.o tm_project.o tm_tag.o \ tm_symbol.o tm_file_entry.o tm_tagmanager.o $(AR) rc $@ $^
Added: trunk/tagmanager/matlab.c =================================================================== --- trunk/tagmanager/matlab.c (rev 0) +++ trunk/tagmanager/matlab.c 2008-11-07 14:39:45 UTC (rev 3190) @@ -0,0 +1,150 @@ +/* +* +* Copyright (c) 2000-2001, Darren Hiebert +* +* This source code is released for free distribution under the terms of the +* GNU General Public License. +* +* This module contains functions for generating tags for Matlab scripts. +* The tags 'function' and 'struct' are parsed. +* Author Roland Baudin roland65@free.fr +*/ + +/* +* INCLUDE FILES +*/ +#include "general.h" /* must always come first */ + +#include <string.h> + +#include "parse.h" +#include "read.h" +#include "vstring.h" + +/* +* DATA DEFINITIONS +*/ +typedef enum { + K_FUNCTION, + K_STRUCT +} MatlabKind; + +static kindOption MatlabKinds [] = { + { TRUE, 'f', "function", "Functions" }, + { TRUE, 's', "struct", "Structures" }, +}; + +/* +* FUNCTION DEFINITIONS +*/ + +static void findMatlabTags (void) +{ + vString *name = vStringNew (); + const unsigned char *line; + const unsigned char *p; + + while ((line = fileReadLine ()) != NULL) + { + int i, ic; + + if (line [0] == '\0' || line [0] == '%') + continue; + + /* search if the line has a comment */ + for (ic = 0 ; line [ic] != '\0' && line [ic]!='%' ; ++ic) + ; + + /* function tag */ + + /* read first word */ + for (i = 0 ; line [i] != '\0' && ! isspace (line [i]) ; ++i) + ; + + if (strncmp ((const char *) line, "function", (size_t) 8) == 0) + { + const unsigned char *cp = line + i; + const unsigned char *ptr = cp; + boolean eq=FALSE; + + while (isspace ((int) *cp)) + ++cp; + + /* search for '=' character in the line */ + while (*ptr != '\0') + { + if (*ptr == '=') + { + eq=TRUE; + break; + } + ptr++; + } + + /* '=' was found => get the right most part of the line after '=' and before '%' */ + if (eq) + { + ptr++; + while (isspace ((int) *ptr)) + ++ptr; + + while (*ptr != '\0' && *ptr != '%') + { + vStringPut (name, (int) *ptr); + ++ptr; + } + } + + /* '=' was not found => get the right most part of the line after + * 'function' and before '%' */ + else + { + while (*cp != '\0' && *cp != '%') + { + vStringPut (name, (int) *cp); + ++cp; + } + } + + vStringTerminate (name); + makeSimpleTag (name, MatlabKinds, K_FUNCTION); + vStringClear (name); + } + + /* struct tag */ + + /* search if the line contains the keyword 'struct' */ + p=(const unsigned char*) strstr ((const char*) line, "struct"); + + /* and avoid the part after the '%' if any */ + if ( p != NULL && ic>0 && p < line+ic) + { + const unsigned char *cp = line; + + /* get the left most part of the line before '=' */ + while (*cp != '\0' && !isspace(*cp) && *cp != '=' ) + { + vStringPut (name, (int) *cp); + ++cp; + } + + vStringTerminate (name); + makeSimpleTag (name, MatlabKinds, K_STRUCT); + vStringClear (name); + } + } + vStringDelete (name); +} + +extern parserDefinition* MatlabParser (void) +{ + static const char *const extensions [] = { "m", NULL }; + parserDefinition* def = parserNew ("Matlab"); + def->kinds = MatlabKinds; + def->kindCount = KIND_COUNT (MatlabKinds); + def->extensions = extensions; + def->parser = findMatlabTags; + return def; +} + +/* vi:set tabstop=8 shiftwidth=4: */
Property changes on: trunk/tagmanager/matlab.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native
Modified: trunk/tagmanager/parsers.h =================================================================== --- trunk/tagmanager/parsers.h 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/tagmanager/parsers.h 2008-11-07 14:39:45 UTC (rev 3190) @@ -46,7 +46,8 @@ RestParser, \ HtmlParser, \ F77Parser, \ - GLSLParser + GLSLParser, \ + MatlabParser
/* langType of each parser @@ -82,6 +83,7 @@ 29 HtmlParser 30 F77Parser 31 GLSLParser +32 MatlabParser */ #endif /* _PARSERS_H */
Modified: trunk/wscript =================================================================== --- trunk/wscript 2008-11-07 14:38:51 UTC (rev 3189) +++ trunk/wscript 2008-11-07 14:39:45 UTC (rev 3190) @@ -56,7 +56,8 @@ 'tagmanager/docbook.c', 'tagmanager/entry.c', 'tagmanager/fortran.c', 'tagmanager/get.c', 'tagmanager/haskell.c', 'tagmanager/haxe.c', 'tagmanager/html.c', 'tagmanager/js.c', 'tagmanager/keyword.c', 'tagmanager/latex.c', 'tagmanager/lregex.c', 'tagmanager/lua.c', - 'tagmanager/make.c', 'tagmanager/options.c', 'tagmanager/parse.c', 'tagmanager/pascal.c', + 'tagmanager/make.c', 'tagmanager/matlab.c', 'tagmanager/options.c', 'tagmanager/parse.c', + 'tagmanager/pascal.c', 'tagmanager/perl.c', 'tagmanager/php.c', 'tagmanager/python.c', 'tagmanager/read.c', 'tagmanager/rest.c', 'tagmanager/ruby.c', 'tagmanager/sh.c', 'tagmanager/sort.c', 'tagmanager/sql.c', 'tagmanager/strlist.c', 'tagmanager/tcl.c', 'tagmanager/tm_file_entry.c', @@ -75,7 +76,7 @@ 'scintilla/LexFortran.cxx', 'scintilla/LexHaskell.cxx', 'scintilla/LexHTML.cxx', 'scintilla/LexLua.cxx', 'scintilla/LexOMS.cxx', 'scintilla/LexOthers.cxx', 'scintilla/LexPascal.cxx', 'scintilla/LexPerl.cxx', 'scintilla/LexPython.cxx', - 'scintilla/LexR.cxx', + 'scintilla/LexR.cxx', 'scintilla/LexMatlab.cxx', 'scintilla/LexRuby.cxx', 'scintilla/LexSQL.cxx', 'scintilla/LexTCL.cxx', 'scintilla/LexVHDL.cxx', 'scintilla/LineMarker.cxx', 'scintilla/PlatGTK.cxx', 'scintilla/PositionCache.cxx', 'scintilla/PropSet.cxx', 'scintilla/RESearch.cxx',
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.