Skip to content

Commit d3e473b

Browse files
committed
📖 Internally document lex states
1 parent fff6dc6 commit d3e473b

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

lib/net/imap/response_parser.rb

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,30 +36,31 @@ def parse(str)
3636

3737
# :stopdoc:
3838

39-
EXPR_BEG = :EXPR_BEG
40-
EXPR_DATA = :EXPR_DATA
41-
EXPR_TEXT = :EXPR_TEXT
42-
EXPR_RTEXT = :EXPR_RTEXT
43-
EXPR_CTEXT = :EXPR_CTEXT
44-
45-
T_SPACE = :SPACE
46-
T_NIL = :NIL
47-
T_NUMBER = :NUMBER
48-
T_ATOM = :ATOM
49-
T_QUOTED = :QUOTED
50-
T_LPAR = :LPAR
51-
T_RPAR = :RPAR
52-
T_BSLASH = :BSLASH
53-
T_STAR = :STAR
54-
T_LBRA = :LBRA
55-
T_RBRA = :RBRA
56-
T_LITERAL = :LITERAL
57-
T_PLUS = :PLUS
58-
T_PERCENT = :PERCENT
59-
T_CRLF = :CRLF
60-
T_EOF = :EOF
61-
T_TEXT = :TEXT
62-
39+
EXPR_BEG = :EXPR_BEG # the default, used in most places
40+
EXPR_DATA = :EXPR_DATA # envelope, body(structure), namespaces
41+
EXPR_TEXT = :EXPR_TEXT # text, after 'resp-text-code "]"'
42+
EXPR_RTEXT = :EXPR_RTEXT # resp-text, before "["
43+
EXPR_CTEXT = :EXPR_CTEXT # resp-text-code, after 'atom SP'
44+
45+
T_SPACE = :SPACE # atom special
46+
T_ATOM = :ATOM # atom (subset of astring chars)
47+
T_NIL = :NIL # subset of atom and label
48+
T_NUMBER = :NUMBER # subset of atom
49+
T_LBRA = :LBRA # subset of atom
50+
T_PLUS = :PLUS # subset of atom; tag special
51+
T_RBRA = :RBRA # atom special; resp_special; valid astring char
52+
T_QUOTED = :QUOTED # starts/end with atom special
53+
T_BSLASH = :BSLASH # atom special; quoted special
54+
T_LPAR = :LPAR # atom special; paren list delimiter
55+
T_RPAR = :RPAR # atom special; paren list delimiter
56+
T_STAR = :STAR # atom special; list wildcard
57+
T_PERCENT = :PERCENT # atom special; list wildcard
58+
T_LITERAL = :LITERAL # starts with atom special
59+
T_CRLF = :CRLF # atom special; text special; quoted special
60+
T_TEXT = :TEXT # any char except CRLF
61+
T_EOF = :EOF # end of response string
62+
63+
# the default, used in most places
6364
BEG_REGEXP = /\G(?:\
6465
(?# 1: SPACE )( +)|\
6566
(?# 2: NIL )(NIL)(?=[\x80-\xff(){ \x00-\x1f\x7f%*"\\\[\]+])|\
@@ -78,6 +79,7 @@ def parse(str)
7879
(?# 15: CRLF )(\r\n)|\
7980
(?# 16: EOF )(\z))/ni
8081

82+
# envelope, body(structure), namespaces
8183
DATA_REGEXP = /\G(?:\
8284
(?# 1: SPACE )( )|\
8385
(?# 2: NIL )(NIL)|\
@@ -87,13 +89,16 @@ def parse(str)
8789
(?# 6: LPAR )(\()|\
8890
(?# 7: RPAR )(\)))/ni
8991

92+
# text, after 'resp-text-code "]"'
9093
TEXT_REGEXP = /\G(?:\
9194
(?# 1: TEXT )([^\x00\r\n]*))/ni
9295

96+
# resp-text, before "["
9397
RTEXT_REGEXP = /\G(?:\
9498
(?# 1: LBRA )(\[)|\
9599
(?# 2: TEXT )([^\x00\r\n]*))/ni
96100

101+
# resp-text-code, after 'atom SP'
97102
CTEXT_REGEXP = /\G(?:\
98103
(?# 1: TEXT )([^\x00\r\n\]]*))/ni
99104

0 commit comments

Comments
 (0)