source: icGREP/icgrep-devel/icgrep/re_parser.h @ 3935

Last change on this file since 3935 was 3935, checked in by daled, 5 years ago

The parser is now able to parse unicode categories.

File size: 2.5 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef RE_PARSER_H
8#define RE_PARSER_H
9
10#include "re_re.h"
11#include "parseresult.h"
12#include "parsesuccess.h"
13#include "parsefailure.h"
14
15#include "cc_compiler.h"
16
17#include <fstream>
18#include <iostream>
19#include <string>
20#include <sstream>
21#include <vector>
22#include <ctype.h>
23
24
25struct parse_int_retVal{
26    int i;
27    std::string remaining;
28};
29
30struct parse_result_retVal{
31    ParseResult* result;
32    std::string remaining;
33};
34
35struct parse_re_list_retVal{
36    std::list<RE*> re_list;
37    std::string remaining;
38};
39
40struct parse_re_vector_retVal{
41    std::vector<RE*> re_vector;
42    std::string remaining;
43};
44
45class RE_Parser
46{
47public:
48    //RE_Parser();
49    //The module exports the parse result.
50    static ParseResult* parse_re(std::string intput_string);
51private:
52    static parse_result_retVal parse_re_helper(std::string s);
53    static parse_re_list_retVal parse_re_alt_form_list(std::string s);
54    static parse_result_retVal parse_re_form(std::string s);
55    static parse_re_list_retVal parse_re_item_list(std::string s);
56    static parse_result_retVal parse_re_item(std::string s);
57    static parse_result_retVal parse_re_unit(std::string s);
58    static parse_result_retVal extend_item(RE* re, std::string s);
59    static parse_result_retVal parse_cc(std::string s);
60    static parse_result_retVal parse_cc_body(std::string s);
61    static parse_result_retVal parse_cc_body0(std::string s, CC* cc_sofar);
62    static parse_result_retVal parse_cc_body1(int chr, std::string s, CC* cc_sofar);
63    static parse_result_retVal parse_utf8_bytes(int suffix_count, std::string s);
64    static parse_result_retVal parse_utf8_suffix_byte(int suffix_byte_num, std::string s, Seq* seq_sofar);
65
66    static parse_result_retVal parse_unicode_category(std::string s);
67    static parse_result_retVal parse_unicode_category1(std::string character, std::string s, Name* name_sofar);
68    static bool isValidUnicodeCategoryName(Name* name);
69
70    static parse_int_retVal parse_hex(std::string s);
71    static parse_int_retVal parse_hex_body(int i, std::string s);
72    static int parse_hex_body1(int i, std::string hex_str);
73
74    static parse_int_retVal parse_int(std::string s);
75    static parse_int_retVal parse_int1(int i, std::string s);
76    static parse_result_retVal negate_cc_result(parse_result_retVal cc_result);
77};
78
79#endif // RE_PARSER_H
Note: See TracBrowser for help on using the repository browser.