/home/andy/git/oilshell/oil/cpp/frontend_match.h
Line | Count | Source |
1 | | // Replacement for frontend/match |
2 | | |
3 | | #ifndef MATCH_H |
4 | | #define MATCH_H |
5 | | |
6 | | #include "_gen/frontend/id_kind.asdl.h" // syntax.asdl depends on this |
7 | | #include "mycpp/runtime.h" |
8 | | using id_kind_asdl::Id_t; // TODO: proper ASDL modules |
9 | | |
10 | | #include "_gen/frontend/syntax.asdl.h" |
11 | | #include "_gen/frontend/types.asdl.h" |
12 | | |
13 | | namespace match { |
14 | | |
15 | | using types_asdl::lex_mode_t; |
16 | | |
17 | | // The big lexer |
18 | | Tuple2<Id_t, int> OneToken(lex_mode_t lex_mode, BigStr* line, int start_pos); |
19 | | |
20 | | // There are 5 secondary lexers with matchers of this type |
21 | | typedef void (*MatchFunc)(const unsigned char* line, int line_len, |
22 | | int start_pos, int* id, int* end_pos); |
23 | | |
24 | | class SimpleLexer { |
25 | | public: |
26 | | SimpleLexer(MatchFunc match_func, BigStr* s) |
27 | 6 | : match_func_(match_func), s_(s), pos_(0) { |
28 | 6 | } |
29 | | |
30 | | Tuple2<Id_t, BigStr*> Next(); |
31 | | List<Tuple2<Id_t, BigStr*>*>* Tokens(); |
32 | | |
33 | 4 | static constexpr ObjHeader obj_header() { |
34 | 4 | return ObjHeader::ClassFixed(field_mask(), sizeof(SimpleLexer)); |
35 | 4 | } |
36 | | |
37 | 4 | static constexpr uint32_t field_mask() { |
38 | 4 | return maskbit(offsetof(SimpleLexer, s_)); |
39 | 4 | } |
40 | | |
41 | | private: |
42 | | MatchFunc match_func_; |
43 | | BigStr* s_; |
44 | | int pos_; |
45 | | }; |
46 | | |
47 | | // |
48 | | // Secondary Lexers |
49 | | // |
50 | | |
51 | | SimpleLexer* BraceRangeLexer(BigStr* s); |
52 | | SimpleLexer* GlobLexer(BigStr* s); |
53 | | SimpleLexer* EchoLexer(BigStr* s); |
54 | | |
55 | | List<Tuple2<Id_t, BigStr*>*>* HistoryTokens(BigStr* s); |
56 | | List<Tuple2<Id_t, BigStr*>*>* Ps1Tokens(BigStr* s); |
57 | | |
58 | | Id_t BracketUnary(BigStr* s); |
59 | | Id_t BracketBinary(BigStr* s); |
60 | | Id_t BracketOther(BigStr* s); |
61 | | |
62 | | // |
63 | | // Other Matching Functions |
64 | | // |
65 | | |
66 | | bool IsValidVarName(BigStr* s); |
67 | | bool ShouldHijack(BigStr* s); |
68 | | bool LooksLikeFloat(BigStr* s); |
69 | | bool LooksLikeInteger(BigStr* s); |
70 | | |
71 | | // StringToInt |
72 | | |
73 | | int MatchOption(BigStr* s); |
74 | | |
75 | | } // namespace match |
76 | | |
77 | | #endif // MATCH_H |