Browse Source

allowed var $x : $t in parser (only for macros : still forbid $-prefixed local vars)
allowed "macro var ..."

Nicolas Cannasse 13 years ago
parent
commit
698abe7b34
2 changed files with 8 additions and 2 deletions
  1. 7 2
      parser.ml
  2. 1 0
      typer.ml

+ 7 - 2
parser.ml

@@ -138,6 +138,10 @@ let rec psep sep f = parser
 let ident = parser
 	| [< '(Const (Ident i),p) >] -> i,p
 
+let dollar_ident = parser
+	| [< '(Const (Ident i),p) >] -> i,p
+	| [< '(Dollar i,p) >] -> ("$" ^ i),p
+
 let lower_ident = parser
 	| [< '(Const (Ident i),p) when is_lower_ident i >] -> i
 
@@ -355,7 +359,7 @@ and parse_complex_type_inner = parser
 and parse_type_path s = parse_type_path1 [] s
 
 and parse_type_path1 pack = parser
-	| [< '(Const (Ident name),p); s >] ->
+	| [< name, p = dollar_ident; s >] ->
 		if is_lower_ident name then
 			(match s with parser
 			| [< '(Dot,p) >] ->
@@ -597,7 +601,7 @@ and parse_array_decl = parser
 		[]
 
 and parse_var_decl = parser
-	| [< name, _ = ident; t = parse_type_opt; s >] ->
+	| [< name, _ = dollar_ident; t = parse_type_opt; s >] ->
 		match s with parser
 		| [< '(Binop OpAssign,_); e = expr >] -> (name,t,Some e)
 		| [< >] -> (name,t,None)
@@ -616,6 +620,7 @@ and expr = parser
 		(match Stream.npeek 1 s with
 		| [(_,p2)] when p2.pmin > p.pmax ->
 			(match s with parser
+			| [< '(Kwd Var,p1); vl = psep Comma parse_var_decl >] -> (EMacro (EVars vl,p1),punion p p1)
 			| [< e = expr >] -> (EMacro e,punion p (pos e))
 			| [< >] -> expr_next (EConst (Ident "macro"),p) s)
 		| _ ->

+ 1 - 0
typer.ml

@@ -1797,6 +1797,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 						unify ctx e.etype t p;
 						Some e
 				) in
+				if v.[0] = '$' then error "Variables names starting with a dollar are not allowed" p;
 				add_local ctx v t, e
 			with
 				Error (e,p) ->