File tree Expand file tree Collapse file tree 9 files changed +35
-14
lines changed Expand file tree Collapse file tree 9 files changed +35
-14
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,7 @@ and source_unit =
3939 | ContractDefinition of contract_definition
4040
4141and import_directive = {
42+ import_pos : Solidity_common .pos ;
4243 import_from : string ;
4344 import_symbols : import_symbols ;
4445}
Original file line number Diff line number Diff line change @@ -56,6 +56,7 @@ and source_unit =
5656 (* * Definition of a contract *)
5757
5858and import_directive = {
59+ import_pos : Solidity_common .pos ;
5960 import_from : string ;
6061 import_symbols : import_symbols ;
6162}
Original file line number Diff line number Diff line change @@ -133,15 +133,18 @@ and bprint_source_unit b ~freeton indent su =
133133 | Pragma (id , s ) ->
134134 if not freeton then
135135 bprint b indent (Format. asprintf " pragma %a %s;" Ident. printf id s)
136- | Import { import_from; import_symbols = ImportAll (None) } ->
136+ | Import { import_from; import_symbols = ImportAll (None ) ;
137+ import_pos = _ } ->
137138 if not freeton then
138139 bprint b indent
139140 (Format. sprintf " import %S;" import_from)
140- | Import { import_from; import_symbols = ImportAll (Some id ) } ->
141+ | Import { import_from; import_symbols = ImportAll (Some id) ;
142+ import_pos = _ } ->
141143 bprint b indent
142144 (Format. sprintf " import * as %s from %s;"
143145 (string_of_ident id) import_from)
144- | Import { import_from; import_symbols = ImportIdents import_list } ->
146+ | Import { import_from; import_symbols = ImportIdents import_list ;
147+ import_pos = _ } ->
145148 bprint b indent
146149 (Format. sprintf " import { %s } from %s;"
147150 (String. concat " , "
Original file line number Diff line number Diff line change @@ -511,7 +511,7 @@ and visitSourceUnit (v : #ast_visitor) (su : source_unit) : unit =
511511 handleAction v#visitSourceUnit continueVisit su
512512
513513and visitImportDirective (v : #ast_visitor ) (id : import_directive ) : unit =
514- let continueVisit ({import_from; import_symbols} : import_directive ) : unit =
514+ let continueVisit ({import_from; import_symbols; import_pos = _ } : import_directive ) : unit =
515515 visitString v import_from;
516516 visitImportSymbols v import_symbols in
517517 handleAction v#visitImportDirective continueVisit id
Original file line number Diff line number Diff line change @@ -15,3 +15,5 @@ val init : freeton:bool -> unit
1515val reset : unit -> unit
1616
1717val token : Lexing .lexbuf -> Solidity_raw_parser .token
18+
19+ val recursive_comments : bool ref
Original file line number Diff line number Diff line change 6060 pos_bol = pos.pos_cnum - chars;
6161 }
6262
63+ let recursive_comments = ref false
64+
6365}
6466
6567let eol_comment =
@@ -105,7 +107,7 @@ rule token = parse
105107 { update_loc lexbuf name (int_of_string num) true 0 ;
106108 token lexbuf }
107109
108- | " /*" { multiline_comment lexbuf }
110+ | " /*" { multiline_comment lexbuf ; token lexbuf }
109111 | " pragma" { Buffer. clear buf; begin_pragma lexbuf }
110112
111113 | " [" { LBRACKET }
@@ -204,8 +206,15 @@ rule token = parse
204206 { error lexbuf " Unrecognized lexeme: \" %s\" " (Lexing. lexeme lexbuf) }
205207
206208and multiline_comment = parse
207- | " */" { token lexbuf }
209+ | " */" { () }
208210 | newline_char { newline lexbuf; multiline_comment lexbuf }
211+ | " hex" ? '\' ' ([^ '\'' ' \r' ' \n' ' \\'] | " \\ " _)* '\' '
212+ | " hex" ? '"' ([^ '"' '\r' '\n' '\\' ] | " \\ " _)* '"'
213+ { multiline_comment lexbuf }
214+ | " /*" {
215+ if ! recursive_comments then
216+ multiline_comment lexbuf;
217+ multiline_comment lexbuf }
209218 | eof { failwith " unexpected end of file in comment" }
210219 | _ { multiline_comment lexbuf }
211220
Original file line number Diff line number Diff line change @@ -17,8 +17,12 @@ let get_imported_files m =
1717 let base = Filename. dirname m.module_file in
1818 List. fold_left (fun fileset unit_node ->
1919 match strip unit_node with
20- | Import { import_from; _ } ->
20+ | Import { import_from; import_pos ; _ } ->
2121 let file = make_absolute_path base import_from in
22+ if not ( Sys. file_exists file ) then
23+ raise (
24+ Solidity_exceptions. SyntaxError
25+ (" File does not exist" , import_pos ) );
2226 StringSet. add file fileset
2327 | _ -> fileset
2428 ) StringSet. empty m.module_units
Original file line number Diff line number Diff line change 216216 | AmbiguousArray (a , expo ) ->
217217 Array (type_name_of_ambiguity a, expo)
218218
219- let import import_from import_symbols =
220- { import_from; import_symbols }
219+ let import import_pos import_from import_symbols =
220+ let import_pos = to_pos import_pos in
221+ { import_pos; import_from; import_symbols }
221222
222223 let rec put_in_none_list l n =
223224 if n < = 0 then l
@@ -468,11 +469,11 @@ source_unit:
468469
469470import_directive:
470471 | STRINGLITERAL as_identifier?
471- { import $ 1 (ImportAll ($ 2 )) }
472+ { import $ loc $ 1 (ImportAll ($ 2 )) }
472473 | STAR as_identifier FROM STRINGLITERAL
473- { import $ 4 (ImportAll (Some $ 2 )) }
474+ { import $ loc $ 4 (ImportAll (Some $ 2 )) }
474475 | LBRACE import_declarations RBRACE FROM STRINGLITERAL
475- { import $ 5 (ImportIdents $ 2 ) }
476+ { import $ loc $ 5 (ImportIdents $ 2 ) }
476477;;
477478
478479import_declarations:
Original file line number Diff line number Diff line change @@ -1934,7 +1934,7 @@ let preprocess_module p menvs m =
19341934 match strip unit_node with
19351935 | Pragma (_ ) ->
19361936 ()
1937- | Import { import_from; import_symbols } ->
1937+ | Import { import_from; import_symbols ; import_pos = _ } ->
19381938 let file = make_absolute_path base import_from in
19391939 let im = StringMap. find file p.program_modules_by_file in
19401940 let imenv = IdentMap. find im.module_id menvs in
@@ -2000,7 +2000,7 @@ let rec resolve_imports_internal ~only_anonymous
20002000 let seen, ordered =
20012001 List. fold_left (fun (seen , ordered ) unit_node ->
20022002 match strip unit_node with
2003- | Import { import_from; import_symbols } ->
2003+ | Import { import_from; import_symbols; import_pos = _ } ->
20042004 let do_imports =
20052005 match import_symbols with
20062006 | ImportAll (None) -> true
You can’t perform that action at this time.
0 commit comments