Final edits. Corrected single, zero arg cases.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5233 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Art Yerkes 2003-11-01 07:54:12 +00:00
commit 243ebeeb27

View file

@ -10,27 +10,36 @@ let c_ify e loc =
| <:expr< True >> -> <:expr< (C_bool $e$) >>
| <:expr< False >> -> <:expr< (C_bool $e$) >>
| _ -> <:expr< $e$ >>
let rec mk_list args l f =
match args with
[] -> (let loc = l in <:expr< [] >>)
| x :: xs ->
(let loc = MLast.loc_of_expr x in
<:expr< [ ($f x loc$) ] @ ($mk_list xs loc f$) >>)
let mk_list args loc f =
let rec mk_list_inner args loc f =
match args with
[] -> <:expr< [] >>
| x :: xs ->
(let loc = MLast.loc_of_expr x in
<:expr< [ ($f x loc$) ] @ ($mk_list_inner xs loc f$) >>) in
match args with
[] -> <:expr< (Obj.magic C_void) >>
| [ a ] -> <:expr< (Obj.magic $f a loc$) >>
| _ -> <:expr< (Obj.magic (C_list ($mk_list_inner args loc f$))) >>
EXTEND
expr:
[ [ e1 = expr ; "'" ; "[" ; e2 = expr ; "]" ->
<:expr< (invoke $e1$) "[]" (C_list [ $c_ify e2 loc$ ]) >>
| e1 = expr ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $str:l$ (C_list $mk_list args loc c_ify$) >>
<:expr< (invoke $e1$) $str:l$ ($mk_list args loc c_ify$) >>
| e1 = expr ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $str:u$ (C_list $mk_list args loc c_ify$) >>
<:expr< (invoke $e1$) $str:u$ ($mk_list args loc c_ify$) >>
| e1 = expr ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) $s$ ($mk_list args loc c_ify$) >>
| e1 = expr ; "'" ; "." ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke $e1$) "()" (C_list $mk_list args loc c_ify$) >>
<:expr< (invoke $e1$) "()" ($mk_list args loc c_ify$) >>
| e1 = expr ; "'" ; "->" ; l = LIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:l$ (C_list $mk_list args loc c_ify$) >>
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:l$ ($mk_list args loc c_ify$) >>
| e1 = expr ; "'" ; "->" ; u = UIDENT ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:u$ (C_list $mk_list args loc c_ify$) >>
<:expr< (invoke ((invoke $e1$) "->" C_void)) $str:u$ ($mk_list args loc c_ify$) >>
| e1 = expr ; "'" ; "->" ; s = expr LEVEL "simple" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
<:expr< (invoke ((invoke $e1$) "->" C_void)) $s$ ($mk_list args loc c_ify$) >>
| e1 = expr ; "'" ; "++" ->
<:expr< (invoke $e1$) "++" C_void >>
| e1 = expr ; "'" ; "--" ->
@ -101,8 +110,7 @@ EXTEND
| c = expr ; "as" ; id = LIDENT -> <:expr< $lid:"get_" ^ id$ $c$ >>
| c = expr ; "to" ; id = LIDENT -> <:expr< $uid:"C_" ^ id$ $c$ >>
| f = expr ; "'" ; "(" ; args = LIST0 (expr LEVEL "simple") SEP "," ; ")" ->
let l = mk_list args loc c_ify in
<:expr< $f$ (C_list $l$) >>
<:expr< $f$ ($mk_list args loc c_ify$) >>
] ] ;
END ;;