User state in Parsec

↘锁芯ラ 提交于 2019-12-03 10:21:45

Unfortunately, Yuras' suggestion of updateParserState is not optimal (you'd use that function if you're looking to modify Parsec's internal state as well); instead you should pass a function that works over your custom user state (i.e. of type u -> u) to modifyState, such as in this example:

expr  = do
  x <- identifier
  modifyState (+1)
  -- ^ in this example, our type u is Int
  return (Id x)

or use any combination of the getState and putState functions. For your case, you'd do something like:

modifyState (Set.insert v)

See this link for more info.

For a more tutorial-like introduction to working with user state in Parsec, this document, though old, should be relevant.

You can use updateParserState

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!