问题描述
我希望将FParsec用于类似Python的语言,基于缩进.
I wish to use FParsec for a python-like language, indentation-based.
我知道这必须在词汇化阶段完成,但是FParsec没有词汇化阶段.是否可以使用FParsec,或者在词法分析后如何喂食它?
I understand that this must be done in the lexing phase, but FParsec don't have a lexing phase. Is possible to use FParsec, or, how can feed it after lexing?
P.D:我是F#的新手,但是有其他语言的经验
P.D: I'm new at F#, but experienced in other languages
推荐答案
是的,有可能.
此处是相关文章 FParsec作者.如果您想进一步研究该主题,这篇论文可能值得一读.该论文指出,基于Parsec(用于激发FParsec的解析器组合器),存在多个用于缩进感知解析的程序包.
Here is a relevant article by FParsec author. If you want to go deeper on the subject, this paper might worth a read. The paper points out that there are multiple packages for indentation-aware parsing that based on Parsec, the parser combinator that inspires FParsec.
FParsec没有单独的词法分析阶段,但是它将词法分析和解析融合到一个阶段.与解析器生成器(fslex/fsyacc)相比,使用解析器组合器(FParsec)更好地进行IMO缩进感知的解析.原因是您需要手动跟踪当前的缩进并根据上下文报告正确的错误消息.
FParsec doesn't have a separate lexing phase but instead it fuses lexing and parsing to a single phase. IMO indentation-aware parsing is better to be done with parser combinators (FParsec) than parser generators (fslex/fsyacc). The reason is that you need to manually track current indentation and report good error messages based on contexts.
这篇关于可以解析“越位"消息. (基于缩进)的语言与fparsec?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!