From eb503363f9af3a375a4ad1dd35001bdfe5faf831 Mon Sep 17 00:00:00 2001 From: Daniel Fiser Date: Tue, 6 Nov 2007 20:23:34 +0100 Subject: [PATCH] Files parser.{h,cpp} splitted into parser.{h,cpp} and tokens.{h,cpp}. --- src/Makefile | 2 +- src/parser/parser.cpp | 45 --------------------------------------------- src/parser/parser.h | 45 ++------------------------------------------- src/parser/tokens.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/parser/tokens.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 98 insertions(+), 89 deletions(-) create mode 100644 src/parser/tokens.cpp create mode 100644 src/parser/tokens.h diff --git a/src/Makefile b/src/Makefile index 88e4db4..3ad4dd3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -24,7 +24,7 @@ TARGETS = qshowdiff DIFF_OBJS = snippet.o diff.o \ levenshtein_table.o levenshtein_distances.o QT_OBJS = diff_view.o main_window.o -PARSER_OBJS = parser.o +PARSER_OBJS = parser.o tokens.o OBJS_TMP = main.o settings.o $(DIFF_OBJS) $(QT_OBJS) $(PARSER_OBJS) OBJS = $(foreach file, $(OBJS_TMP), objs/$(file)) diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 9052aa5..9f11730 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -3,41 +3,6 @@ using namespace std; -Tokens::Tokens(const char *f_tok, - const char *h_tok, - const char *c_tok, - const char *a_tok, - const char *d_tok) : - file_tok(f_tok), - hunk_tok(h_tok), - context_tok(c_tok), - added_tok(a_tok), - deleted_tok(d_tok){} - -Tokens::token Tokens::match(QString &line) const -{ - if (file_tok.indexIn(line) != -1){ - return FILE_TOK; - }else if (hunk_tok.indexIn(line) != -1){ - return HUNK_TOK; - }else if (context_tok.indexIn(line) != -1){ - return CONTEXT_TOK; - }else if (added_tok.indexIn(line) != -1){ - return ADDED_TOK; - }else if (deleted_tok.indexIn(line) != -1){ - return DELETED_TOK; - } - - return NONE_TOK; -} - -TokensGit::TokensGit() : Tokens::Tokens("^diff --git a/([^ ]+) b/.*$", - "^@@ -([0-9]+),.* \\+([0-9]+),.*$", - "^ .*$", - "^\\+.*$", - "^-.*$"){} - - /* PARSER */ // public: void Parser::parse() @@ -405,13 +370,3 @@ void Parser::_finishChanged() } /* PARSER END */ - - -Tokens *factory(string type) -{ - Tokens *ret; - - ret = new TokensGit(); - DBG("factory(" << type << ") - ret: " << (long)ret); - return ret; -} diff --git a/src/parser/parser.h b/src/parser/parser.h index c3c6821..9050e79 100644 --- a/src/parser/parser.h +++ b/src/parser/parser.h @@ -4,50 +4,9 @@ #include #include #include -#include -#include "../diff/diff.h" - -class Tokens{ - public: - /*{*/ - /** - * Tokens - */ - QRegExp file_tok; - QRegExp hunk_tok; - QRegExp context_tok; - QRegExp added_tok; - QRegExp deleted_tok; - /*}*/ - - protected: - Tokens(const char *file_tok, - const char *hunk_tok, - const char *context_tok, - const char *added_tok, - const char *deleted_tok); - public: - enum token{ - FILE_TOK, - HUNK_TOK, - CONTEXT_TOK, - ADDED_TOK, - DELETED_TOK, - NONE_TOK - }; - - virtual token match(QString &line) const; -}; - - -class TokensGit : public Tokens{ - public: - TokensGit(); -}; - - -Tokens *factory(std::string); +#include "tokens.h" +#include "../diff/diff.h" class Parser{ private: diff --git a/src/parser/tokens.cpp b/src/parser/tokens.cpp new file mode 100644 index 0000000..5be2e53 --- /dev/null +++ b/src/parser/tokens.cpp @@ -0,0 +1,47 @@ +#include "tokens.h" +using std::string; + +Tokens *factory(string type) +{ + Tokens *ret; + + ret = new TokensGit(); + DBG("factory(" << type << ") - ret: " << (long)ret); + return ret; +} + + +Tokens::Tokens(const char *f_tok, + const char *h_tok, + const char *c_tok, + const char *a_tok, + const char *d_tok) : + file_tok(f_tok), + hunk_tok(h_tok), + context_tok(c_tok), + added_tok(a_tok), + deleted_tok(d_tok){} + +Tokens::token Tokens::match(QString &line) const +{ + if (file_tok.indexIn(line) != -1){ + return FILE_TOK; + }else if (hunk_tok.indexIn(line) != -1){ + return HUNK_TOK; + }else if (context_tok.indexIn(line) != -1){ + return CONTEXT_TOK; + }else if (added_tok.indexIn(line) != -1){ + return ADDED_TOK; + }else if (deleted_tok.indexIn(line) != -1){ + return DELETED_TOK; + } + + return NONE_TOK; +} + +/* CONCRETE TOKENS: */ +TokensGit::TokensGit() : Tokens::Tokens("^diff --git a/([^ ]+) b/.*$", + "^@@ -([0-9]+),.* \\+([0-9]+),.*$", + "^ .*$", + "^\\+.*$", + "^-.*$"){} diff --git a/src/parser/tokens.h b/src/parser/tokens.h new file mode 100644 index 0000000..ab869b5 --- /dev/null +++ b/src/parser/tokens.h @@ -0,0 +1,48 @@ +#ifndef _TOKENS_H_ +#define _TOKENS_H_ + +#include +#include + +#include "../debug.h" + +class Tokens{ + public: + /*{*/ + /** + * Tokens + */ + QRegExp file_tok; + QRegExp hunk_tok; + QRegExp context_tok; + QRegExp added_tok; + QRegExp deleted_tok; + /*}*/ + + protected: + Tokens(const char *file_tok, + const char *hunk_tok, + const char *context_tok, + const char *added_tok, + const char *deleted_tok); + + public: + enum token{ + FILE_TOK, + HUNK_TOK, + CONTEXT_TOK, + ADDED_TOK, + DELETED_TOK, + NONE_TOK + }; + + virtual token match(QString &line) const; +}; + +class TokensGit : public Tokens{ + public: + TokensGit(); +}; + +Tokens *factory(std::string); +#endif -- 2.11.4.GIT