From d7ab3d962c9aedbd0f79e919c05e3c65cf6404f5 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 20 Jun 2018 19:37:08 +0630 Subject: [PATCH] Harmonize names in dune and jbuild lexers Signed-off-by: Rudi Grinberg --- src/usexp/dune_lexer.mll | 9 ++++----- src/usexp/jbuild_lexer.mll | 22 +++++++++++----------- test/unit-tests/sexp.mlt | 4 ++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/usexp/dune_lexer.mll b/src/usexp/dune_lexer.mll index 3bf74724..2e43b3da 100644 --- a/src/usexp/dune_lexer.mll +++ b/src/usexp/dune_lexer.mll @@ -8,10 +8,9 @@ let blank = [' ' '\t' '\012'] let digit = ['0'-'9'] let hexdigit = ['0'-'9' 'a'-'f' 'A'-'F'] -let atom_char_dune = +let atom_char = [^ '%' ';' '(' ')' '"' '\000'-'\032' '\127'-'\255'] -(* rule for dune files *) rule token = parse | newline { Lexing.new_line lexbuf; token lexbuf } @@ -24,17 +23,17 @@ rule token = parse | '"' { Buffer.clear escaped_buf; let start = Lexing.lexeme_start_p lexbuf in - let s = dune_quoted_string lexbuf in + let s = start_quoted_string lexbuf in lexbuf.lex_start_p <- start; Quoted_string s } - | atom_char_dune+ as s + | atom_char+ as s { Token.Atom (Atom.of_string s) } | _ as c { error lexbuf (Printf.sprintf "Invalid atom character '%c'" c) } | eof { Eof } -and dune_quoted_string = parse +and start_quoted_string = parse | "\\|" { block_string_start With_escape_sequences lexbuf } | "\\>" diff --git a/src/usexp/jbuild_lexer.mll b/src/usexp/jbuild_lexer.mll index 51376bd9..4a2d546e 100644 --- a/src/usexp/jbuild_lexer.mll +++ b/src/usexp/jbuild_lexer.mll @@ -8,7 +8,7 @@ let blank = [' ' '\t' '\012'] let digit = ['0'-'9'] let hexdigit = ['0'-'9' 'a'-'f' 'A'-'F'] -let atom_char_jbuild = +let atom_char = [^ ';' '(' ')' '"' ' ' '\t' '\r' '\n' '\012'] (* rule for jbuild files *) @@ -29,7 +29,7 @@ rule token = parse Quoted_string s } | "#|" - { jbuild_block_comment lexbuf; + { block_comment lexbuf; token lexbuf } | "#;" @@ -37,19 +37,19 @@ rule token = parse | eof { Eof } | "" - { jbuild_atom "" (Lexing.lexeme_start_p lexbuf) lexbuf } + { atom "" (Lexing.lexeme_start_p lexbuf) lexbuf } -and jbuild_atom acc start = parse +and atom acc start = parse | '#'+ '|' { lexbuf.lex_start_p <- start; - error lexbuf "jbuild_atoms cannot contain #|" + error lexbuf "jbuild atoms cannot contain #|" } | '|'+ '#' { lexbuf.lex_start_p <- start; - error lexbuf "jbuild_atoms cannot contain |#" + error lexbuf "jbuild atoms cannot contain |#" } - | ('#'+ | '|'+ | (atom_char_jbuild # ['|' '#'])) as s - { jbuild_atom (if acc = "" then s else acc ^ s) start lexbuf + | ('#'+ | '|'+ | (atom_char # ['|' '#'])) as s + { atom (if acc = "" then s else acc ^ s) start lexbuf } | "" { if acc = "" then @@ -86,11 +86,11 @@ and quoted_string_after_escaped_newline mode = parse | [' ' '\t']* { quoted_string mode lexbuf } -and jbuild_block_comment = parse +and block_comment = parse | '"' { Buffer.clear escaped_buf; ignore (quoted_string In_block_comment lexbuf : string); - jbuild_block_comment lexbuf + block_comment lexbuf } | "|#" { () @@ -99,7 +99,7 @@ and jbuild_block_comment = parse { error lexbuf "unterminated block comment" } | _ - { jbuild_block_comment lexbuf + { block_comment lexbuf } and escape_sequence mode = parse diff --git a/test/unit-tests/sexp.mlt b/test/unit-tests/sexp.mlt index 79db5495..cc42cb6d 100644 --- a/test/unit-tests/sexp.mlt +++ b/test/unit-tests/sexp.mlt @@ -107,14 +107,14 @@ parse {|x#|y|} [%%expect{| - : parse_result = Different - {jbuild = Error "jbuild_atoms cannot contain #|"; dune = Ok [(atom x#|y)]} + {jbuild = Error "jbuild atoms cannot contain #|"; dune = Ok [(atom x#|y)]} |}] parse {|x|#y|} [%%expect{| - : parse_result = Different - {jbuild = Error "jbuild_atoms cannot contain |#"; dune = Ok [(atom x|#y)]} + {jbuild = Error "jbuild atoms cannot contain |#"; dune = Ok [(atom x|#y)]} |}] parse {|"\a"|}