[geany/geany] 8294ea: Add Asciidoc filetype
Lex
git-noreply at geany.org
Thu Jan 17 04:43:24 UTC 2013
Branch: refs/heads/master
Author: Lex <elextr at gmail.com>
Committer: Lex <elextr at gmail.com>
Date: Thu, 17 Jan 2013 04:43:24 UTC
Commit: 8294ea2c2e948894fd211d0ea55b34f12e76d553
https://github.com/geany/geany/commit/8294ea2c2e948894fd211d0ea55b34f12e76d553
Log Message:
-----------
Add Asciidoc filetype
Add a filetype for Asciidoc with symbol parser, but not styling.
Modified Paths:
--------------
data/filetype_extensions.conf
data/filetypes.asciidoc
src/filetypes.c
src/filetypes.h
src/symbols.c
tagmanager/ctags/Makefile.am
tagmanager/ctags/asciidoc.c
tagmanager/ctags/makefile.win32
tagmanager/ctags/parsers.h
wscript
Modified: data/filetype_extensions.conf
1 files changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -5,6 +5,7 @@
Abc=*.abc;*.abp;
ActionScript=*.as;
Ada=*.adb;*.ads;
+Asciidoc=*.asciidoc;
ASM=*.asm;
CAML=*.ml;*.mli;
C=*.c;*.h;
Modified: data/filetypes.asciidoc
35 files changed, 35 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,35 @@
+# For complete documentation of this file, please see Geany's main documentation
+[styling]
+# no syntax highlighting yet
+
+[settings]
+# default extension used when saving files
+extension=asciidoc
+
+# the following characters are these which a "word" can contains, see documentation
+#wordchars=_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
+
+# single comments, like # in this file
+comment_single=//
+# multiline comments
+#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=
+
+# sort tags by appearance
+symbol_list_sort_mode=1
+
+[indentation]
+#width=4
+# 0 is spaces, 1 is tabs, 2 is tab & spaces
+#type=1
Modified: src/filetypes.c
8 files changed, 8 insertions(+), 0 deletions(-)
===================================================================
@@ -496,6 +496,14 @@ static void init_builtin_filetypes(void)
ft->name = g_strdup("Forth");
filetype_make_title(ft, TITLE_SOURCE_FILE);
ft->group = GEANY_FILETYPE_GROUP_SCRIPT;
+
+#define ASCIIDOC
+ ft = filetypes[GEANY_FILETYPES_ASCIIDOC];
+ ft->lang = 43;
+ ft->name = g_strdup("Asciidoc");
+ filetype_make_title(ft, TITLE_SOURCE_FILE);
+ ft->group = GEANY_FILETYPE_GROUP_MARKUP;
+
}
Modified: src/filetypes.h
1 files changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -90,6 +90,7 @@
GEANY_FILETYPES_ERLANG,
GEANY_FILETYPES_COBOL,
GEANY_FILETYPES_OBJECTIVEC,
+ GEANY_FILETYPES_ASCIIDOC,
/* ^ append items here */
GEANY_MAX_BUILT_IN_FILETYPES /* Don't use this, use filetypes_array->len instead */
}
Modified: src/symbols.c
11 files changed, 11 insertions(+), 0 deletions(-)
===================================================================
@@ -807,6 +807,17 @@ static void add_top_level_items(GeanyDocument *doc)
NULL);
break;
}
+ case GEANY_FILETYPES_ASCIIDOC:
+ {
+ tag_list_add_groups(tag_store,
+ &(tv_iters.tag_namespace), _("Chapter"), NULL,
+ &(tv_iters.tag_member), _("Section"), NULL,
+ &(tv_iters.tag_macro), _("Level2section"), NULL,
+ &(tv_iters.tag_variable), _("Level3section"), NULL,
+ &(tv_iters.tag_struct), _("Level4section"), NULL,
+ NULL);
+ break;
+ }
case GEANY_FILETYPES_RUBY:
{
tag_list_add_groups(tag_store,
Modified: tagmanager/ctags/Makefile.am
1 files changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -13,6 +13,7 @@ noinst_LIBRARIES = libctags.a
parsers = \
abc.c \
actionscript.c \
+ asciidoc.c \
asm.c \
basic.c \
c.c \
Modified: tagmanager/ctags/asciidoc.c
205 files changed, 205 insertions(+), 0 deletions(-)
===================================================================
@@ -0,0 +1,205 @@
+/*
+*
+* Copyright (c) 2012, Lex Trotman
+* Based on Rest code by Nick Treleaven, see rest.c
+*
+* 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 asciidoc files.
+*/
+
+/*
+* INCLUDE FILES
+*/
+#include "general.h" /* must always come first */
+
+#include <ctype.h>
+#include <string.h>
+
+#include "parse.h"
+#include "read.h"
+#include "vstring.h"
+#include "nestlevel.h"
+
+/*
+* DATA DEFINITIONS
+*/
+typedef enum {
+ K_CHAPTER = 0,
+ K_SECTION,
+ K_SUBSECTION,
+ K_SUBSUBSECTION,
+ K_LEVEL5SECTION,
+ SECTION_COUNT
+} asciidocKind;
+
+static kindOption AsciidocKinds[] = {
+ { TRUE, 'n', "namespace", "chapters"},
+ { TRUE, 'm', "member", "sections" },
+ { TRUE, 'd', "macro", "level2sections" },
+ { TRUE, 'v', "variable", "level3sections" },
+ { TRUE, 's', "struct", "level4sections" }
+};
+
+static char kindchars[SECTION_COUNT]={ '=', '-', '~', '^', '+' };
+
+static NestingLevels *nestingLevels = NULL;
+
+/*
+* FUNCTION DEFINITIONS
+*/
+
+static NestingLevel *getNestingLevel(const int kind)
+{
+ NestingLevel *nl;
+
+ while (1)
+ {
+ nl = nestingLevelsGetCurrent(nestingLevels);
+ if (nl && nl->type >= kind)
+ nestingLevelsPop(nestingLevels);
+ else
+ break;
+ }
+ return nl;
+}
+
+static void makeAsciidocTag (const vString* const name, const int kind)
+{
+ const NestingLevel *const nl = getNestingLevel(kind);
+
+ if (vStringLength (name) > 0)
+ {
+ tagEntryInfo e;
+ initTagEntry (&e, vStringValue (name));
+
+ e.lineNumber--; /* we want the line before the '---' underline chars */
+ e.kindName = AsciidocKinds [kind].name;
+ e.kind = AsciidocKinds [kind].letter;
+
+ if (nl && nl->type < kind)
+ {
+ e.extensionFields.scope [0] = AsciidocKinds [nl->type].name;
+ e.extensionFields.scope [1] = vStringValue (nl->name);
+ }
+ makeTagEntry (&e);
+ }
+ nestingLevelsPush(nestingLevels, name, kind);
+}
+
+
+/* checks if str is all the same character */
+static boolean issame(const char *str)
+{
+ char first = *str;
+
+ while (*str)
+ {
+ char c;
+
+ str++;
+ c = *str;
+ if (c && c != first)
+ return FALSE;
+ }
+ return TRUE;
+}
+
+
+static int get_kind(char c)
+{
+ int i;
+
+ for (i = 0; i < SECTION_COUNT; i++)
+ {
+ if (kindchars[i] == c)
+ return i;
+ }
+ return -1;
+}
+
+
+/* computes the length of an UTF-8 string
+ * if the string doesn't look like UTF-8, return -1 */
+static int utf8_strlen(const char *buf, int buf_len)
+{
+ int len = 0;
+ const char *end = buf + buf_len;
+
+ for (len = 0; buf < end; len ++)
+ {
+ /* perform quick and naive validation (no sub-byte checking) */
+ if (! (*buf & 0x80))
+ buf ++;
+ else if ((*buf & 0xe0) == 0xc0)
+ buf += 2;
+ else if ((*buf & 0xf0) == 0xe0)
+ buf += 3;
+ else if ((*buf & 0xf8) == 0xf0)
+ buf += 4;
+ else /* not a valid leading UTF-8 byte, abort */
+ return -1;
+
+ if (buf > end) /* incomplete last byte */
+ return -1;
+ }
+
+ return len;
+}
+
+
+static void findAsciidocTags (void)
+{
+ vString *name = vStringNew ();
+ const unsigned char *line;
+
+ nestingLevels = nestingLevelsNew();
+
+ while ((line = fileReadLine ()) != NULL)
+ {
+ int line_len = strlen((const char*) line);
+ int name_len_bytes = vStringLength(name);
+ int name_len = utf8_strlen(vStringValue(name), name_len_bytes);
+
+ /* if the name doesn't look like UTF-8, assume one-byte charset */
+ if (name_len < 0)
+ name_len = name_len_bytes;
+
+ /* underlines must be +-2 chars */
+ if (line_len >= name_len - 2 && line_len <= name_len + 2 && name_len > 0 &&
+ ispunct(line[0]) && issame((const char*) line))
+ {
+ char c = line[0];
+ int kind = get_kind(c);
+
+ if (kind >= 0)
+ {
+ makeAsciidocTag(name, kind);
+ continue;
+ }
+ }
+ vStringClear (name);
+ if (! isspace(*line))
+ vStringCatS(name, (const char*) line);
+ vStringTerminate(name);
+ }
+ vStringDelete (name);
+ nestingLevelsFree(nestingLevels);
+}
+
+extern parserDefinition* AsciidocParser (void)
+{
+ static const char *const patterns [] = { "*.asciidoc", NULL };
+ static const char *const extensions [] = { "asciidoc", NULL };
+ parserDefinition* const def = parserNew ("Asciidoc");
+
+ def->kinds = AsciidocKinds;
+ def->kindCount = KIND_COUNT (AsciidocKinds);
+ def->patterns = patterns;
+ def->extensions = extensions;
+ def->parser = findAsciidocTags;
+ return def;
+}
+
+/* vi:set tabstop=8 shiftwidth=4: */
Modified: tagmanager/ctags/makefile.win32
2 files changed, 1 insertions(+), 1 deletions(-)
===================================================================
@@ -46,7 +46,7 @@ clean:
$(COMPLIB): abc.o args.o c.o cobol.o fortran.o make.o conf.o pascal.o perl.o php.o diff.o vhdl.o verilog.o lua.o js.o \
actionscript.o nsis.o objc.o \
-haskell.o haxe.o html.o python.o lregex.o rest.o sh.o ctags.o entry.o get.o keyword.o nestlevel.o \
+haskell.o haxe.o html.o python.o lregex.o asciidoc.o rest.o sh.o ctags.o entry.o get.o keyword.o nestlevel.o \
options.o \
parse.o basic.o read.o sort.o strlist.o latex.o markdown.o matlab.o docbook.o tcl.o ruby.o asm.o sql.o txt2tags.o css.o \
vstring.o r.o
Modified: tagmanager/ctags/parsers.h
4 files changed, 3 insertions(+), 1 deletions(-)
===================================================================
@@ -57,7 +57,8 @@
VerilogParser, \
RParser, \
CobolParser, \
- ObjcParser
+ ObjcParser, \
+ AsciidocParser
/*
langType of each parser
0 CParser
@@ -103,6 +104,7 @@
40 RParser
41 CobolParser
42 ObjcParser
+43 AsciidocParser
*/
#endif /* _PARSERS_H */
Modified: wscript
1 files changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -64,6 +64,7 @@ ctags_sources = set([
'tagmanager/ctags/args.c',
'tagmanager/ctags/abc.c',
'tagmanager/ctags/actionscript.c',
+ 'tagmanager/ctags/asciidoc.c',
'tagmanager/ctags/asm.c',
'tagmanager/ctags/basic.c',
'tagmanager/ctags/c.c',
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list