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?
I am messing around writing a toy programming language in OCaml with ocamllex, and
Share
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:
intCaveat: you will need to preprocess your input to start with a single
\nif it doesn’t contain one.