haskell - Avoid repetition in lexing when using parsec -


the parsec documentation has example of using maketokenparser build lexer:

module main   import text.parsec  import qualified text.parsec.token p  import text.parsec.language (haskelldef)   -- parser  ...   expr  =   parens expr        <|> identifier        <|> ...    -- lexer  lexer       = p.maketokenparser haskelldef       parens      = p.parens lexer  braces      = p.braces lexer  identifier  = p.identifier lexer  reserved    = p.reserved lexer  ... 

in "the lexer" block, every p.* applied lexer 1 can avoid repeating in "the parser" block. repeating every token still tedious. there way avoid repetition more? thinking implicitly apply lexer everywhere in "the parser", @ lost how to.

there general syntax pattern matching on records in haskell (i started noticing of p.parens, p.braces, etc. record projection functions - can see looking @ docs.) . can use here

p.tokenparser { p.parens      = parens               , p.braces      = braces               , p.identifier  = identifier               , p.reserved    = reserved               } = p.maketokenparser haskelldef  

edit

as erikr has pointed out, don't want some of parsers, want 29 of gentokenparser fields brought global scope, can enable recordwildcards extension , write

 p.tokenparser {..} = p.maketokenparser haskelldef 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -