sisi4s
Loading...
Searching...
No Matches
Parsing.hpp
Go to the documentation of this file.
1#ifndef _ALEJANDROS_PARSING_LIBRAY
2#define _ALEJANDROS_PARSING_LIBRAY
3
4#include <regex>
5#include <string>
6#include <vector>
7
8namespace pars {
9using Str = std::string;
10const Str oneOrMore("+"), newline("\\n"), anyChar("."), tab("\\t"), anyOf("*"),
11 optional("?"), eof("$"), orOf("|"), bof("^") // begin of line
12 ,
13 alnum("[[:alnum:]]") // lowercase letters, uppercase letters, and digits
14 ,
15 alpha("[[:alpha:]]") // lowercase letters and uppercase letters
16 ,
17 blank("[[:blank:]]") // space or tab
18 ,
19 cntrl("[[:cntrl:]]") // the file format escape characters
20 ,
21 digit("[[:digit:]]") // digits
22 // lowercase letters, uppercase letters, digits, and punctuation
23 ,
24 graph("[[:graph:]]"), lower("[[:lower:]]") // lowercase letters
25 ,
26 upper("[[:upper:]]") // uppercase characters
27 // lowercase letters, uppercase letters, digits, punctuation, and space
28 ,
29 print("[[:print:]]"), punct("[[:punct:]]") // punctuation
30 ,
31 space("[[:space:]]") // space
32 ,
33 xdigit("[[:xdigit:]]") // hexadecimal digits (with upper and lower)
34 ,
35 realNumber("[-eE+\\d.]+") // real number TODO: improve
36 ;
37
38const std::function<Str(Str)> capture([](const Str &i) {
39 return "(" + i + ")";
40}),
41 group([](const Str &i) { return "(?:" + i + ")"; });
42
43Str oneOf(const std::vector<Str> &);
44
45struct Regex {
46 const std::string s;
47 const std::regex r;
48 Regex(const char *s_)
49 : s(s_)
50 , r(s_) {}
51 Regex(const std::string &s_)
52 : s(s_)
53 , r(s_) {}
54};
55
56template <typename F>
57std::vector<F> parseVector(const std::string &);
58
59} // namespace pars
60
61#endif
Definition Parsing.cxx:6
const Str lower("[[:lower:]]")
const Str bof("^")
const Str alnum("[[:alnum:]]")
const Str blank("[[:blank:]]")
const Str eof("$")
const Str graph("[[:graph:]]")
const Str xdigit("[[:xdigit:]]")
const std::function< Str(Str)> group([](const Str &i) { return "(?:"+i+")";})
std::vector< std::string > parseVector(const std::string &l)
Definition Parsing.cxx:19
const Str anyOf("*")
const Str oneOrMore("+")
const Str newline("\\n")
const Str optional("?")
const Str upper("[[:upper:]]")
const std::function< Str(Str)> capture([](const Str &i) { return "("+i+")";})
const Str digit("[[:digit:]]")
const Str space("[[:space:]]")
const Str cntrl("[[:cntrl:]]")
const Str orOf("|")
const Str realNumber("[-eE+\\d.]+")
const Str tab("\\t")
std::string oneOf(const std::vector< std::string > &v)
Definition Parsing.cxx:8
std::string Str
Definition Parsing.hpp:9
const Str anyChar(".")
const Str print("[[:print:]]")
const Str punct("[[:punct:]]")
const Str alpha("[[:alpha:]]")
Definition Parsing.hpp:45
Regex(const std::string &s_)
Definition Parsing.hpp:51
Regex(const char *s_)
Definition Parsing.hpp:48
const std::regex r
Definition Parsing.hpp:47
const std::string s
Definition Parsing.hpp:46