Fork me on GitHub
#instaparse
<
2018-05-30
>
fabrao04:05:47

Hello all, I´m doing parser for fixed width with instaparse and the code is

(->>
   ((insta/parser
     "VALOR = CODIGO BARRAS
CODIGO = 2DIGIT
BARRAS = 3DIGIT
" :input-format :abnf) "12334")
   (insta/transform {:DIGIT (comp str)}))
How do I concat the "DIGITs" and keep CODIGO and BARRAS?

aengelberg06:05:22

@fabrao try adding transform entries for :CODIGO (partial apply str) :BARRAS (partial apply str)

fabrao12:05:42

@aengelberg it did not work, this keep showing [:VALOR [:DIGIT "1"]:DIGIT2 [:DIGIT "3"][:DIGIT "3"]:DIGIT4]

fabrao12:05:13

I had to change to

((insta/parser
     "VALOR = CODIGO BARRAS
CODIGO = #'.{3}'
BARRAS = #'.{2}'
") "12334")