Permalink
Browse files

[enhance] libbsl: first version of new directive parser.

  • Loading branch information...
arthuraa committed Aug 3, 2012
1 parent 5746a54 commit 1f10c508fff55404431a84a79d4254d7a5969a52
@@ -135,6 +135,7 @@ type token =
| CommentLine of string
| CommentTag of string * string
+val string_of_token : token -> string
val init_lexer : unit -> unit
val lex : bool -> Lexing.lexbuf -> token
val stream : bool -> Lexing.lexbuf -> token Stream.t
View
@@ -127,6 +127,113 @@
| CommentLine of string
| CommentTag of string * string
+(* used for debug only, not error messages *)
+let string_of_token = function
+ | Break -> "break"
+ | Case -> "case"
+ | Catch -> "catch"
+ | Continue -> "continue"
+ | Debugger -> "debugger"
+ | Default -> "default"
+ | Delete -> "delete"
+ | Do -> "do"
+ | Else -> "else"
+ | Finally -> "finally"
+ | For -> "for"
+ | Function -> "function"
+ | If -> "if"
+ | In -> "in"
+ | Instanceof -> "instanceof"
+ | New -> "new"
+ | Return -> "return"
+ | Switch -> "switch"
+ | This -> "this"
+ | Throw -> "throw"
+ | Try -> "try"
+ | Typeof -> "typeof"
+ | Var -> "var"
+ | Void -> "void"
+ | While -> "while"
+ | With -> "with"
+ | Class -> "class"
+ | Const -> "const"
+ | Enum -> "enum"
+ | Export -> "export"
+ | Extends -> "extends"
+ | Import -> "import"
+ | Super -> "super"
+ | Implements -> "implements"
+ | Interface -> "interface"
+ | Let -> "let"
+ | Package -> "package"
+ | Private -> "private"
+ | Protected -> "protected"
+ | Public -> "public"
+ | Static -> "static"
+ | Yield -> "yield"
+ | True -> "true"
+ | False -> "false"
+ | Null -> "null"
+ | Regexp (s1,s2) -> Printf.sprintf "Regexp /%s/%s" s1 s2
+ | String s -> Printf.sprintf "%S" s
+ | Ident s -> "Ident " ^ s
+ | Integer s -> s
+ | LT -> "LT"
+ | EOF -> "EOF"
+ | Lbracket -> "["
+ | Rbracket -> "]"
+ | Lcurly -> "{"
+ | Rcurly -> "}"
+ | Lparen -> "("
+ | Rparen -> ")"
+ | Dot -> "."
+ | Semic -> ";"
+ | Comma -> ","
+ | Lt -> "<"
+ | Gt -> ">"
+ | Le -> "<="
+ | Ge -> ">="
+ | EqualEqual -> "=="
+ | BangEqual -> "!="
+ | EqualEqualEqual -> "==="
+ | BangEqualEqual -> "!=="
+ | Plus -> "+"
+ | Minus -> "-"
+ | Times -> "*"
+ | Percent -> "%"
+ | PlusPlus -> "++"
+ | MinusMinus -> "--"
+ | LtLt -> "<<"
+ | GtGt -> ">>"
+ | GtGtGt -> ">>>"
+ | Amper -> "&"
+ | Bar -> "|"
+ | Chapeau -> "^"
+ | Bang -> "!"
+ | Tilda -> "~"
+ | AmperAmper -> "&&"
+ | BarBar -> "||"
+ | Question -> "?"
+ | Colon -> ":"
+ | Equal -> "="
+ | PlusEqual -> "+="
+ | MinusEqual -> "-="
+ | TimesEqual -> "*="
+ | PercentEqual -> "%="
+ | LtLtEqual -> "<<="
+ | GtGtEqual -> ">>="
+ | GtGtGtEqual -> ">>>="
+ | AmperEqual -> "&="
+ | BarEqual -> "|="
+ | ChapeauEqual -> "^="
+ | Div -> "/"
+ | DivEqual -> "/="
+ | OpenDocComment -> "/**"
+ | CloseComment -> "*/"
+ | CommentLine s -> s
+ | CommentTag (t, _) -> "@" ^ t
+
+
(* the ecmascript defines two kinds of lexing: for the places in the ast
* where a token starting with / is a regular expression, and the places where
* it is the division or the division-assignment /=
View
@@ -23,112 +23,6 @@ let dummy_pos = FilePos.nopos "jsParse"
let label () = Annot.next_label dummy_pos
let native_ident = JsCons.Ident.native
-(* used for debug only, not error messages *)
-let string_of_token = function
- | Break -> "break"
- | Case -> "case"
- | Catch -> "catch"
- | Continue -> "continue"
- | Debugger -> "debugger"
- | Default -> "default"
- | Delete -> "delete"
- | Do -> "do"
- | Else -> "else"
- | Finally -> "finally"
- | For -> "for"
- | Function -> "function"
- | If -> "if"
- | In -> "in"
- | Instanceof -> "instanceof"
- | New -> "new"
- | Return -> "return"
- | Switch -> "switch"
- | This -> "this"
- | Throw -> "throw"
- | Try -> "try"
- | Typeof -> "typeof"
- | Var -> "var"
- | Void -> "void"
- | While -> "while"
- | With -> "with"
- | Class -> "class"
- | Const -> "const"
- | Enum -> "enum"
- | Export -> "export"
- | Extends -> "extends"
- | Import -> "import"
- | Super -> "super"
- | Implements -> "implements"
- | Interface -> "interface"
- | Let -> "let"
- | Package -> "package"
- | Private -> "private"
- | Protected -> "protected"
- | Public -> "public"
- | Static -> "static"
- | Yield -> "yield"
- | True -> "true"
- | False -> "false"
- | Null -> "null"
- | Regexp (s1,s2) -> Printf.sprintf "Regexp /%s/%s" s1 s2
- | String s -> Printf.sprintf "%S" s
- | Ident s -> "Ident " ^ s
- | Integer s -> s
- | LT -> "LT"
- | EOF -> "EOF"
- | Lbracket -> "["
- | Rbracket -> "]"
- | Lcurly -> "{"
- | Rcurly -> "}"
- | Lparen -> "("
- | Rparen -> ")"
- | Dot -> "."
- | Semic -> ";"
- | Comma -> ","
- | Lt -> "<"
- | Gt -> ">"
- | Le -> "<="
- | Ge -> ">="
- | EqualEqual -> "=="
- | BangEqual -> "!="
- | EqualEqualEqual -> "==="
- | BangEqualEqual -> "!=="
- | Plus -> "+"
- | Minus -> "-"
- | Times -> "*"
- | Percent -> "%"
- | PlusPlus -> "++"
- | MinusMinus -> "--"
- | LtLt -> "<<"
- | GtGt -> ">>"
- | GtGtGt -> ">>>"
- | Amper -> "&"
- | Bar -> "|"
- | Chapeau -> "^"
- | Bang -> "!"
- | Tilda -> "~"
- | AmperAmper -> "&&"
- | BarBar -> "||"
- | Question -> "?"
- | Colon -> ":"
- | Equal -> "="
- | PlusEqual -> "+="
- | MinusEqual -> "-="
- | TimesEqual -> "*="
- | PercentEqual -> "%="
- | LtLtEqual -> "<<="
- | GtGtEqual -> ">>="
- | GtGtGtEqual -> ">>>="
- | AmperEqual -> "&="
- | BarEqual -> "|="
- | ChapeauEqual -> "^="
- | Div -> "/"
- | DivEqual -> "/="
- | OpenDocComment -> "/**"
- | CloseComment -> "*/"
- | CommentLine s -> s
- | CommentTag (t, _) -> "@" ^ t
-
(* redefining the modules Stream allows us to 'override' the syntax of streams
* the new peek, junk and empty function look at the first non-newline token
* (which allows us to write almost the whole parser while implicitely
View
@@ -28,3 +28,4 @@ compiler/libbsl/BslError
compiler/libbsl/BslArgs
compiler/libbsl/BslTracker
compiler/libbsl/BslGeneration
+compiler/libbsl/BslJsParse
View
@@ -42,3 +42,6 @@
<bslbrowser.ml> : with_mlstate_debug
<bslOcaml.ml> : with_mlstate_debug
<bslConf.ml> : with_mlstate_debug
+
+<bslJsParse.ml>: use_camlp4, camlp4orf_fixed
+<bslJsParse.ml>: use_jslang
Oops, something went wrong.

0 comments on commit 1f10c50

Please sign in to comment.