浏览代码

allowed dollars when meaningful.

Nicolas Cannasse 19 年之前
父节点
当前提交
fb90fab856
共有 3 个文件被更改,包括 26 次插入4 次删除
  1. 9 2
      genneko.ml
  2. 5 1
      genswf8.ml
  3. 12 1
      lexer.mll

+ 9 - 2
genneko.ml

@@ -139,12 +139,19 @@ let array p el =
 let pmap_list f p =
 	PMap.fold (fun v acc -> f v :: acc) p []
 
+let no_dollar t =
+	if t.[0] = '$' then
+		String.sub t 1 (String.length t - 1)
+	else
+		t
+
 let gen_type_path p (path,t) =
 	match path with
-	| [] -> ident p t
+	| [] -> 
+		ident p (no_dollar t)
 	| path :: l ->
 		let epath = List.fold_left (fun e path -> field p e path) (ident p path) l in
-		field p epath t
+		field p epath (no_dollar t)
 
 let gen_constant pe c =
 	let p = pos pe in

+ 5 - 1
genswf8.ml

@@ -162,7 +162,11 @@ let new_call ctx kind n  =
 
 let always_protected = function
 	| "prototype" | "toString" | "__resolve" -> true
-	| _ -> false
+	| s ->
+		if String.length s > 0 && s.[0] = '$' then
+			true
+		else
+			false
 
 let unprotect a =
 	if !protect_all || always_protected a then 

+ 12 - 1
lexer.mll

@@ -119,6 +119,9 @@ let mk_ident lexbuf =
 	| s ->
 		mk lexbuf (try Kwd (Hashtbl.find keywords s) with Not_found -> Const (Ident s))
 
+let invalid_char lexbuf =
+	error (Invalid_character (lexeme_char lexbuf 0)) (lexeme_start lexbuf)
+
 }
 
 let ident = ['_' 'a'-'z'] ['_' 'a'-'z' 'A'-'Z' '0'-'9']*
@@ -225,7 +228,15 @@ rule token = parse
 		}	
 	| ident { mk_ident lexbuf }
 	| idtype { mk lexbuf (Const (Type (lexeme lexbuf))) }
-	| _ { error (Invalid_character (lexeme_char lexbuf 0)) (lexeme_start lexbuf) }
+	| '$' ident {
+			if not (Plugin.defined "swf-mark") then invalid_char lexbuf;
+			mk_ident lexbuf
+		}
+	| '$' idtype {
+			if not (Plugin.defined "swf-mark") then invalid_char lexbuf;
+			mk lexbuf (Const (Type (lexeme lexbuf)))
+		}
+	| _ { invalid_char lexbuf }
 
 and comment = parse
 	| eof { raise Exit }