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 digit = ['0'-'9']
|
||||||
let hexdigit = ['0'-'9' 'a'-'f' 'A'-'F']
|
let hexdigit = ['0'-'9' 'a'-'f' 'A'-'F']
|
||||||
|
|
||||||
let atom_char_dune =
|
let atom_char =
|
||||||
[^ '%' ';' '(' ')' '"' '\000'-'\032' '\127'-'\255']
|
[^ '%' ';' '(' ')' '"' '\000'-'\032' '\127'-'\255']
|
||||||
|
|
||||||
(* rule for dune files *)
|
|
||||||
rule token = parse
|
rule token = parse
|
||||||
| newline
|
| newline
|
||||||
{ Lexing.new_line lexbuf; token lexbuf }
|
{ Lexing.new_line lexbuf; token lexbuf }
|
||||||
|
@ -24,17 +23,17 @@ rule token = parse
|
||||||
| '"'
|
| '"'
|
||||||
{ Buffer.clear escaped_buf;
|
{ Buffer.clear escaped_buf;
|
||||||
let start = Lexing.lexeme_start_p lexbuf in
|
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;
|
lexbuf.lex_start_p <- start;
|
||||||
Quoted_string s
|
Quoted_string s
|
||||||
}
|
}
|
||||||
| atom_char_dune+ as s
|
| atom_char+ as s
|
||||||
{ Token.Atom (Atom.of_string s) }
|
{ Token.Atom (Atom.of_string s) }
|
||||||
| _ as c { error lexbuf (Printf.sprintf "Invalid atom character '%c'" c) }
|
| _ as c { error lexbuf (Printf.sprintf "Invalid atom character '%c'" c) }
|
||||||
| eof
|
| eof
|
||||||
{ Eof }
|
{ Eof }
|
||||||
|
|
||||||
and dune_quoted_string = parse
|
and start_quoted_string = parse
|
||||||
| "\\|"
|
| "\\|"
|
||||||
{ block_string_start With_escape_sequences lexbuf }
|
{ block_string_start With_escape_sequences lexbuf }
|
||||||
| "\\>"
|
| "\\>"
|
||||||
|
|
|
@ -8,7 +8,7 @@ let blank = [' ' '\t' '\012']
|
||||||
let digit = ['0'-'9']
|
let digit = ['0'-'9']
|
||||||
let hexdigit = ['0'-'9' 'a'-'f' 'A'-'F']
|
let hexdigit = ['0'-'9' 'a'-'f' 'A'-'F']
|
||||||
|
|
||||||
let atom_char_jbuild =
|
let atom_char =
|
||||||
[^ ';' '(' ')' '"' ' ' '\t' '\r' '\n' '\012']
|
[^ ';' '(' ')' '"' ' ' '\t' '\r' '\n' '\012']
|
||||||
|
|
||||||
(* rule for jbuild files *)
|
(* rule for jbuild files *)
|
||||||
|
@ -29,7 +29,7 @@ rule token = parse
|
||||||
Quoted_string s
|
Quoted_string s
|
||||||
}
|
}
|
||||||
| "#|"
|
| "#|"
|
||||||
{ jbuild_block_comment lexbuf;
|
{ block_comment lexbuf;
|
||||||
token lexbuf
|
token lexbuf
|
||||||
}
|
}
|
||||||
| "#;"
|
| "#;"
|
||||||
|
@ -37,19 +37,19 @@ rule token = parse
|
||||||
| eof
|
| eof
|
||||||
{ 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;
|
{ lexbuf.lex_start_p <- start;
|
||||||
error lexbuf "jbuild_atoms cannot contain #|"
|
error lexbuf "jbuild atoms cannot contain #|"
|
||||||
}
|
}
|
||||||
| '|'+ '#'
|
| '|'+ '#'
|
||||||
{ lexbuf.lex_start_p <- start;
|
{ lexbuf.lex_start_p <- start;
|
||||||
error lexbuf "jbuild_atoms cannot contain |#"
|
error lexbuf "jbuild atoms cannot contain |#"
|
||||||
}
|
}
|
||||||
| ('#'+ | '|'+ | (atom_char_jbuild # ['|' '#'])) as s
|
| ('#'+ | '|'+ | (atom_char # ['|' '#'])) as s
|
||||||
{ jbuild_atom (if acc = "" then s else acc ^ s) start lexbuf
|
{ atom (if acc = "" then s else acc ^ s) start lexbuf
|
||||||
}
|
}
|
||||||
| ""
|
| ""
|
||||||
{ if acc = "" then
|
{ if acc = "" then
|
||||||
|
@ -86,11 +86,11 @@ and quoted_string_after_escaped_newline mode = parse
|
||||||
| [' ' '\t']*
|
| [' ' '\t']*
|
||||||
{ quoted_string mode lexbuf }
|
{ quoted_string mode lexbuf }
|
||||||
|
|
||||||
and jbuild_block_comment = parse
|
and block_comment = parse
|
||||||
| '"'
|
| '"'
|
||||||
{ Buffer.clear escaped_buf;
|
{ Buffer.clear escaped_buf;
|
||||||
ignore (quoted_string In_block_comment lexbuf : string);
|
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"
|
{ error lexbuf "unterminated block comment"
|
||||||
}
|
}
|
||||||
| _
|
| _
|
||||||
{ jbuild_block_comment lexbuf
|
{ block_comment lexbuf
|
||||||
}
|
}
|
||||||
|
|
||||||
and escape_sequence mode = parse
|
and escape_sequence mode = parse
|
||||||
|
|
|
@ -107,14 +107,14 @@ parse {|x#|y|}
|
||||||
[%%expect{|
|
[%%expect{|
|
||||||
- : parse_result =
|
- : parse_result =
|
||||||
Different
|
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|}
|
parse {|x|#y|}
|
||||||
[%%expect{|
|
[%%expect{|
|
||||||
- : parse_result =
|
- : parse_result =
|
||||||
Different
|
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"|}
|
parse {|"\a"|}
|
||||||
|
|
Loading…
Reference in New Issue