Skip to content

Commit 4520f2e

Browse files
committed
Merge branch 'main' into release/2.x
2 parents f2f3976 + 06d1c85 commit 4520f2e

File tree

16 files changed

+385
-178
lines changed

16 files changed

+385
-178
lines changed

libnixf/include/nixf/Basic/Nodes/Op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

33
#include "Basic.h"
4+
#include "Tokens.h"
45

56
#include "nixf/Basic/Nodes/Attrs.h"
6-
#include "nixf/Basic/TokenKinds.h"
77

88
#include <memory>
99

libnixf/include/nixf/Basic/TokenKinds.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

libnixf/include/nixf/Basic/TokenKinds.inc

Lines changed: 0 additions & 100 deletions
This file was deleted.

libnixf/include/nixf/Basic/Tokens.inc

Lines changed: 0 additions & 9 deletions
This file was deleted.

libnixf/src/Parse/Lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void Lexer::maybeKW() {
320320
Tok = tok_kw_##NAME; \
321321
return; \
322322
}
323-
#include "nixf/Basic/TokenKinds.inc"
323+
#include "TokenKinds.inc"
324324
#undef TOK_KEYWORD
325325
}
326326

libnixf/src/Parse/ParseExpr.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ std::shared_ptr<Expr> Parser::parseExprApp(int Limit) {
7171
}
7272

7373
std::shared_ptr<Expr> Parser::parseExpr() {
74-
// Look ahead 3 tokens.
74+
// Look ahead 4 tokens.
7575
switch (peek().kind()) {
7676
case tok_id: {
7777
switch (peek(1).kind()) {
@@ -93,8 +93,15 @@ std::shared_ptr<Expr> Parser::parseExpr() {
9393
case tok_comma: // { a ,
9494
case tok_id: // { a b
9595
case tok_ellipsis: // { a ...
96-
case tok_r_curly:
9796
return parseExprLambda();
97+
case tok_r_curly:
98+
switch (peek(3).kind()) {
99+
case tok_colon: // { a } :
100+
case tok_at: // { a } @
101+
return parseExprLambda();
102+
default:
103+
return parseExprAttrs();
104+
}
98105
default:
99106
break;
100107
}

libnixf/src/Parse/ParseOp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ std::shared_ptr<Expr> Parser::parseExprOpBP(unsigned LeftRBP) {
108108
for (;;) {
109109
switch (Token Tok = peek(); Tok.kind()) {
110110
#define TOK_BIN_OP(NAME) case tok_op_##NAME:
111-
#include "nixf/Basic/TokenKinds.inc"
111+
#include "TokenKinds.inc"
112112
#undef TOK_BIN_OP
113113
{
114114
// For all binary ops:

libnixf/src/Parse/ParseSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "Parser.h"
55

6-
#include "nixf/Basic/TokenKinds.h"
6+
#include "Tokens.h"
77
#include "nixf/Parse/Parser.h"
88

99
using namespace nixf;

libnixf/src/Parse/Token.h

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,13 @@
11
#pragma once
22

3+
#include "Tokens.h"
34
#include "nixf/Basic/Range.h"
4-
#include "nixf/Basic/TokenKinds.h"
55

66
#include <cassert>
77
#include <string_view>
88

99
namespace nixf {
1010

11-
namespace tok {
12-
13-
constexpr std::string_view spelling(TokenKind Kind) {
14-
switch (Kind) {
15-
#define TOK_KEYWORD(NAME) \
16-
case tok_kw_##NAME: \
17-
return #NAME;
18-
#include "nixf/Basic/TokenKinds.inc"
19-
#undef TOK_KEYWORD
20-
case tok_dquote:
21-
return "\"";
22-
case tok_quote2:
23-
return "''";
24-
case tok_dollar_curly:
25-
return "${";
26-
case tok_l_curly:
27-
return "{";
28-
case tok_r_curly:
29-
return "}";
30-
case tok_l_paren:
31-
return "(";
32-
case tok_r_paren:
33-
return ")";
34-
case tok_eq:
35-
return "=";
36-
case tok_semi_colon:
37-
return ";";
38-
case tok_l_bracket:
39-
return "[";
40-
case tok_r_bracket:
41-
return "]";
42-
case tok_colon:
43-
return ":";
44-
default:
45-
assert(false && "Not yet implemented!");
46-
}
47-
__builtin_unreachable();
48-
}
49-
50-
} // namespace tok
51-
5211
/// \brief A token. With it's kind, and the range in source code.
5312
///
5413
/// This class is trivially copyable.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from tokens import bin_op_tokens, keyword_tokens, tokens
2+
3+
4+
def generate_token_section(section_name: str, tokens: list) -> str:
5+
if not tokens:
6+
return ""
7+
8+
section = [f"#ifdef {section_name}"]
9+
section.extend(f"{section_name}({token.name})" for token in tokens)
10+
section.append(f"#endif // {section_name}\n")
11+
12+
return "\n".join(section)
13+
14+
15+
def generate_token_kinds_inc() -> str:
16+
sections = [
17+
generate_token_section("TOK_KEYWORD", keyword_tokens),
18+
generate_token_section("TOK", tokens),
19+
generate_token_section("TOK_BIN_OP", bin_op_tokens),
20+
]
21+
22+
return "\n".join(filter(None, sections)).strip()
23+
24+
25+
if __name__ == "__main__":
26+
import sys
27+
28+
with open(sys.argv[1], "w") as f:
29+
f.write(generate_token_kinds_inc())

0 commit comments

Comments
 (0)