cpp

Coverage Report

Created: 2022-09-21 22:22

/home/andy/git/oilshell/oil/cpp/leaky_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, Str* 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, Str* s)
27
2
      : match_func_(match_func), s_(s), pos_(0) {
28
2
  }
29
  Tuple2<Id_t, Str*> Next();
30
  List<Tuple2<Id_t, Str*>*>* Tokens();
31
32
 private:
33
  MatchFunc match_func_;
34
  Str* s_;
35
  int pos_;
36
};
37
38
//
39
// Secondary Lexers
40
//
41
42
SimpleLexer* BraceRangeLexer(Str* s);
43
SimpleLexer* GlobLexer(Str* s);
44
SimpleLexer* EchoLexer(Str* s);
45
46
List<Tuple2<Id_t, Str*>*>* HistoryTokens(Str* s);
47
List<Tuple2<Id_t, Str*>*>* Ps1Tokens(Str* s);
48
49
Id_t BracketUnary(Str* s);
50
Id_t BracketBinary(Str* s);
51
Id_t BracketOther(Str* s);
52
53
//
54
// Other Matching Functions
55
//
56
57
bool IsValidVarName(Str* s);
58
bool ShouldHijack(Str* s);
59
60
// StringToInt
61
62
int MatchOption(Str* s);
63
64
}  // namespace match
65
66
#endif  // MATCH_H