Permalink
Browse files

[enhance] jsparse: add filename option to string parser.

  • Loading branch information...
1 parent 53d1155 commit a838fe096602ae1c9f40c9ea594466f807d13717 @arthuraa arthuraa committed Aug 13, 2012
View
@@ -704,14 +704,15 @@ let stream_of_file lex_comments file =
module String =
struct
- let code ?throw_exn str =
+ let code ?filename ?throw_exn str =
build_parser ?throw_exn code
- (JsLex.stream_of_string ~lex_comments:true str)
- let expr ?throw_exn ?globalize str =
+ (JsLex.stream_of_string ?filename ~lex_comments:true str)
+ let expr ?filename ?throw_exn ?globalize str =
build_parser ?throw_exn ~globalize:(global_expr ?globalize)
- expr (JsLex.stream_of_string ~lex_comments:true str)
- let stm ?throw_exn str =
- build_parser ?throw_exn stm (JsLex.stream_of_string ~lex_comments:true str)
+ expr (JsLex.stream_of_string ?filename ~lex_comments:true str)
+ let stm ?filename ?throw_exn str =
+ build_parser ?throw_exn stm
+ (JsLex.stream_of_string ?filename ~lex_comments:true str)
end
module File =
struct
@@ -47,9 +47,9 @@ val pp : Format.formatter -> error -> unit
module String :
sig
- val code : ?throw_exn:bool -> string -> JsAst.code
- val expr : ?throw_exn:bool -> ?globalize:bool -> string -> JsAst.expr
- val stm : ?throw_exn:bool -> string -> JsAst.statement
+ val code : ?filename:string -> ?throw_exn:bool -> string -> JsAst.code
+ val expr : ?filename:string -> ?throw_exn:bool -> ?globalize:bool -> string -> JsAst.expr
+ val stm : ?filename:string -> ?throw_exn:bool -> string -> JsAst.statement
end
module File :
@@ -347,9 +347,9 @@ let parse_file filename =
JsParse.Exception e ->
`error (Format.to_string JsParse.pp e)
-let parse_string content =
+let parse_string ?filename content =
try
- let code = JsParse.String.code ~throw_exn:true content in
+ let code = JsParse.String.code ?filename ~throw_exn:true content in
doc_comment [] code
with
JsParse.Exception e ->
@@ -30,6 +30,7 @@ val parse_file :
(** [parse_string string] attempts to read js code in [string] and parse
its directives according to the doc-like syntax *)
val parse_string :
+ ?filename:string ->
string ->
[ `error of string
| `success of (FilePos.pos * BslTags.t * BslDirectives.Js.t) list ]
@@ -1566,7 +1566,7 @@ let parse_bypass_file pprocess options filename =
let parse_js_bypass_file_new pprocess filename =
let contents = pprocess filename (File.content filename) in
FilePos.add_file filename contents;
- match BslJsParse.parse_string contents with
+ match BslJsParse.parse_string ~filename contents with
| `error e -> OManager.error "%s" e
| `success directives ->
{ BslJs. filename; contents; directives; }

0 comments on commit a838fe0

Please sign in to comment.