@@ -99,6 +99,45 @@ def parse(str)
99
99
100
100
Token = Struct . new ( :symbol , :value )
101
101
102
+ # atom = 1*ATOM-CHAR
103
+ #
104
+ # TODO: match atom entirely by regexp (in the "lexer")
105
+ def atom ; -combine_adjacent ( *ATOM_TOKENS ) end
106
+
107
+ # the #accept version of #atom
108
+ def atom? ; -combine_adjacent ( *ATOM_TOKENS ) if lookahead? ( *ATOM_TOKENS ) end
109
+
110
+ # Returns <tt>atom.upcase</tt>
111
+ def case_insensitive__atom ; -combine_adjacent ( *ATOM_TOKENS ) . upcase end
112
+
113
+ # Returns <tt>atom?&.upcase</tt>
114
+ def case_insensitive__atom?
115
+ -combine_adjacent ( *ATOM_TOKENS ) . upcase if lookahead? ( *ATOM_TOKENS )
116
+ end
117
+
118
+ # In addition to explicitly uses of +tagged-ext-label+, use this to match
119
+ # keywords when the grammar has not provided any extension syntax.
120
+ #
121
+ # Do *not* use this for labels where the grammar specifies extensions
122
+ # can be +atom+, even if all currently defined labels would match. For
123
+ # example response codes in +resp-text-code+.
124
+ #
125
+ # tagged-ext-label = tagged-label-fchar *tagged-label-char
126
+ # ; Is a valid RFC 3501 "atom".
127
+ # tagged-label-fchar = ALPHA / "-" / "_" / "."
128
+ # tagged-label-char = tagged-label-fchar / DIGIT / ":"
129
+ #
130
+ # TODO: add to lexer and only match tagged-ext-label
131
+ alias tagged_ext_label case_insensitive__atom
132
+ alias tagged_ext_label? case_insensitive__atom?
133
+
134
+ # Use #label or #label_in to assert specific known labels
135
+ # (+tagged-ext-label+ only, not +atom+).
136
+ def label ( word )
137
+ ( val = tagged_ext_label ) == word and return val
138
+ parse_error ( "unexpected atom %p, expected %p instead" , val , word )
139
+ end
140
+
102
141
def response
103
142
token = lookahead
104
143
case token . symbol
@@ -1333,10 +1372,6 @@ def case_insensitive_string
1333
1372
T_PLUS
1334
1373
]
1335
1374
1336
- def atom
1337
- -combine_adjacent ( *ATOM_TOKENS )
1338
- end
1339
-
1340
1375
# ASTRING-CHAR = ATOM-CHAR / resp-specials
1341
1376
# resp-specials = "]"
1342
1377
ASTRING_CHARS_TOKENS = [ *ATOM_TOKENS , T_RBRA ]
@@ -1408,12 +1443,18 @@ def nil_atom
1408
1443
# This advances @pos directly so it's safe before changing @lex_state.
1409
1444
def accept_space
1410
1445
if @token
1411
- shift_token if @token . symbol == T_SPACE
1446
+ if @token . symbol == T_SPACE
1447
+ shift_token
1448
+ " "
1449
+ end
1412
1450
elsif @str [ @pos ] == " "
1413
1451
@pos += 1
1452
+ " "
1414
1453
end
1415
1454
end
1416
1455
1456
+ alias SP? accept_space
1457
+
1417
1458
# The RFC is very strict about this and usually we should be too.
1418
1459
# But skipping spaces is usually a safe workaround for buggy servers.
1419
1460
#
0 commit comments