[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [53837] trunk/blender/source/blender/ editors/space_text: patch [#33888] Syntax Highlighting Changes

Campbell Barton ideasman42 at gmail.com
Wed Jan 16 04:43:13 CET 2013


Revision: 53837
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=53837
Author:   campbellbarton
Date:     2013-01-16 03:43:09 +0000 (Wed, 16 Jan 2013)
Log Message:
-----------
patch [#33888] Syntax Highlighting Changes
from Benjamin Tolputt (btolputt), (with minor changes)

adds support for LUA syntax highlighting.

Modified Paths:
--------------
    trunk/blender/source/blender/editors/space_text/CMakeLists.txt
    trunk/blender/source/blender/editors/space_text/space_text.c
    trunk/blender/source/blender/editors/space_text/text_format.c
    trunk/blender/source/blender/editors/space_text/text_format.h

Added Paths:
-----------
    trunk/blender/source/blender/editors/space_text/text_format_lua.c

Modified: trunk/blender/source/blender/editors/space_text/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/editors/space_text/CMakeLists.txt	2013-01-16 03:30:40 UTC (rev 53836)
+++ trunk/blender/source/blender/editors/space_text/CMakeLists.txt	2013-01-16 03:43:09 UTC (rev 53837)
@@ -39,6 +39,7 @@
 	text_autocomplete.c
 	text_draw.c
 	text_format.c
+	text_format_lua.c
 	text_format_osl.c
 	text_format_py.c
 	text_header.c

Modified: trunk/blender/source/blender/editors/space_text/space_text.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/space_text.c	2013-01-16 03:30:40 UTC (rev 53836)
+++ trunk/blender/source/blender/editors/space_text/space_text.c	2013-01-16 03:43:09 UTC (rev 53837)
@@ -571,5 +571,6 @@
 	/* register formatters */
 	ED_text_format_register_py();
 	ED_text_format_register_osl();
+	ED_text_format_register_lua();
 }
 

Modified: trunk/blender/source/blender/editors/space_text/text_format.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format.c	2013-01-16 03:30:40 UTC (rev 53836)
+++ trunk/blender/source/blender/editors/space_text/text_format.c	2013-01-16 03:43:09 UTC (rev 53837)
@@ -178,14 +178,31 @@
 
 TextFormatType *ED_text_format_get(Text *text)
 {
-	/* NOTE: once more types are added we'll need to return some type based on 'text'
-	 * for now this function is more of a placeholder */
+	TextFormatType* tft;
 
-	/* XXX, wrong, but OK for testing */
-	if (text && BLI_testextensie(text->id.name + 2, ".osl")) {
-		return tft_lb.last;
+	if (text) {
+		const char *text_ext = strchr(text->id.name + 2, '.');
+		if (text_ext) {
+			text_ext++;  /* skip the '.' */
+			/* Check all text formats in the static list */
+			for (tft = tft_lb.first; tft; tft = tft->next) {
+				/* All formats should have an ext, but just in case */
+				const char **ext;
+				for (ext = tft->ext; *ext; ext++) {
+					/* If extension matches text name, return the matching tft */
+					if (BLI_strcasecmp(text_ext, *ext) == 0) {
+						return tft;
+					}
+				}
+			}
+		}
+
+		/* If we make it here we never found an extension that worked - return 
+		 * the "default" text format */
+		return tft_lb.first;
 	}
 	else {
+		/* Return the "default" text format */
 		return tft_lb.first;
 	}
 }

Modified: trunk/blender/source/blender/editors/space_text/text_format.h
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format.h	2013-01-16 03:30:40 UTC (rev 53836)
+++ trunk/blender/source/blender/editors/space_text/text_format.h	2013-01-16 03:43:09 UTC (rev 53837)
@@ -100,6 +100,7 @@
 /* formatters */
 void ED_text_format_register_py(void);
 void ED_text_format_register_osl(void);
+void ED_text_format_register_lua(void);
 
 #define STR_LITERAL_STARTSWITH(str, str_literal, len_var) \
 	(strncmp(str, str_literal, len_var = (sizeof(str_literal) - 1)) == 0)

Added: trunk/blender/source/blender/editors/space_text/text_format_lua.c
===================================================================
--- trunk/blender/source/blender/editors/space_text/text_format_lua.c	                        (rev 0)
+++ trunk/blender/source/blender/editors/space_text/text_format_lua.c	2013-01-16 03:43:09 UTC (rev 53837)
@@ -0,0 +1,318 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_text/text_format_lua.c
+ *  \ingroup sptext
+ */
+
+#include <string.h>
+
+#include "BLI_blenlib.h"
+
+#include "DNA_text_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_text.h"
+
+#include "text_format.h"
+
+/* *** Lua Keywords (for format_line) *** */
+
+/* Checks the specified source string for a Lua keyword (minus boolean & 'nil'). 
+ * This name must start at the beginning of the source string and must be 
+ * followed by a non-identifier (see text_check_identifier(char)) or null char.
+ *
+ * If a keyword is found, the length of the matching word is returned.
+ * Otherwise, -1 is returned.
+ *
+ * See:
+ * http://www.lua.org/manual/5.1/manual.html#2.1
+ */
+
+static int txtfmt_lua_find_keyword(const char *string)
+{
+	int i, len;
+
+	if      (STR_LITERAL_STARTSWITH(string, "and",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "break",    len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "do",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "else",     len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "elseif",   len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "end",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "for",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "function", len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "if",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "in",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "local",    len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "not",      len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "or",       len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "repeat",   len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "return",   len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "then",     len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "until",    len)) i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "while",    len)) i = len;
+	else                                                      i = 0;
+
+	/* If next source char is an identifier (eg. 'i' in "definate") no match */
+	if (i == 0 || text_check_identifier(string[i]))
+		return -1;
+	return i;
+}
+
+/* Checks the specified source string for a Lua special name/function. This 
+ * name must start at the beginning of the source string and must be followed 
+ * by a non-identifier (see text_check_identifier(char)) or null character.
+ *
+ * If a special name is found, the length of the matching name is returned.
+ * Otherwise, -1 is returned. 
+ * 
+ * See:
+ * http://www.lua.org/manual/5.1/manual.html#5.1
+ */
+
+static int txtfmt_lua_find_specialvar(const char *string)
+{
+	int i, len;
+
+	if      (STR_LITERAL_STARTSWITH(string, "assert",           len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "collectgarbage",   len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "dofile",           len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "error",            len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "_G",               len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "getfenv",          len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "getmetatable",     len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "__index",          len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "ipairs",           len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "load",             len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "loadfile",         len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "loadstring",       len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "next",             len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "pairs",            len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "pcall",            len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "print",            len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "rawequal",         len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "rawget",           len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "rawset",           len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "select",           len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "setfenv",          len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "setmetatable",     len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "tonumber",         len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "tostring",         len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "type",             len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "unpack",           len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "_VERSION",         len))   i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "xpcall",           len))   i = len;
+	else                                                i = 0;
+
+	/* If next source char is an identifier (eg. 'i' in "definate") no match */
+	if (i == 0 || text_check_identifier(string[i]))
+		return -1;
+	return i;
+}
+
+static int txtfmt_lua_find_bool(const char *string)
+{
+	int i, len;
+
+	if      (STR_LITERAL_STARTSWITH(string, "nil",   len))  i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "true",  len))  i = len;
+	else if (STR_LITERAL_STARTSWITH(string, "false", len))  i = len;
+	else                                                    i = 0;
+
+	/* If next source char is an identifier (eg. 'i' in "Nonetheless") no match */
+	if (i == 0 || text_check_identifier(string[i]))
+		return -1;
+	return i;
+}
+
+static char txtfmt_lua_format_identifier(const char *str)
+{
+	char fmt;
+	if      ((txtfmt_lua_find_specialvar(str))  != -1) fmt = FMT_TYPE_SPECIAL;
+	else if ((txtfmt_lua_find_keyword(str))     != -1) fmt = FMT_TYPE_KEYWORD;
+	else                                               fmt = FMT_TYPE_DEFAULT;
+	return fmt;
+}
+
+static void txtfmt_lua_format_line(SpaceText *st, TextLine *line, const int do_next)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list