diff options
author | David Allsopp <david.allsopp@metastack.com> | 2022-04-24 11:44:19 +0100 |
---|---|---|
committer | David Allsopp <david.allsopp@metastack.com> | 2022-04-25 16:54:37 +0100 |
commit | ea647ca7d2ae0e2c898bde8d7ff4cf381c65ace6 (patch) | |
tree | 4240d8791d3f56740cf9864ade65bfe16d853a53 /tools | |
parent | 22f00d49d1c0bc20b64d10ad374fc967b75bbe62 (diff) | |
download | ocaml-ea647ca7d2ae0e2c898bde8d7ff4cf381c65ace6.tar.gz |
Only allow tabs in the emitters in "..." and `...`
Diffstat (limited to 'tools')
-rw-r--r-- | tools/cvt_emit.mll | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/tools/cvt_emit.mll b/tools/cvt_emit.mll index 396f644b9a..d5ea331317 100644 --- a/tools/cvt_emit.mll +++ b/tools/cvt_emit.mll @@ -15,7 +15,7 @@ { let first_item = ref false -let command_beginning = ref 0 +let lexeme_beginning = ref 0 let add_semicolon () = if !first_item @@ -36,7 +36,7 @@ let print_unescaped_string s = } rule main = parse - "`" { command_beginning := Lexing.lexeme_start lexbuf; + "`" { lexeme_beginning := Lexing.lexeme_start lexbuf; first_item := true; print_char '('; command lexbuf; @@ -44,13 +44,20 @@ rule main = parse main lexbuf } | "\\`" { print_string "`"; main lexbuf } + | '\t' { prerr_string "Invalid tab at character "; + prerr_int (Lexing.lexeme_start lexbuf); + prerr_newline(); + exit 2 } + | '"' { lexeme_beginning := Lexing.lexeme_start lexbuf; + print_char '"'; + string lexbuf } | eof { () } | _ { print_char(Lexing.lexeme_char lexbuf 0); main lexbuf } and command = parse "`" { () } | eof { prerr_string "Unterminated `...` at character "; - prerr_int !command_beginning; + prerr_int !lexeme_beginning; prerr_newline(); exit 2 } | "{" [^ '}'] * "}" @@ -79,6 +86,17 @@ and command = parse end; command lexbuf } +and string = parse + | '"' { print_char '"'; + main lexbuf } + | '\\' _ | [^ '\\' '"' ]+ + { print_string (Lexing.lexeme lexbuf); + string lexbuf } + | eof { prerr_string "Unterminated \"...\" at character "; + prerr_int !lexeme_beginning; + prerr_newline(); + exit 2 } + { let _ = main(Lexing.from_channel stdin) |