The Felix compiler supports a new experimental option:

/////////////////////////////////////////
include "flx_faio";

var clock = Faio::mk_alarm_clock();
var i = 0;

proc foo(x: int, y: int) {
    print x; endl; print y; endl;
    Faio::sleep (clock,1.0);
    whilst i < 10 do print "hi"; endl; ++i; endl; done;
}

export proc foo of (int*int) as "foo";

/////////////
[EMAIL PROTECTED]:/work/felix/svn/felix/felix/trunk$ bin/flxg -Ilib xx1

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
; print y ; endl ; Faio :: sleep ( clock , 1.0 ) ; whilst i < 10 do
Syntax Error before token 53 in xx1.flx, line 10 col 22
print "hi" ; endl ; ++ i ; endl ; done ; }
   0: export proc foo of ( int * int
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Flx_exceptions.ParseError("Error parsing input")
PARSE ERROR
Unknown exception Parsing File
///////////////////////////////////////////////////
[EMAIL PROTECTED]:/work/felix/svn/felix/felix/trunk$ bin/flxg \
-Ilib --hash-include=lib/std.flx xx1
////////////////////////////////////////////

The option -hash-include=filename, which can be repeated
any number of times, creates a token stream by successively
preprocessing all the hash-include files, followed by the
main file.

In other words, the above code can be compiled even though
it uses a syntax extension 'whilst' defined in lib/std.flx

It also worked with --hash-include=lib/flx.flxh

You should note what happens is that the token stream
created by preprocessing is merely concatenated.
This is achieved by the Ocaml code:

  let pre_tokens  = 
    List.concat
    (List.map
      (fun filename -> 
        Flx_pretok.pre_tokens_of_filename 
          filename 
          basedir
          include_dirs 
          expand_expr
      )
      filenames
    )
  in

pre_tokens_of_filename looks like:

let pre_tokens_of_filename filename dirname incdirs expand_expr =
  let state = new Flx_lexstate.lexer_state filename dirname incdirs
expand_expr in
  let infile = open_in filename in
  let src = Lexing.from_channel infile in
  let toks = pre_tokens_of_lexbuf src state in
    close_in infile; 
    toks

Note that each file has a separate lexer state.

It is not clear if this hack is what we want.
However it does allow you to run scripts that do not
include the magic incantation

#include <flx.flxh>

at the top of the main file. Note you cannot omit the
summoning spell in included files (i.e. libraries),
only top level scripts: the effect isn't transitive.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to