-
-
Save ThePhD/8d516eeadb3ca6629b1a12435555788c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ open Parser } | |
(* handle windows newlines *) | |
let eol = '\r'? '\n' | |
(* state variables: line number, etc. *) | |
let line_num = ref 1 | |
(* the basic text eater *) | |
(* we save all the characters that we see, | |
we encounter the preprocessor starter *) | |
rule token = parse | |
| '#' { preprocessor_token lexbuf } | |
| eol { incr line_num; token lexbuf } | |
| eof { EOF } | |
| _ as c { TEXT(c) } | |
(* The actual preprocessor tokens *) | |
(* Here, we see that we just capture | |
string expressions, dot-delimeted ident names, | |
macro continuation lines and more *) | |
and preprocessor_token = parse | |
| "import" { IMPORT } | |
| "strings" { STRINGS } | |
| '"'(_* as s)'"' { STRING(s) } | |
| '.' { DOT } | |
| ident { IDENTIFIER(s) } | |
| eol '#' { incr line_num; CONTINUE } | |
| eol | eof { EOF; token lexbuf } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment