Skip to content

Commit 71d0964

Browse files
authored
Merge pull request #3560 from ruby/optimize-context-terminator
Context terminator updates
2 parents c4e388d + 915f6b3 commit 71d0964

5 files changed

Lines changed: 235 additions & 123 deletions

File tree

config.yml

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,42 @@ warnings:
320320
- UNUSED_LOCAL_VARIABLE
321321
- VOID_STATEMENT
322322
tokens:
323+
# The order of the tokens at the beginning is important, because we use them
324+
# for a lookup table.
323325
- name: EOF
324326
value: 1
325327
comment: final token in the file
326-
- name: MISSING
327-
comment: "a token that was expected but not found"
328-
- name: NOT_PROVIDED
329-
comment: "a token that was not present but it is okay"
328+
- name: BRACE_RIGHT
329+
comment: "}"
330+
- name: COMMA
331+
comment: ","
332+
- name: EMBEXPR_END
333+
comment: "}"
334+
- name: KEYWORD_DO
335+
comment: "do"
336+
- name: KEYWORD_ELSE
337+
comment: "else"
338+
- name: KEYWORD_ELSIF
339+
comment: "elsif"
340+
- name: KEYWORD_END
341+
comment: "end"
342+
- name: KEYWORD_ENSURE
343+
comment: "ensure"
344+
- name: KEYWORD_IN
345+
comment: "in"
346+
- name: KEYWORD_RESCUE
347+
comment: "rescue"
348+
- name: KEYWORD_THEN
349+
comment: "then"
350+
- name: KEYWORD_WHEN
351+
comment: "when"
352+
- name: NEWLINE
353+
comment: "a newline character outside of other tokens"
354+
- name: PARENTHESIS_RIGHT
355+
comment: ")"
356+
- name: SEMICOLON
357+
comment: ";"
358+
# Tokens from here on are not used for lookup, and can be in any order.
330359
- name: AMPERSAND
331360
comment: "&"
332361
- name: AMPERSAND_AMPERSAND
@@ -349,8 +378,6 @@ tokens:
349378
comment: "!~"
350379
- name: BRACE_LEFT
351380
comment: "{"
352-
- name: BRACE_RIGHT
353-
comment: "}"
354381
- name: BRACKET_LEFT
355382
comment: "["
356383
- name: BRACKET_LEFT_ARRAY
@@ -373,8 +400,6 @@ tokens:
373400
comment: ":"
374401
- name: COLON_COLON
375402
comment: "::"
376-
- name: COMMA
377-
comment: ","
378403
- name: COMMENT
379404
comment: "a comment"
380405
- name: CONSTANT
@@ -393,8 +418,6 @@ tokens:
393418
comment: "a line inside of embedded documentation"
394419
- name: EMBEXPR_BEGIN
395420
comment: "#{"
396-
- name: EMBEXPR_END
397-
comment: "}"
398421
- name: EMBVAR
399422
comment: "#"
400423
- name: EQUAL
@@ -461,20 +484,10 @@ tokens:
461484
comment: "def"
462485
- name: KEYWORD_DEFINED
463486
comment: "defined?"
464-
- name: KEYWORD_DO
465-
comment: "do"
466487
- name: KEYWORD_DO_LOOP
467488
comment: "do keyword for a predicate in a while, until, or for loop"
468-
- name: KEYWORD_ELSE
469-
comment: "else"
470-
- name: KEYWORD_ELSIF
471-
comment: "elsif"
472-
- name: KEYWORD_END
473-
comment: "end"
474489
- name: KEYWORD_END_UPCASE
475490
comment: "END"
476-
- name: KEYWORD_ENSURE
477-
comment: "ensure"
478491
- name: KEYWORD_FALSE
479492
comment: "false"
480493
- name: KEYWORD_FOR
@@ -483,8 +496,6 @@ tokens:
483496
comment: "if"
484497
- name: KEYWORD_IF_MODIFIER
485498
comment: "if in the modifier form"
486-
- name: KEYWORD_IN
487-
comment: "in"
488499
- name: KEYWORD_MODULE
489500
comment: "module"
490501
- name: KEYWORD_NEXT
@@ -497,8 +508,6 @@ tokens:
497508
comment: "or"
498509
- name: KEYWORD_REDO
499510
comment: "redo"
500-
- name: KEYWORD_RESCUE
501-
comment: "rescue"
502511
- name: KEYWORD_RESCUE_MODIFIER
503512
comment: "rescue in the modifier form"
504513
- name: KEYWORD_RETRY
@@ -509,8 +518,6 @@ tokens:
509518
comment: "self"
510519
- name: KEYWORD_SUPER
511520
comment: "super"
512-
- name: KEYWORD_THEN
513-
comment: "then"
514521
- name: KEYWORD_TRUE
515522
comment: "true"
516523
- name: KEYWORD_UNDEF
@@ -523,8 +530,6 @@ tokens:
523530
comment: "until"
524531
- name: KEYWORD_UNTIL_MODIFIER
525532
comment: "until in the modifier form"
526-
- name: KEYWORD_WHEN
527-
comment: "when"
528533
- name: KEYWORD_WHILE
529534
comment: "while"
530535
- name: KEYWORD_WHILE_MODIFIER
@@ -561,16 +566,12 @@ tokens:
561566
comment: "-="
562567
- name: MINUS_GREATER
563568
comment: "->"
564-
- name: NEWLINE
565-
comment: "a newline character outside of other tokens"
566569
- name: NUMBERED_REFERENCE
567570
comment: "a numbered reference to a capture group in the previous regular expression match"
568571
- name: PARENTHESIS_LEFT
569572
comment: "("
570573
- name: PARENTHESIS_LEFT_PARENTHESES
571574
comment: "( for a parentheses node"
572-
- name: PARENTHESIS_RIGHT
573-
comment: ")"
574575
- name: PERCENT
575576
comment: "%"
576577
- name: PERCENT_EQUAL
@@ -603,8 +604,6 @@ tokens:
603604
comment: "the beginning of a regular expression"
604605
- name: REGEXP_END
605606
comment: "the end of a regular expression"
606-
- name: SEMICOLON
607-
comment: ";"
608607
- name: SLASH
609608
comment: "/"
610609
- name: SLASH_EQUAL
@@ -649,6 +648,10 @@ tokens:
649648
comment: "a separator between words in a list"
650649
- name: __END__
651650
comment: "marker for the point in the file at which the parser should stop"
651+
- name: MISSING
652+
comment: "a token that was expected but not found"
653+
- name: NOT_PROVIDED
654+
comment: "a token that was not present but it is okay"
652655
flags:
653656
- name: ArgumentsNodeFlags
654657
values:

