OCamllex 匹配行首?
我正在用 ocamllex 在 OCaml 中编写一种玩具编程语言,并试图使该语言对缩进更改敏感,python 风格,但在将行开头与 ocamllex 的正则表达式规则匹配时遇到问题。我习惯使用 ^
来匹配行的开头,但在 OCaml 中这是字符串连接运算符。不幸的是,谷歌搜索对我来说并没有出现太多:(有人知道这是如何工作的吗?
I am messing around writing a toy programming language in OCaml with ocamllex, and was trying to make the language sensitive to indentation changes, python-style, but am having a problem matching the beginning of a line with ocamllex's regex rules. I am used to using ^
to match the beginning of a line, but in OCaml that is the string concat operator. Google searches haven't been turning up much for me unfortunately :( Anyone know how this would work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定是否明确支持零长度匹配符号(例如 Perl 样式正则表达式中的
^
,它匹配位置而不是子字符串)。但是,您应该能够让您的词法分析器将换行符转换为显式标记,如下所示:parser.mly
lexer.mll
这未经测试,但总体思路是:
int
传递警告:您需要预处理输入以从单个
\n 如果它不包含一个。
I'm not sure if there is explicit support for zero-length matching symbols (like
^
in Perl-style regular expressions, which matches a position rather than a substring). However, you should be able to let your lexer turn newlines into an explicit token, something like this:parser.mly
lexer.mll
This is untested, but the general idea is:
int
Caveat: you will need to preprocess your input to start with a single
\n
if it doesn't contain one.