brewery
notashelf /
0a5920adaf7d2eed5d5936f8b350917fccb2ca59

nixir

public

Import-resolving Nix IR plugin

Star0tarball
clone
ssh://git@git.notashelf.dev:33/notashelf/nixir.git
src/irc/lexer.hC94 lines1.3 KB
1
#pragma once
2
3
#include <string>
4
#include <vector>
5
6
namespace nix_irc {
7
8
struct Token {
9
  enum Type {
10
    LPAREN,
11
    RPAREN,
12
    LBRACE,
13
    RBRACE,
14
    LBRACKET,
15
    RBRACKET,
16
    IDENT,
17
    STRING,
18
    STRING_INTERP,
19
    INDENTED_STRING,
20
    INDENTED_STRING_INTERP,
21
    PATH,
22
    LOOKUP_PATH,
23
    INT,
24
    FLOAT,
25
    URI,
26
    BOOL,
27
    LET,
28
    IN,
29
    REC,
30
    IF,
31
    THEN,
32
    ELSE,
33
    ASSERT,
34
    WITH,
35
    INHERIT,
36
    IMPORT,
37
    DOT,
38
    SEMICOLON,
39
    COLON,
40
    EQUALS,
41
    AT,
42
    COMMA,
43
    QUESTION,
44
    ELLIPSIS,
45
    // Operators
46
    PLUS,
47
    MINUS,
48
    STAR,
49
    SLASH,
50
    CONCAT,
51
    MERGE,
52
    EQEQ,
53
    NE,
54
    LT,
55
    GT,
56
    LE,
57
    GE,
58
    AND,
59
    OR,
60
    IMPL,
61
    NOT,
62
    EOF_
63
  } type;
64
  std::string value;
65
  size_t line;
66
  size_t col;
67
};
68
69
class Lexer {
70
public:
71
  Lexer(const std::string& input);
72
  std::vector<Token> tokenize();
73
74
private:
75
  std::vector<Token> tokens;
76
  const std::string& input;
77
  size_t pos;
78
  size_t line;
79
  size_t col;
80
81
  void emit(const Token& t);
82
  void skip_whitespace();
83
  void tokenize_string();
84
  void tokenize_indented_string();
85
  std::string strip_indentation(const std::string& s);
86
  void tokenize_path();
87
  void tokenize_home_path();
88
  void tokenize_int();
89
  void tokenize_float();
90
  void tokenize_uri();
91
  void tokenize_ident();
92
};
93
94
} // namespace nix_irc