rakelib/lint.rake

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,6 @@ task :lint do
55
require "yaml"
66
config = YAML.safe_load_file(File.expand_path("../config.yml", __dir__))
77

8-
tokens = config.fetch("tokens")[4..-1].map { |token| token.fetch("name") }
9-
if tokens.sort != tokens
10-
warn("Tokens are not sorted alphabetically")
11-
12-
tokens.sort.zip(tokens).each do |(sorted, unsorted)|
13-
warn("Expected #{sorted} got #{unsorted}") if sorted != unsorted
14-
end
15-
16-
exit(1)
17-
end
18-
198
nodes = config.fetch("nodes")
209
names = nodes.map { |node| node.fetch("name") }
2110
if names.sort != names

snapshots/case_in_hash_key.txt

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
@ ProgramNode (location: (1,0)-(6,3))
2+
├── flags: ∅
3+
├── locals: []
4+
└── statements:
5+
@ StatementsNode (location: (1,0)-(6,3))
6+
├── flags: ∅
7+
└── body: (length: 1)
8+
└── @ CaseMatchNode (location: (1,0)-(6,3))
9+
├── flags: newline
10+
├── predicate:
11+
│ @ IntegerNode (location: (1,5)-(1,6))
12+
│ ├── flags: static_literal, decimal
13+
│ └── value: 1
14+
├── conditions: (length: 2)
15+
│ ├── @ InNode (location: (2,0)-(3,18))
16+
│ │ ├── flags: ∅
17+
│ │ ├── pattern:
18+
│ │ │ @ IntegerNode (location: (2,3)-(2,4))
19+
│ │ │ ├── flags: static_literal, decimal
20+
│ │ │ └── value: 2
21+
│ │ ├── statements:
22+
│ │ │ @ StatementsNode (location: (3,2)-(3,18))
23+
│ │ │ ├── flags: ∅
24+
│ │ │ └── body: (length: 1)
25+
│ │ │ └── @ CallNode (location: (3,2)-(3,18))
26+
│ │ │ ├── flags: newline
27+
│ │ │ ├── receiver:
28+
│ │ │ │ @ ConstantReadNode (location: (3,2)-(3,3))
29+
│ │ │ │ ├── flags: ∅
30+
│ │ │ │ └── name: :A
31+
│ │ │ ├── call_operator_loc: (3,3)-(3,4) = "."
32+
│ │ │ ├── name: :print
33+
│ │ │ ├── message_loc: (3,4)-(3,9) = "print"
34+
│ │ │ ├── opening_loc: ∅
35+
│ │ │ ├── arguments:
36+
│ │ │ │ @ ArgumentsNode (location: (3,10)-(3,18))
37+
│ │ │ │ ├── flags: contains_keywords
38+
│ │ │ │ └── arguments: (length: 1)
39+
│ │ │ │ └── @ KeywordHashNode (location: (3,10)-(3,18))
40+
│ │ │ │ ├── flags: symbol_keys
41+
│ │ │ │ └── elements: (length: 1)
42+
│ │ │ │ └── @ AssocNode (location: (3,10)-(3,18))
43+
│ │ │ │ ├── flags: ∅
44+
│ │ │ │ ├── key:
45+
│ │ │ │ │ @ SymbolNode (location: (3,10)-(3,18))
46+
│ │ │ │ │ ├── flags: static_literal, forced_us_ascii_encoding
47+
│ │ │ │ │ ├── opening_loc: ∅
48+
│ │ │ │ │ ├── value_loc: (3,10)-(3,17) = "message"
49+
│ │ │ │ │ ├── closing_loc: (3,17)-(3,18) = ":"
50+
│ │ │ │ │ └── unescaped: "message"
51+
│ │ │ │ ├── value:
52+
│ │ │ │ │ @ ImplicitNode (location: (3,10)-(3,18))
53+
│ │ │ │ │ ├── flags: ∅
54+
│ │ │ │ │ └── value:
55+
│ │ │ │ │ @ CallNode (location: (3,10)-(3,18))
56+
│ │ │ │ │ ├── flags: ignore_visibility
57+
│ │ │ │ │ ├── receiver: ∅
58+
│ │ │ │ │ ├── call_operator_loc: ∅
59+
│ │ │ │ │ ├── name: :message
60+
│ │ │ │ │ ├── message_loc: (3,10)-(3,17) = "message"
61+
│ │ │ │ │ ├── opening_loc: ∅
62+
│ │ │ │ │ ├── arguments: ∅
63+
│ │ │ │ │ ├── closing_loc: ∅
64+
│ │ │ │ │ └── block: ∅
65+
│ │ │ │ └── operator_loc: ∅
66+
│ │ │ ├── closing_loc: ∅
67+
│ │ │ └── block: ∅
68+
│ │ ├── in_loc: (2,0)-(2,2) = "in"
69+
│ │ └── then_loc: ∅
70+
│ └── @ InNode (location: (4,0)-(5,18))
71+
│ ├── flags: ∅
72+
│ ├── pattern:
73+
│ │ @ IntegerNode (location: (4,3)-(4,4))
74+
│ │ ├── flags: static_literal, decimal
75+
│ │ └── value: 3
76+
│ ├── statements:
77+
│ │ @ StatementsNode (location: (5,2)-(5,18))
78+
│ │ ├── flags: ∅
79+
│ │ └── body: (length: 1)
80+
│ │ └── @ CallNode (location: (5,2)-(5,18))
81+
│ │ ├── flags: newline
82+
│ │ ├── receiver:
83+
│ │ │ @ ConstantReadNode (location: (5,2)-(5,3))
84+
│ │ │ ├── flags: ∅
85+
│ │ │ └── name: :A
86+
│ │ ├── call_operator_loc: (5,3)-(5,4) = "."
87+
│ │ ├── name: :print
88+
│ │ ├── message_loc: (5,4)-(5,9) = "print"
89+
│ │ ├── opening_loc: ∅
90+
│ │ ├── arguments:
91+
│ │ │ @ ArgumentsNode (location: (5,10)-(5,18))
92+
│ │ │ ├── flags: contains_keywords
93+
│ │ │ └── arguments: (length: 1)
94+
│ │ │ └── @ KeywordHashNode (location: (5,10)-(5,18))
95+
│ │ │ ├── flags: symbol_keys
96+
│ │ │ └── elements: (length: 1)
97+
│ │ │ └── @ AssocNode (location: (5,10)-(5,18))
98+
│ │ │ ├── flags: ∅
99+
│ │ │ ├── key:
100+
│ │ │ │ @ SymbolNode (location: (5,10)-(5,18))
101+
│ │ │ │ ├── flags: static_literal, forced_us_ascii_encoding
102+
│ │ │ │ ├── opening_loc: ∅
103+
│ │ │ │ ├── value_loc: (5,10)-(5,17) = "message"
104+
│ │ │ │ ├── closing_loc: (5,17)-(5,18) = ":"
105+
│ │ │ │ └── unescaped: "message"
106+
│ │ │ ├── value:
107+
│ │ │ │ @ ImplicitNode (location: (5,10)-(5,18))
108+
│ │ │ │ ├── flags: ∅
109+
│ │ │ │ └── value:
110+
│ │ │ │ @ CallNode (location: (5,10)-(5,18))
111+
│ │ │ │ ├── flags: ignore_visibility
112+
│ │ │ │ ├── receiver: ∅
113+
│ │ │ │ ├── call_operator_loc: ∅
114+
│ │ │ │ ├── name: :message
115+
│ │ │ │ ├── message_loc: (5,10)-(5,17) = "message"
116+
│ │ │ │ ├── opening_loc: ∅
117+
│ │ │ │ ├── arguments: ∅
118+
│ │ │ │ ├── closing_loc: ∅
119+
│ │ │ │ └── block: ∅
120+
│ │ │ └── operator_loc: ∅
121+
│ │ ├── closing_loc: ∅
122+
│ │ └── block: ∅
123+
│ ├── in_loc: (4,0)-(4,2) = "in"
124+
│ └── then_loc: ∅
125+
├── else_clause: ∅
126+
├── case_keyword_loc: (1,0)-(1,4) = "case"
127+
└── end_keyword_loc: (6,0)-(6,3) = "end"

0 commit comments

Comments
 (0)