@@ -326,6 +326,9 @@ def unescape_quoted(quoted)
326
326
# TODO: add to lexer and only match tagged-ext-label
327
327
def_token_matchers :tagged_ext_label , T_ATOM , T_NIL , send : :upcase
328
328
329
+ def_token_matchers :CRLF , T_CRLF
330
+ def_token_matchers :EOF , T_EOF
331
+
329
332
# atom = 1*ATOM-CHAR
330
333
# ATOM-CHAR = <any CHAR except atom-specials>
331
334
ATOM_TOKENS = [ T_ATOM , T_NUMBER , T_NIL , T_LBRA , T_PLUS ]
@@ -403,23 +406,25 @@ def case_insensitive__nstring
403
406
alias number64 number
404
407
alias number64? number?
405
408
409
+ # [RFC3501 & RFC9051:]
410
+ # response = *(continue-req / response-data) response-done
411
+ #
412
+ # For simplicity, response isn't interpreted as the combination of the
413
+ # three response types, but instead represents any individual server
414
+ # response. Our simplified interpretation is defined as:
415
+ # response = continue-req | response_data | response-tagged
416
+ #
417
+ # n.b: our "response-tagged" definition parses "greeting" too.
406
418
def response
407
- token = lookahead
408
- case token . symbol
409
- when T_PLUS
410
- result = continue_req
411
- when T_STAR
412
- result = response_untagged
413
- else
414
- result = response_tagged
415
- end
416
- while lookahead . symbol == T_SPACE
417
- # Ignore trailing space for Microsoft Exchange Server
418
- shift_token
419
- end
420
- match ( T_CRLF )
421
- match ( T_EOF )
422
- return result
419
+ resp = case lookahead! ( T_PLUS , T_STAR , *TAG_TOKENS ) . symbol
420
+ when T_PLUS then continue_req
421
+ when T_STAR then response_data
422
+ else response_tagged
423
+ end
424
+ accept_spaces # QUIRKY: Ignore trailing space (MS Exchange Server?)
425
+ CRLF!
426
+ EOF!
427
+ resp
423
428
end
424
429
425
430
# RFC3501 & RFC9051:
@@ -434,7 +439,7 @@ def continue_req
434
439
ContinuationRequest . new ( SP? ? resp_text : ResponseText ::EMPTY , @str )
435
440
end
436
441
437
- def response_untagged
442
+ def response_data
438
443
match ( T_STAR )
439
444
match ( T_SPACE )
440
445
token = lookahead
@@ -1566,10 +1571,10 @@ def nil_atom
1566
1571
#
1567
1572
# This advances @pos directly so it's safe before changing @lex_state.
1568
1573
def accept_spaces
1569
- shift_token if @token &. symbol == T_SPACE
1570
- if @str . index ( SPACES_REGEXP , @pos )
1574
+ return false unless SP?
1575
+ @str . index ( SPACES_REGEXP , @pos ) and
1571
1576
@pos = $~. end ( 0 )
1572
- end
1577
+ true
1573
1578
end
1574
1579
1575
1580
def next_token
0 commit comments