Browse Source

null, true, false are now keywords

Nicolas Cannasse 13 years ago
parent
commit
2b05fa43ca
4 changed files with 18 additions and 3 deletions
  1. 6 0
      ast.ml
  2. 2 1
      doc/CHANGES.txt
  3. 1 1
      lexer.mll
  4. 9 1
      parser.ml

+ 6 - 0
ast.ml

@@ -62,6 +62,9 @@ type keyword =
 	| Callback
 	| Inline
 	| Using
+	| Null
+	| True
+	| False
 
 type binop =
 	| OpAdd
@@ -352,6 +355,9 @@ let s_keyword = function
 	| Callback -> "callback"
 	| Inline -> "inline"
 	| Using -> "using"
+	| Null -> "null"
+	| True -> "true"
+	| False -> "false"
 
 let rec s_binop = function
 	| OpAdd -> "+"

+ 2 - 1
doc/CHANGES.txt

@@ -1,7 +1,7 @@
 2012-??-??: 2.09
 	all : optimized const == const and const != const (with different const types)
 	all : add Type.allEnums(e)
-	all : fixed some issue with completion
+	all : big improvements with completion speed and fixed many issues
 	flash9 : fixed -D swfprotected with swc output
 	neko : added ~ implementation
 	js : upgraded jquery version, more api overloads
@@ -32,6 +32,7 @@
 	js : added source mapping with -debug (replace previous stack emulation)
 	flash : added @:file("a.dat") class File extends flash.utils.ByteArray
 	js : added --js-modern for wrapping output in a closure and ES5 strict mode
+	all : null, true and false are now keywords
 
 2011-09-25: 2.08
 	js : added js.JQuery

+ 1 - 1
lexer.mll

@@ -75,7 +75,7 @@ let keywords =
 		Switch;Case;Default;Public;Private;Try;Untyped;
 		Catch;New;This;Throw;Extern;Enum;In;Interface;
 		Cast;Override;Dynamic;Typedef;Package;Callback;
-		Inline;Using];
+		Inline;Using;Null;True;False];
 	h
 
 let init file =

+ 9 - 1
parser.ml

@@ -142,10 +142,15 @@ let any_ident = parser
 	| [< '(Const (Ident i),p) >] -> i, p
 	| [< '(Const (Type t),p) >] -> t, p
 
+let any_enum_ident = parser
+	| [< i = any_ident >] -> i
+	| [< '(Kwd k,p) when Filename.basename p.pfile = "StdTypes.hx" >] -> s_keyword k, p 
+
 let property_ident = parser
 	| [< i, _ = any_ident >] -> i
 	| [< '(Kwd Dynamic,_) >] -> "dynamic"
 	| [< '(Kwd Default,_) >] -> "default"
+	| [< '(Kwd Null,_) >] -> "null"
 
 let get_doc s =
 	let d = !doc in
@@ -434,7 +439,7 @@ and parse_enum s =
 	doc := None;
 	let meta = parse_meta s in
 	match s with parser
-	| [< name, p1 = any_ident; doc = get_doc; s >] ->
+	| [< name, p1 = any_enum_ident; doc = get_doc; s >] ->
 		match s with parser
 		| [< '(POpen,_); l = psep Comma parse_enum_param; '(PClose,_); p = semicolon; >] -> (name,doc,meta,l,punion p1 p)
 		| [< '(Semicolon,p) >] -> (name,doc,meta,[],punion p1 p)
@@ -602,6 +607,9 @@ and expr = parser
 		| _ -> e)
 	| [< '(Const c,p); s >] -> expr_next (EConst c,p) s
 	| [< '(Kwd This,p); s >] -> expr_next (EConst (Ident "this"),p) s
+	| [< '(Kwd True,p); s >] -> expr_next (EConst (Ident "true"),p) s
+	| [< '(Kwd False,p); s >] -> expr_next (EConst (Ident "false"),p) s
+	| [< '(Kwd Null,p); s >] -> expr_next (EConst (Ident "null"),p) s
 	| [< '(Kwd Callback,p); s >] -> expr_next (EConst (Ident "callback"),p) s
 	| [< '(Kwd Cast,p1); s >] ->
 		(match s with parser