Harmonize names in dune and jbuild lexers
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
e3aa13424d
commit
d7ab3d962c
|
@ -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 }
|
||||
| "\\>"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"|}
|
||||
|
|
Loading…
Reference in New Issue