[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[aspell-devel] Django filter
From: |
Sergey Poznyakoff |
Subject: |
[aspell-devel] Django filter |
Date: |
Sat, 10 Mar 2012 17:01:52 +0200 |
Hello,
Attached patch implements a filter for Django templates.
Regads,
Sergey
Index: Makefile.am
===================================================================
RCS file: /sources/aspell/aspell/Makefile.am,v
retrieving revision 1.64
diff -p -u -r1.64 Makefile.am
--- Makefile.am 7 Jul 2011 06:21:05 -0000 1.64
+++ Makefile.am 10 Mar 2012 14:52:13 -0000
@@ -182,7 +182,8 @@ optfiles = \
modules/filter/html-filter.info\
modules/filter/context-filter.info\
modules/filter/nroff-filter.info\
- modules/filter/texinfo-filter.info
+ modules/filter/texinfo-filter.info\
+ modules/filter/django-filter.info
### Add any extra data files your filter uses here
fltdata = \
@@ -222,7 +223,8 @@ libaspell_la_SOURCES +=\
modules/filter/sgml.cpp\
modules/filter/context.cpp\
modules/filter/nroff.cpp\
- modules/filter/texinfo.cpp
+ modules/filter/texinfo.cpp\
+ modules/filter/django.cpp
else # not COMPILE_IN_FILTERS
@@ -233,7 +235,8 @@ filter_ldflags = -module -avoid-version
### must look like lib<filtername>-filter.la see development manual
filter_LTLIBRARIES = email-filter.la tex-filter.la\
sgml-filter.la context-filter.la\
- nroff-filter.la texinfo-filter.la
+ nroff-filter.la texinfo-filter.la\
+ django-filter.la
email_filter_la_SOURCES = modules/filter/email.cpp
email_filter_la_LIBADD = libaspell.la
@@ -259,6 +262,10 @@ texinfo_filter_la_SOURCES = modules/fil
texinfo_filter_la_LIBADD = libaspell.la
texinfo_filter_la_LDFLAGS = ${filter_ldflags}
+django_filter_la_SOURCES = modules/filter/django.cpp
+django_filter_la_LIBADD = libaspell.la
+django_filter_la_LDFLAGS = ${filter_ldflags}
+
### Before this line add the corresponding <yourfilterlibrary>_SOURCES and
### <yourfilterlibrary>_LIBADD lines. The later at least has to look
### like <yourfilterlibrary>_LIBADD = ${top_builddir}/lib/libaspell.la
--- /dev/null 2008-08-31 00:18:45.000000000 +0300
+++ modules/filter/django.cpp 2012-03-10 13:08:16.000000000 +0200
@@ -0,0 +1,130 @@
+/* This file is part of The New Aspell
+
+ Copyright (C) 2012 Sergey Poznyakoff
+
+ GNU Aspell free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 2.1 of the
+ License, or (at your option) any later version.
+
+ GNU Aspell is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with GNU Aspell. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+
+#include "settings.h"
+#include "asc_ctype.hpp"
+#include "config.hpp"
+#include "indiv_filter.hpp"
+#include "string_map.hpp"
+#include "mutable_container.hpp"
+#include "clone_ptr.hpp"
+#include "filter_char_vector.hpp"
+
+namespace
+{
+ using namespace aspell;
+
+ class DjangoFilter : public NormalFilter
+ {
+ private:
+ enum filter_state {
+ initial, // initial state: print everything
+ brace, // open brace seen
+ escape, // within Django braces: skip until close_brace
+ maybe_close // close_brace[0] seen
+ } state;
+
+ char close_brace[2]; // sequence of characters that ends brace state.
+
+ bool inline process_char (FilterChar::Chr c);
+
+ public:
+
+ PosibErr<bool> setup(Config *)
+ {
+ set_name("django");
+ set_order_num(0.20);
+ reset();
+ return true;
+ };
+ void reset()
+ {
+ state = initial;
+ };
+ void process(FilterChar * &, FilterChar * &);
+ };
+
+ bool DjangoFilter::process_char(FilterChar::Chr c)
+ {
+ switch (state)
+ {
+ case initial:
+ if (c == '{')
+ state = brace;
+ return false;
+
+ case brace:
+ switch (c)
+ {
+ case '#': /* comment */
+ case '%': /* code */
+ close_brace[0] = c;
+ close_brace[1] = '}';
+ state = escape;
+ break;
+
+ case '{': /* variable reference */
+ close_brace[0] = '}';
+ close_brace[1] = '}';
+ state = escape;
+ break;
+
+ default:
+ state = initial;
+ }
+ return false;
+
+ case escape:
+ if (c == close_brace[0])
+ state = maybe_close;
+ return true;
+
+ case maybe_close:
+ if (c == close_brace[1])
+ state = initial;
+ else
+ state = escape;
+ return false;
+ }
+ return true;
+ }
+
+ void DjangoFilter::process(FilterChar * & str, FilterChar * & stop)
+ {
+ FilterChar * cur = str;
+ for (; cur != stop; cur++)
+ {
+ if (process_char (*cur))
+ *cur = ' ';
+ }
+ }
+}
+
+C_EXPORT
+IndividualFilter * new_aspell_django_filter() {
+ return new DjangoFilter;
+}
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [aspell-devel] Django filter,
Sergey Poznyakoff <=