Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More bugs with 3.07+2 #8330

Closed
vicuna opened this issue Oct 21, 2003 · 1 comment
Closed

More bugs with 3.07+2 #8330

vicuna opened this issue Oct 21, 2003 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Oct 21, 2003

Original bug ID: 1886
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

#1 Camlp4 syntax extension pa_ocamllex
pa_ocamllex does not support rules with formal parameters. I removed my
pa_ocamllex code from the module where it was embedded and placed it
into a .mll file, which was then compiled with ocamllex without any problem.

Here is the code as it appears now in xcaml_lexer.mll. Previously, all
'let' and 'rule' bindings were prefixed by the pa_ocamllex keyword.
let dollar = "\$"
let base_char = [^'$''\n''<']
let base_text = (base_char | dollar | ('<' [^'?'])) +
let xcaml_char = [^'$''\n''>''?']
let xcaml_text = (xcaml_char | dollar | ('?' [^'>']) )+
let dollar_expr_char = [^'\n'')']
let dollar_expr_text = (dollar_expr_char | (')' [^'$']) )+
let eol = '\n'
let white_char = [' ''\t''\r']
let white = white_char +
let id = ['A'-'Z''a'-'z''0'-'9''-''_''.']+

rule base_lexer accu line = parse
| (white eol) as newline { [< 'Base(newline); base_lexer accu (succ
line) lexbuf >] }
| "<?xcaml" { [< stream_of_queue accu; 'Line(line);
xcaml_lexer line lexbuf >] }
| base_text as base_line { [< 'Base(base_line); base_lexer accu line
lexbuf >] }
| '$' (id as name) { Queue.add (Dollar(dollar_var name)) accu; [<
'Base("%s"); base_lexer accu line lexbuf >] }
| "$#" (id as name) { Queue.add (Dollar(hash_var name)) accu; [<
'Base("%s"); base_lexer accu line lexbuf >] }
| "$!" (id as name) { Queue.add (Dollar(bang_var name)) accu; [<
'Base("%s"); base_lexer accu line lexbuf >] }
| "$(" { let code, line = dollar_expr_lexer line
(Buffer.create 128) lexbuf in
Queue.add (Line(line)) accu;
Queue.add (Dollar(code)) accu;
[< 'Base("%s"); base_lexer accu line lexbuf >] }

and xcaml_lexer line = parse
| (white eol) as newline { [< 'Code(newline); xcaml_lexer
(succ line) lexbuf >] }
| xcaml_text as code_line { [< 'Code(code_line); xcaml_lexer
line lexbuf >] }
| '$' (id as name) { [< 'Code(dollar_var name); xcaml_lexer
line lexbuf >] }
| '$' (id as name) '?' { [< 'Code(dollar_var_ex name); xcaml_lexer
line lexbuf >] }
| "$#" (id as name) { [< 'Code(hash_var name); xcaml_lexer
line lexbuf >] }
| "$#" (id as name) '?' { [< 'Code(hash_var_ex name); xcaml_lexer
line lexbuf >] }
| "$!" (id as name) { [< 'Code(bang_var name); xcaml_lexer
line lexbuf >] }
| "$!" (id as name) '?' { [< 'Code(bang_var_ex name); xcaml_lexer
line lexbuf >] }
| "?>" { [< 'Line(line); base_lexer (Queue.create ())
line lexbuf >] }

and dollar_expr_lexer buf line = parse
| (white eol) as newline { Buffer.add buf newline; dollar_expr_lexer buf
(succ line) lexbuf }
| dollar_expr_text as code_line { Buffer.add buf code_line;
dollar_expr_lexer buf line lexbuf }
| ")$" { (Buffer.contents buf),line }


#2 ocamlyacc does not generate correct mli files when the header and
trailer contain module type definitions and module implementations. I am
attaching sample code. I realize I am using ocamlyacc for some really
weird stuff, but given that ocamlc -i generates the correct signatures,
add the functionality to ocamlyacc might be worth considering.

Have fun!

Alex


%{
(*

  •                   Xcaml-lib
    
  •             Copyright (c) 2003 Baretta SRL
    
  •             Via Lago d'Orta 3
    
  •             20098 San Giuliano Milanese -- Italy
    
  • This code is free software. You may use it, modify it,
  • and redistribute it under the terms of the
  • GNU General Public License, Version 2. You may obtain
  • a copy of this license by writing to
  • Free Software Foundation, Inc.
  • 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  • $Id$

*)

open Batched_queue
open Printf

let add buf s = Buffer.add_string buf s

let open_printf = "printf ""
let open_write = "write ""
let close_printf = "" "
let close_write = close_printf

module type PARSER_PARAMS = sig val filename : string end
module type PARSER_TYPE = sig
val prog: (Lexing.lexbuf -> token) -> Lexing.lexbuf -> (string -> unit) -> unit
end
module Parser (Params:PARSER_PARAMS) : PARSER_TYPE = struct

%}

%token Line
%token Base Dollar Code

%nonassoc shift
%right Dollar Base
%left Line Code

%start prog

%type <(string -> unit) -> unit > prog

%%

prog:
| xcaml prog {fun out -> $1 out; $2 out }
| text prog {fun out -> $1 out; $2 out }
| {fun out -> ()}
;

xcaml:
| xcaml_elem %prec shift {fun out -> out $1}
| xcaml_elem xcaml {fun out -> out $1; $2 out}
;

xcaml_elem:
| Line {sprintf "\n# %d "%s"\n" $1 Params.filename }
| Code {$1}
;

text:
| simple_text %prec shift {fun out -> out open_write ; $1 out; out close_write}
| dollar_text {fun out -> out open_printf; $1 out}
;

simple_text:
| simple_text simple_elem {fun out -> $1 out; out $2}
| simple_elem {fun out -> out $1}
;

simple_elem:
| Base {$1}
;

dollar_text:
| simple_text dollar_elems
{fun out -> $1 out; out close_printf; $2 out}
;

dollar_elems:
| dollar_elem dollar_elems {fun out -> out $1; $2 out }
| dollar_elem {fun out -> out $1}

dollar_elem:
| Dollar {$1}
;

%%

end



@vicuna
Copy link
Author

vicuna commented Jul 13, 2004

Comment author: administrator

#1: in 3.08 pa_ocamllex is "unmaintained"; maybe someone will pick maintenance.
#2 is normal behavior: ocamlyacc doesn't export definitions found in header and
trailer code (it cannot guess what to put in the generated .mli file).

@vicuna vicuna closed this as completed Jul 13, 2004
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant