#360: Fix inclusion
------------------------+---------------------------------------------------
 Reporter:  toots       |       Owner:  admin   
     Type:  Bugs        |      Status:  new     
 Priority:  10          |   Milestone:  1.0 beta
Component:  Liquidsoap  |     Version:          
 Keywords:              |         Mac:  1       
    Linux:  1           |      Netbsd:  1       
    Other:  1           |     Freebsd:  1       
------------------------+---------------------------------------------------

Comment(by toots):

 Possible fix:
 {{{

 Index: lang/lang_lexer.mll
 ===================================================================
 --- lang/lang_lexer.mll (révision 7317)
 +++ lang/lang_lexer.mll (copie de travail)
 @@ -113,6 +113,7 @@
    | "%ifdef"   { PP_IFDEF }
    | "%endif"   { PP_ENDIF }
    | "%include" { PP_INCLUDE }
 +  | "%open"    { PP_OPEN }

    | eof { EOF }

 Index: lang/lang_pp.ml
 ===================================================================
 --- lang/lang_pp.ml     (révision 7317)
 +++ lang/lang_pp.ml     (copie de travail)
 @@ -104,6 +104,7 @@
            copy_lexbuf top_lexbuf lexbuf ;
            token
      in
 +    let opened_modules = Hashtbl.create 3 in
        match tokenizer () with
          | Lang_parser.PP_INCLUDE ->
              let new_lexbuf =
 @@ -125,6 +126,30 @@
              in
                Stack.push new_lexbuf state ;
                token top_lexbuf
 +        | Lang_parser.PP_OPEN ->
 +            let modname =
 +              match tokenizer () with
 +                | Lang_parser.STRING s -> s
 +                | _ -> failwith "expected a string after %open"
 +            in
 +            if not (Hashtbl.mem opened_modules modname) then
 +             begin
 +              let filename =
 +                Printf.sprintf "%s/%s.liq" Configure.libs_dir modname
 +              in
 +              let channel = open_in filename in
 +              let new_lexbuf = Lexing.from_channel channel in
 +              Stack.push channel in_channels ;
 +              new_lexbuf.Lexing.lex_start_p <-
 +                  { new_lexbuf.Lexing.lex_start_p with
 +                      Lexing.pos_fname = filename } ;
 +              new_lexbuf.Lexing.lex_curr_p <-
 +                  { new_lexbuf.Lexing.lex_curr_p with
 +                      Lexing.pos_fname = filename } ;
 +              Hashtbl.add opened_modules modname true ;
 +              Stack.push new_lexbuf state
 +             end ;
 +            token top_lexbuf
          | Lang_parser.EOF ->
              if Stack.length state = 1 then Lang_parser.EOF else begin
                ignore (Stack.pop state) ;
 Index: lang/lang_parser.mly
 ===================================================================
 --- lang/lang_parser.mly        (révision 7317)
 +++ lang/lang_parser.mly        (copie de travail)
 @@ -125,7 +125,7 @@
  %token MINUS
  %token NOT
  %token REF GET SET
 -%token PP_IFDEF PP_ENDIF PP_ENDL PP_INCLUDE PP_DEF
 +%token PP_IFDEF PP_ENDIF PP_ENDL PP_INCLUDE PP_OPEN PP_DEF
  %token <string list> PP_COMMENT

  %left YIELDS
 }}}

 That way, you put a {{{%open utils}}} in {{{externals.liq}}} and you are
 sure utils is loaded before externals.

 A related issue is whether or not all files in the libdir should be opened
 by default. If we split them, maybe it make sense to consider a core set
 which is loaded by default, say pervasives to really copy ocaml, and then
 other which are not necessarily loaded by default..

-- 
Ticket URL: <http://savonet.rastageeks.org/ticket/360#comment:4>
Savonet <http://savonet.rastageeks.org/>
Let's program our stream !
------------------------------------------------------------------------------

_______________________________________________
Savonet-trac mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/savonet-trac

Reply via email to