Merge branch 'contrib'
This commit is contained in:
commit
c218d06601
|
@ -24,6 +24,7 @@
|
||||||
*.toc
|
*.toc
|
||||||
*.tp
|
*.tp
|
||||||
*.vr
|
*.vr
|
||||||
|
*.swp
|
||||||
.hg/
|
.hg/
|
||||||
.hgignore
|
.hgignore
|
||||||
lexer.ml
|
lexer.ml
|
||||||
|
|
|
@ -4,6 +4,7 @@ Graydon Hoare <graydon@mozilla.com>
|
||||||
|
|
||||||
Other authors:
|
Other authors:
|
||||||
|
|
||||||
|
Adam Bozanich <adam.boz@gmail.com>
|
||||||
Andreas Gal <gal@mozilla.com>
|
Andreas Gal <gal@mozilla.com>
|
||||||
Brendan Eich <brendan@mozilla.org>
|
Brendan Eich <brendan@mozilla.org>
|
||||||
Chris Double <chris.double@double.co.nz>
|
Chris Double <chris.double@double.co.nz>
|
||||||
|
|
|
@ -775,7 +775,6 @@ and parse_type_item
|
||||||
let item = Ast.MOD_ITEM_type (effect, ty) in
|
let item = Ast.MOD_ITEM_type (effect, ty) in
|
||||||
(ident, span ps apos bpos (decl params item))
|
(ident, span ps apos bpos (decl params item))
|
||||||
|
|
||||||
|
|
||||||
and parse_mod_item (ps:pstate) : (Ast.ident * Ast.mod_item) =
|
and parse_mod_item (ps:pstate) : (Ast.ident * Ast.mod_item) =
|
||||||
let apos = lexpos ps in
|
let apos = lexpos ps in
|
||||||
let parse_lib_name ident =
|
let parse_lib_name ident =
|
||||||
|
@ -849,72 +848,35 @@ and parse_mod_item (ps:pstate) : (Ast.ident * Ast.mod_item) =
|
||||||
note_required_mod ps {lo=apos; hi=bpos} conv rlib item;
|
note_required_mod ps {lo=apos; hi=bpos} conv rlib item;
|
||||||
(ident, item)
|
(ident, item)
|
||||||
end
|
end
|
||||||
|
|
||||||
| USE ->
|
|
||||||
begin
|
|
||||||
bump ps;
|
|
||||||
let ident = ctxt "use mod: ident" Pexp.parse_ident ps in
|
|
||||||
let meta =
|
|
||||||
ctxt "use mod: meta" parse_optional_meta_pat ps ident
|
|
||||||
in
|
|
||||||
let bpos = lexpos ps in
|
|
||||||
let id = (span ps apos bpos ()).id in
|
|
||||||
let (path, items) =
|
|
||||||
ps.pstate_get_mod meta id ps.pstate_node_id ps.pstate_opaque_id
|
|
||||||
in
|
|
||||||
let bpos = lexpos ps in
|
|
||||||
expect ps SEMI;
|
|
||||||
let rlib =
|
|
||||||
REQUIRED_LIB_rust { required_libname = path;
|
|
||||||
required_prefix = ps.pstate_depth }
|
|
||||||
in
|
|
||||||
iflog ps
|
|
||||||
begin
|
|
||||||
fun _ ->
|
|
||||||
log ps "extracted mod from %s (binding to %s)"
|
|
||||||
path ident;
|
|
||||||
log ps "%a" Ast.sprintf_mod_items items;
|
|
||||||
end;
|
|
||||||
let item = decl [||] (Ast.MOD_ITEM_mod (empty_view, items)) in
|
|
||||||
let item = span ps apos bpos item in
|
|
||||||
note_required_mod ps {lo=apos; hi=bpos} CONV_rust rlib item;
|
|
||||||
(ident, item)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
| _ -> raise (unexpected ps)
|
| _ -> raise (unexpected ps)
|
||||||
|
|
||||||
|
and parse_mod_items_header_from_signature (ps:pstate) : Ast.mod_view =
|
||||||
|
let exports = Hashtbl.create 0 in
|
||||||
|
while (peek ps = EXPORT)
|
||||||
|
do
|
||||||
|
bump ps;
|
||||||
|
parse_export ps exports;
|
||||||
|
expect ps SEMI;
|
||||||
|
done;
|
||||||
|
if (Hashtbl.length exports) = 0
|
||||||
|
then htab_put exports Ast.EXPORT_all_decls ();
|
||||||
|
{empty_view with Ast.view_exports = exports}
|
||||||
|
|
||||||
and parse_mod_items_from_signature
|
and parse_mod_items_from_signature
|
||||||
(ps:pstate)
|
(ps:pstate)
|
||||||
: (Ast.mod_view * Ast.mod_items) =
|
: (Ast.mod_view * Ast.mod_items) =
|
||||||
let exports = Hashtbl.create 0 in
|
expect ps LBRACE;
|
||||||
let mis = Hashtbl.create 0 in
|
let view = parse_mod_items_header_from_signature ps in
|
||||||
let in_view = ref true in
|
let items = Hashtbl.create 0 in
|
||||||
expect ps LBRACE;
|
|
||||||
while not (peek ps = RBRACE)
|
while not (peek ps = RBRACE)
|
||||||
do
|
do
|
||||||
if !in_view
|
let (ident,item) = ctxt "mod items from sig: mod item"
|
||||||
then
|
parse_mod_item_from_signature ps
|
||||||
match peek ps with
|
in
|
||||||
EXPORT ->
|
htab_put items ident item;
|
||||||
bump ps;
|
|
||||||
parse_export ps exports;
|
|
||||||
expect ps SEMI;
|
|
||||||
| _ ->
|
|
||||||
in_view := false
|
|
||||||
else
|
|
||||||
let (ident, mti) = ctxt "mod items from sig: mod item"
|
|
||||||
parse_mod_item_from_signature ps
|
|
||||||
in
|
|
||||||
Hashtbl.add mis ident mti;
|
|
||||||
done;
|
done;
|
||||||
if (Hashtbl.length exports) = 0
|
|
||||||
then Hashtbl.add exports Ast.EXPORT_all_decls ();
|
|
||||||
expect ps RBRACE;
|
expect ps RBRACE;
|
||||||
({empty_view with Ast.view_exports = exports}, mis)
|
(view,items)
|
||||||
|
|
||||||
|
|
||||||
and parse_mod_item_from_signature (ps:pstate)
|
and parse_mod_item_from_signature (ps:pstate)
|
||||||
: (Ast.ident * Ast.mod_item) =
|
: (Ast.ident * Ast.mod_item) =
|
||||||
|
@ -1032,7 +994,6 @@ and expand_tags_to_stmts
|
||||||
(Ast.DECL_mod_item (ident, tag_item))))
|
(Ast.DECL_mod_item (ident, tag_item))))
|
||||||
id_items
|
id_items
|
||||||
|
|
||||||
|
|
||||||
and expand_tags_to_items
|
and expand_tags_to_items
|
||||||
(ps:pstate)
|
(ps:pstate)
|
||||||
(item:Ast.mod_item)
|
(item:Ast.mod_item)
|
||||||
|
@ -1043,7 +1004,6 @@ and expand_tags_to_items
|
||||||
(fun (ident, item) -> htab_put items ident item)
|
(fun (ident, item) -> htab_put items ident item)
|
||||||
id_items
|
id_items
|
||||||
|
|
||||||
|
|
||||||
and note_required_mod
|
and note_required_mod
|
||||||
(ps:pstate)
|
(ps:pstate)
|
||||||
(sp:span)
|
(sp:span)
|
||||||
|
@ -1123,48 +1083,89 @@ and parse_export
|
||||||
in
|
in
|
||||||
Hashtbl.add exports e ()
|
Hashtbl.add exports e ()
|
||||||
|
|
||||||
|
and parse_use
|
||||||
|
(ps:pstate)
|
||||||
|
: (Ast.ident * Ast.mod_item) =
|
||||||
|
bump ps;
|
||||||
|
let ident = ctxt "use mod: ident" Pexp.parse_ident ps in
|
||||||
|
let meta =
|
||||||
|
ctxt "use mod: meta" parse_optional_meta_pat ps ident
|
||||||
|
in
|
||||||
|
let apos = lexpos ps in
|
||||||
|
let bpos = lexpos ps in
|
||||||
|
let id = (span ps apos bpos ()).id in
|
||||||
|
let (path, items) =
|
||||||
|
ps.pstate_get_mod meta id ps.pstate_node_id ps.pstate_opaque_id
|
||||||
|
in
|
||||||
|
let bpos = lexpos ps in
|
||||||
|
expect ps SEMI;
|
||||||
|
let rlib =
|
||||||
|
REQUIRED_LIB_rust { required_libname = path;
|
||||||
|
required_prefix = ps.pstate_depth }
|
||||||
|
in
|
||||||
|
iflog ps
|
||||||
|
begin
|
||||||
|
fun _ ->
|
||||||
|
log ps "extracted mod from %s (binding to %s)"
|
||||||
|
path ident;
|
||||||
|
log ps "%a" Ast.sprintf_mod_items items;
|
||||||
|
end;
|
||||||
|
let item = decl [||] (Ast.MOD_ITEM_mod (empty_view, items)) in
|
||||||
|
let item = span ps apos bpos item in
|
||||||
|
note_required_mod ps {lo=apos; hi=bpos} CONV_rust rlib item;
|
||||||
|
(ident, item)
|
||||||
|
|
||||||
|
and parse_item_decl ps items fn =
|
||||||
|
let (ident, item) = fn ps in
|
||||||
|
htab_put items ident item;
|
||||||
|
expand_tags_to_items ps item items
|
||||||
|
|
||||||
|
and parse_mod_header (ps:pstate)
|
||||||
|
: (Ast.mod_view * Ast.mod_items) =
|
||||||
|
let imports = Hashtbl.create 0 in
|
||||||
|
let exports = Hashtbl.create 0 in
|
||||||
|
let items = Hashtbl.create 4 in
|
||||||
|
let rec loop () =
|
||||||
|
match peek ps with
|
||||||
|
IMPORT ->
|
||||||
|
bump ps;
|
||||||
|
parse_import ps imports;
|
||||||
|
expect ps SEMI;
|
||||||
|
loop ()
|
||||||
|
| EXPORT ->
|
||||||
|
bump ps;
|
||||||
|
parse_export ps exports;
|
||||||
|
expect ps SEMI;
|
||||||
|
loop ()
|
||||||
|
| USE ->
|
||||||
|
parse_item_decl ps items parse_use;
|
||||||
|
loop ()
|
||||||
|
| _ -> ()
|
||||||
|
in
|
||||||
|
loop ();
|
||||||
|
if (Hashtbl.length exports) = 0
|
||||||
|
then Hashtbl.add exports Ast.EXPORT_all_decls ();
|
||||||
|
let view = { Ast.view_imports = imports;
|
||||||
|
Ast.view_exports = exports }
|
||||||
|
in
|
||||||
|
(view, items)
|
||||||
|
|
||||||
and parse_mod_items
|
and parse_mod_items
|
||||||
(ps:pstate)
|
(ps:pstate)
|
||||||
(terminal:token)
|
(terminal:token)
|
||||||
: (Ast.mod_view * Ast.mod_items) =
|
: (Ast.mod_view * Ast.mod_items) =
|
||||||
ps.pstate_depth <- ps.pstate_depth + 1;
|
ps.pstate_depth <- ps.pstate_depth + 1;
|
||||||
let imports = Hashtbl.create 0 in
|
let (view, items) = parse_mod_header ps in
|
||||||
let exports = Hashtbl.create 0 in
|
|
||||||
let in_view = ref true in
|
|
||||||
let items = Hashtbl.create 4 in
|
|
||||||
while (not (peek ps = terminal))
|
while (not (peek ps = terminal))
|
||||||
do
|
do
|
||||||
if !in_view
|
parse_item_decl ps items parse_mod_item;
|
||||||
then
|
|
||||||
match peek ps with
|
|
||||||
IMPORT ->
|
|
||||||
bump ps;
|
|
||||||
parse_import ps imports;
|
|
||||||
expect ps SEMI;
|
|
||||||
| EXPORT ->
|
|
||||||
bump ps;
|
|
||||||
parse_export ps exports;
|
|
||||||
expect ps SEMI;
|
|
||||||
| _ ->
|
|
||||||
in_view := false
|
|
||||||
else
|
|
||||||
let (ident, item) = parse_mod_item ps in
|
|
||||||
htab_put items ident item;
|
|
||||||
expand_tags_to_items ps item items;
|
|
||||||
done;
|
done;
|
||||||
if (Hashtbl.length exports) = 0
|
|
||||||
then Hashtbl.add exports Ast.EXPORT_all_decls ();
|
|
||||||
expect ps terminal;
|
expect ps terminal;
|
||||||
ps.pstate_depth <- ps.pstate_depth - 1;
|
ps.pstate_depth <- ps.pstate_depth - 1;
|
||||||
let view = { Ast.view_imports = imports;
|
(view, items)
|
||||||
Ast.view_exports = exports }
|
|
||||||
in
|
|
||||||
(view, items)
|
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(*
|
(*
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
* fill-column: 78;
|
* fill-column: 78;
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
mod foo {
|
||||||
|
export x;
|
||||||
|
use std (ver="0.0.1");
|
||||||
|
fn x() -> int { ret 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
mod bar {
|
||||||
|
use std (ver="0.0.1");
|
||||||
|
export y;
|
||||||
|
fn y() -> int { ret 1; }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo.x();
|
||||||
|
bar.y();
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue