Created parser and interfaces for creating specific parsers for specific
[qshowdiff.git] / src / parser / parser.h
blob82306ec0179ebf385c61560244933f54903e2eb7
1 #ifndef _PARSER_H_
2 #define _PARSER_H_
4 #include <string>
5 #include <vector>
6 #include <QTextStream>
7 #include "../diff/diff.h"
9 class Tokens{
10 public:
11 /*{*/
12 /**
13 * Tokens
15 QRegExp file_tok;
16 QRegExp hunk_tok;
17 QRegExp context_tok;
18 QRegExp added_tok;
19 QRegExp deleted_tok;
20 /*}*/
22 protected:
23 Tokens(const char *file_tok,
24 const char *hunk_tok,
25 const char *context_tok,
26 const char *added_tok,
27 const char *deleted_tok);
29 public:
30 enum token{
31 FILE_TOK,
32 HUNK_TOK,
33 CONTEXT_TOK,
34 ADDED_TOK,
35 DELETED_TOK,
36 NONE_TOK
39 virtual token match(QString &line) const;
43 class TokensGit : public Tokens{
44 public:
45 TokensGit();
49 Tokens *factory(std::string);
51 class Parser{
52 private:
53 enum states{
54 START_STATE = 0,
55 FILE_STATE,
56 HUNK_STATE,
57 CONTEXT_STATE,
58 ADDED_STATE,
59 DELETED_STATE,
60 CHANGED_STATE,
61 END_STATE
64 states _current_state;
65 QString _current_line;
66 Tokens::token _current_token;
68 QTextStream *_in;
69 Tokens *_tokens;
71 File *_cur_file;
72 Hunk *_cur_hunk;
73 Text *_cur_context;
74 Text *_cur_deleted;
75 Text *_cur_added;
77 void _changeState(states);
78 void _readNextLine();
79 QString _capCurrentLine(int);
81 void _createNewFile();
82 void _finishFile();
84 void _createNewHunk();
85 void _finishHunk();
87 void _addCurrentLineToContext();
88 void _finishContext();
89 void _addCurrentLineToAdded();
90 void _finishAdded();
91 void _addCurrentLineToDeleted();
92 void _finishDeleted();
93 void _finishChanged();
95 void _start();
96 void _file();
97 void _hunk();
98 void _context();
99 void _added();
100 void _deleted();
101 void _changed();
102 void _end();
103 public:
104 Parser(std::string type, QTextStream *in) :
105 _current_state(START_STATE),
106 _in(in),
107 _cur_file(NULL), _cur_hunk(NULL), _cur_context(NULL),
108 _cur_deleted(NULL), _cur_added(NULL) { _tokens = factory(type); }
109 void parse();
112 #endif