@@ -83,11 +83,48 @@ howl.aux.lpeg_lexer ->
8383
8484 decorator = c ' preproc' , P ' @' * name * ( ' .' * name) ^ 0
8585
86+ f_prefix = c ' special' , any {
87+ S ' rR' * S ' fF'
88+ S ' fF' * S ' rR'
89+ S ' fF'
90+ }
91+
92+ format_conv = c( ' operator' , P ' !' ) * c( ' special' , S ' sra' )
93+ format_number = any {
94+ c ' number' , integer
95+ c( ' operator' , P ' {' ) * ( - P ' }' * V ' all' ) * c( ' operator' , P ' }' )
96+ }
97+ format_spec = c( ' operator' , ' :' ) * sequence {
98+ ( c( ' string' , P 1 ) ^- 1 * c ' operator' , S ' <>=^' ) ^- 1 -- fill and align
99+ ( P ' ' + c ' operator' , S ' +-' ) ^- 1 -- sign
100+ c( ' operator' , P ' #' ) ^- 1 -- #
101+ c( ' number' , P ' 0' ) ^- 1 -- 0
102+ format_number^- 1 -- width
103+ c( ' operator' , P ' ,' ) ^- 1 -- ,
104+ ( c( ' operator' , P ' .' ) * format_number) ^- 1 -- .precision
105+ c( ' special' , S ' bcdeEfFgGnosxX%' ) ^- 1 -- type
106+ }
107+
108+ gen_string_interpolation = ( type ) ->
109+ sequence {
110+ ( - ( P ' }' + format_conv + format_spec) * ( V ' all' + 1 )) ^ 1
111+ format_conv^- 1
112+ format_spec^- 1
113+ c ' operator' , ' }'
114+ V " #{type}q_string_chunk"
115+ }
116+
117+ gen_string_chunk = ( quote, type ) ->
118+ sequence {
119+ c ' string' , scan_to( P ( quote) + # P ' {' , P ' \\ ' )
120+ V " #{type}q_interpolation" ^ 0
121+ }
122+
86123 P {
87124 ' all'
88125
89126 all : any {
90- string,
127+ V ' string' ,
91128 comment,
92129 number,
93130 operator,
@@ -100,4 +137,24 @@ howl.aux.lpeg_lexer ->
100137 identifier,
101138 decorator
102139 }
140+
141+ tsq_interpolation : gen_string_interpolation ' ts'
142+ tdq_interpolation : gen_string_interpolation ' td'
143+ sq_interpolation : gen_string_interpolation ' s'
144+ dq_interpolation : gen_string_interpolation ' d'
145+ tsq_string_chunk : gen_string_chunk " '''" , ' ts'
146+ tdq_string_chunk : gen_string_chunk ' """' , ' td'
147+ sq_string_chunk : gen_string_chunk " '" , ' s'
148+ dq_string_chunk : gen_string_chunk ' "' , ' d'
149+ f_string : any {
150+ capture( ' string' , " '''" ) * V ' tsq_string_chunk'
151+ capture( ' string' , ' """' ) * V ' tdq_string_chunk'
152+ capture( ' string' , " '" ) * V ' sq_string_chunk'
153+ capture( ' string' , ' "' ) * V ' dq_string_chunk'
154+ }
155+
156+ string : any {
157+ f_prefix * V ' f_string'
158+ string
159+ }
103160 }
0 commit comments