text stringlengths 0 601k |
|---|
let defaultInterfaceParserFor use_stdin filename = let open Reason_toolchain in let ( theParser , parsedAsML ) = if Filename . check_suffix filename " . rei " then ( RE . interface_with_comments , false ) else if Filename . check_suffix filename " . mli " then ( ML . interface_with_comments , true ) else err ( " Cannot... |
let parse ~ use_stdin filetype filename = let ( ( ast , comments ) , parsedAsML , parsedAsInterface ) = ( match filetype with | ` Auto -> defaultInterfaceParserFor use_stdin filename | ` BinaryReason -> Printer_maker . reasonBinaryParser use_stdin filename | ` Binary -> Printer_maker . ocamlBinaryParser use_stdin filen... |
let print printtype filename parsedAsML output_chan output_formatter = match printtype with | ` BinaryReason -> fun ( ast , comments ) -> ( output_value output_chan ( Config . ast_intf_magic_number , filename , ast , comments , parsedAsML , true ) ; ) | ` Binary -> fun ( ast , _ ) -> ( let ast = Reason_syntax_util . ( ... |
type break_criterion = | Never | IfNeed | Always | Always_rec |
type separator = | NoSep | Sep of string | SepFinal of string * string |
module WhitespaceRegion = struct type t = { range : Range . t ; comments : Comment . t list ; newlines : int ; } let make ~ range ~ newlines ( ) = { range ; comments = [ ] ; newlines ; } let newlines t = t . newlines let range t = t . range let comments t = t . comments let addComment t comment = { t with comments = co... |
type t = | SourceMap of Location . t * t | Sequence of config * ( t list ) | Label of ( Easy_format . t -> Easy_format . t -> Easy_format . t ) * t * t | Easy of Easy_format . t | Whitespace of WhitespaceRegion . t * t break : break_criterion ; wrap : string * string ; inline : bool * bool ; sep : separator ; indent : ... |
let string_of_easy = function | Easy_format . Atom ( s , _ ) -> s | Easy_format . List ( _ , _ ) -> " list " | Easy_format . Label ( _ , _ ) -> " label " | Easy_format . Custom _ -> " custom " |
let indent_more indent = " " ^ indent |
let dump_easy ppf easy = let printf fmt = Format . fprintf ppf fmt in let rec traverse indent = function | Easy_format . Atom ( s , _ ) -> printf " % s Atom ' :% s ' \ n " indent s | Easy_format . List ( ( opening , sep , closing , config ) , items ) -> let break = ( match config . wrap_body with | ` No_breaks -> " No_... |
let dump ppf layout = let printf fmt = Format . fprintf ppf fmt in let rec traverse indent = function | SourceMap ( loc , layout ) -> printf " % s SourceMap [ ( % d :% d ) ( -% d :% d ) ] \ n " indent loc . loc_start . Lexing . pos_lnum ( loc . loc_start . Lexing . pos_cnum - loc . loc_start . Lexing . pos_bol ) loc . ... |
let source_map ( ? loc = Location . none ) layout = if loc = Location . none then layout else SourceMap ( loc , layout ) |
let default_list_settings = { Easy_format . space_after_opening = false ; space_after_separator = false ; space_before_separator = false ; separators_stick_left = true ; space_before_closing = false ; stick_to_label = true ; align_closing = true ; wrap_body = ` No_breaks ; indent_body = 0 ; list_style = Some " list " ;... |
let easy_settings_from_config { break ; wrap ; inline ; indent ; preSpace ; postSpace ; pad ; sep } = let ( opn , cls ) = wrap in let ( padOpn , padCls ) = pad in let ( inlineStart , inlineEnd ) = inline in let sepStr = match sep with NoSep -> " " | Sep s | SepFinal ( s , _ ) -> s in ( opn , sepStr , cls , { default_li... |
let to_easy_format layout = let rec traverse = function | Sequence ( config , sublayouts ) -> let items = List . map traverse sublayouts in Easy_format . List ( easy_settings_from_config config , items ) | Label ( labelFormatter , left , right ) -> labelFormatter ( traverse left ) ( traverse right ) | SourceMap ( _ , s... |
let get_location layout = let union loc1 loc2 = match ( loc1 , loc2 ) with | None , _ -> loc2 | _ , None -> loc1 | Some loc1 , Some loc2 -> Some { loc1 with Location . loc_end = loc2 . Location . loc_end } in let rec traverse = function | Sequence ( _ , subLayouts ) -> let locs = List . map traverse subLayouts in List ... |
let is_before ~ location layout = match get_location layout with | None -> true | Some loc -> Reason_syntax_util . location_is_before loc location |
let contains_location layout ~ location = match get_location layout with | None -> false | Some layout_loc -> Reason_syntax_util . location_contains layout_loc location |
type ' a positioned = ' a * Lexing . position * Lexing . position |
type t = { declarative_lexer_state : Reason_declarative_lexer . state ; lexbuf : Lexing . lexbuf ; mutable comments : ( string * Location . t ) list ; mutable queued_tokens : token positioned list ; mutable queued_exn : exn option ; mutable last_cnum : int ; mutable completion_ident_offset : int ; completion_ident_pos ... |
let init ? insert_completion_ident lexbuf = let declarative_lexer_state = Reason_declarative_lexer . make ( ) in let completion_ident_offset , completion_ident_pos = match insert_completion_ident with | None -> ( min_int , Lexing . dummy_pos ) | Some pos -> ( pos . Lexing . pos_cnum , pos ) in { declarative_lexer_state... |
let lexbuf state = state . lexbuf |
let rec token state = match Reason_declarative_lexer . token state . declarative_lexer_state state . lexbuf with | COMMENT ( s , comment_loc ) -> state . comments <- ( s , comment_loc ) :: state . comments ; token state | tok -> tok |
let save_triple lexbuf tok = ( tok , lexbuf . Lexing . lex_start_p , lexbuf . Lexing . lex_curr_p ) |
let fake_triple t ( _ , pos , _ ) = ( t , pos , pos ) |
let closing_of = function | LPAREN -> RPAREN | LBRACE -> RBRACE | _ -> assert false |
let inject_es6_fun = function | tok :: acc -> tok :: fake_triple ES6_FUN tok :: acc | _ -> assert false |
let is_triggering_token = function | EQUALGREATER | COLON -> true | _ -> false |
let rec lex_balanced_step state closing acc tok = let lexbuf = state . lexbuf in let acc = save_triple lexbuf tok :: acc in match tok , closing with | ( RPAREN , RPAREN ) | ( RBRACE , RBRACE ) | ( RBRACKET , RBRACKET ) -> acc | ( ( RPAREN | RBRACE | RBRACKET | EOF ) , _ ) -> raise ( Lex_balanced_failed ( acc , None ) )... |
let lookahead_esfun state ( tok , _ , _ as lparen ) = match lex_balanced state ( closing_of tok ) [ ] with | exception ( Lex_balanced_failed ( tokens , exn ) ) -> state . queued_tokens <- List . rev tokens ; state . queued_exn <- exn ; lparen | tokens -> begin match token state with | exception exn -> state . queued_to... |
let token state = let lexbuf = state . lexbuf in match state . queued_tokens , state . queued_exn with | [ ] , Some exn -> state . queued_exn <- None ; raise exn | [ ( LPAREN , _ , _ ) as lparen ] , None -> lookahead_esfun state lparen | [ ( LBRACE , _ , _ ) as lparen ] , None -> lookahead_esfun state lparen | [ ] , No... |
let token state = let space_start = state . last_cnum in let ( token ' , start_p , curr_p ) as token = token state in let token_start = start_p . Lexing . pos_cnum in let token_stop = curr_p . Lexing . pos_cnum in state . last_cnum <- token_stop ; if state . completion_ident_offset > min_int && space_start <= state . c... |
type comment = string * Location . t |
type invalid_docstrings = comment list |
let add_invalid_docstring text loc_start loc_end invalid_docstrings = let loc = { Location . loc_start ; loc_end ; loc_ghost = false } in ( ( text , loc ) :: invalid_docstrings ) |
let get_comments state invalid_docstrings = let cnum ( _ , loc ) = loc . Location . loc_start . Lexing . pos_cnum in let rec merge_comments acc = function | [ ] , xs | xs , [ ] -> List . rev_append xs acc | ( ( x :: _ ) as xs ) , ( y :: ys ) when cnum x >= cnum y -> merge_comments ( y :: acc ) ( xs , ys ) | x :: xs , y... |
module Range = struct type t = { lnum_start : int ; lnum_end : int } let makeRangeBetween loc1 loc2 = Location . { lnum_start = loc1 . loc_end . pos_lnum + 1 ; lnum_end = loc2 . loc_start . pos_lnum - 1 ; } let containsLoc range loc = let open Location in range . lnum_start <= loc . loc_start . pos_lnum && range . lnum... |
let hasSpaceBetween loc1 loc2 = Location . ( loc1 . loc_start . pos_lnum - loc2 . loc_end . pos_lnum ) > 1 |
type ' a parser = ' a S . parser list |
let initial entry_point position = [ S . initial entry_point position ] |
type ' a step = | Intermediate of ' a parser | Success of ' a * Reason_lexer . invalid_docstrings | Error |
let rec fork token = function | [ ] -> [ ] | x :: xs -> begin match S . step x token with | S . Intermediate x ' -> x :: x ' :: fork token xs | _ -> x :: fork token xs end |
let rec progress_successful token acc = function | [ ] -> Intermediate ( List . rev acc ) | x :: xs -> begin match S . step x token with | S . Intermediate p -> progress_successful token ( p :: acc ) xs | S . Error -> progress_successful token acc xs | S . Success ( result , ds ) -> Success ( result , ds ) end |
let step parsers token = match token with | ( Reason_parser . ES6_FUN , _ , _ ) -> Intermediate ( fork token parsers ) | _ -> match parsers with | [ x ] -> begin match S . step x token with | S . Intermediate parser -> Intermediate [ parser ] | S . Success ( result , ds ) -> Success ( result , ds ) | S . Error -> Error... |
let recover cp ds = [ S . recover cp ds ] |
let recovery_env = function | [ ] -> assert false | x :: _xs -> S . recovery_env x |
module type OCaml_version = Versions . OCaml_version |
module Compiler_libs = struct module Location = Location module Longident = Longident module type Asttypes = module type of struct include Asttypes end module rec Asttypes : Asttypes = Asttypes module type Parsetree = module type of struct include Parsetree end module rec Parsetree : Parsetree = Parsetree module Docstr... |
let cautious f ppf arg = try f ppf arg with Ellipsis -> fprintf ppf " . . . " |
let rec print_ident ppf = function Oide_ident s -> pp_print_string ppf s . printed_name | Oide_dot ( id , s ) -> print_ident ppf id ; pp_print_char ppf ' . ' ; pp_print_string ppf s | Oide_apply ( id1 , id2 ) -> fprintf ppf " % a ( % a ) " print_ident id1 print_ident id2 # else |
let rec print_ident ppf = function Oide_ident s -> ! Oprint . out_ident ppf s | Oide_dot ( id , s ) -> print_ident ppf id ; pp_print_char ppf ' . ' ; ! Oprint . out_ident ppf s | Oide_apply ( id1 , id2 ) -> fprintf ppf " % a ( % a ) " print_ident id1 print_ident id2 # endif |
let parenthesized_ident name = ( List . mem name [ " or " ; " mod " ; " land " ; " lor " ; " lxor " ; " lsl " ; " lsr " ; " asr " ] ) || ( match name . [ 0 ] with ' a ' . . ' z ' | ' A ' . . ' Z ' | ' \ 223 ' . . ' \ 246 ' | ' \ 248 ' . . ' \ 255 ' | ' _ ' -> false | _ -> true ) |
let value_ident ppf name = if parenthesized_ident name then fprintf ppf " ( % s ) " ( Reason_syntax_util . ml_to_reason_swap name ) else pp_print_string ppf name |
let valid_float_lexeme s = let l = String . length s in let rec loop i = if i >= l then s ^ " . " else match s . [ i ] with | ' 0 ' . . ' 9 ' | ' ' - -> loop ( i + 1 ) | _ -> s in loop 0 |
let float_repres f = match classify_float f with FP_nan -> " nan " | FP_infinite -> if f < 0 . 0 then " neg_infinity " else " infinity " | _ -> let float_val = let s1 = Printf . sprintf " . % 12g " f in if f = float_of_string s1 then s1 else let s2 = Printf . sprintf " . % 15g " f in if f = float_of_string s2 then s2 e... |
let parenthesize_if_neg ppf fmt v isneg = if isneg then pp_print_char ppf ' ( ' ; fprintf ppf fmt v ; if isneg then pp_print_char ppf ' ) ' |
let print_out_value ppf tree = let rec print_tree_1 ppf = function | Oval_constr ( name , [ Oval_constr ( ( Oide_ident { printed_name = " ( ) " } ) , [ ] ) ] ) -> fprintf ppf " [ @< 1 >% a ( ) ] " @ print_ident name | Oval_constr ( name , [ param ] ) -> fprintf ppf " [ @< 1 >% a ( % a ) ] " @ print_ident name print_con... |
let rec print_list_init pr sep ppf = function [ ] -> ( ) | a :: l -> sep ppf ; pr ppf a ; print_list_init pr sep ppf l |
let rec print_list pr sep ppf = function [ ] -> ( ) | [ a ] -> pr ppf a | a :: l -> pr ppf a ; sep ppf ; print_list pr sep ppf l |
let pr_present = print_list ( fun ppf s -> fprintf ppf " ` % s " s ) ( fun ppf -> fprintf ppf " @ " ) |
let pr_vars = print_list ( fun ppf s -> fprintf ppf " ' % s " s ) ( fun ppf -> fprintf ppf " @ " ) |
type label = | Nonlabeled | Labeled of string | Optional of string |
let get_label lbl = if lbl = " " then Nonlabeled else if String . get lbl 0 = ' ' ? then Optional ( String . sub lbl 1 @@ String . length lbl - 1 ) else Labeled lbl |
let rec print_out_type ppf = function | Otyp_alias ( ty , s ) -> fprintf ppf " [ @% a @ as ' % s ] " @ print_out_type ty s | Otyp_poly ( sl , ty ) -> fprintf ppf " [ @< hov 2 >% a . @ % a ] " @ pr_vars sl print_out_type ty | ty -> print_out_type_1 ~ uncurried : false ppf ty let suffix = match get_label lab with | Nonla... |
let out_type = ref print_out_type |
let variance = function | false , false -> " " | true , true -> " " | true , false -> " " + | false , true -> " " - |
let type_parameter ppf ( ty , var ) = fprintf ppf " % s % s " ( variance var ) ( if ty = " _ " then ty else " ' " ^ ty ) |
let print_out_class_params ppf = function [ ] -> ( ) | tyl -> fprintf ppf " ( [ @< 1 >% a ] ) @@ " ( print_list type_parameter ( fun ppf -> fprintf ppf " , @ " ) ) tyl |
let rec print_out_class_type ppf = function Octy_constr ( id , tyl ) -> let pr_tyl ppf = function [ ] -> ( ) | tyl -> fprintf ppf " [ @< 1 > % a ] " @ ( print_typlist print_out_wrap_type " " ) tyl in fprintf ppf " [ @% a % a ] " @ print_ident id pr_tyl tyl | Octy_arrow ( lab , argument_type , return_class_type ) -> let... |
let is_rec_next = function | Osig_class ( _ , _ , _ , _ , Orec_next ) :: _ | Osig_class_type ( _ , _ , _ , _ , Orec_next ) :: _ | Osig_module ( _ , _ , Orec_next ) :: _ | Osig_type ( _ , Orec_next ) :: _ -> true | _ -> false |
let rec print_out_functor ppf = function Omty_functor ( None , mty_res ) -> fprintf ppf " ( ) % a " print_out_functor mty_res | Omty_functor ( Some ( name , mty_arg ) , mty_res ) -> let name = match name with | None -> " _ " | Some name -> name in fprintf ppf " ( % s : % a ) => % a " name print_out_module_type mty_arg ... |
let print_out_exception ppf exn outv = match exn with Sys . Break -> fprintf ppf " Interrupted . . " @ | Out_of_memory -> fprintf ppf " Out of memory during evaluation . . " @ | Stack_overflow -> fprintf ppf " Stack overflow during evaluation ( looping recursion ) . . " ?@ | _ -> fprintf ppf " [ @ Exception :@ % a . ] ... |
let rec print_items ppf = function [ ] -> ( ) | ( Osig_typext ( ext , Oext_first ) , None ) :: items -> let rec gather_extensions acc items = match items with ( Osig_typext ( ext , Oext_next ) , None ) :: items -> gather_extensions ( ( ext . oext_name , ext . oext_args , ext . oext_ret_type ) :: acc ) items | _ -> ( Li... |
let print_out_phrase ppf = function Ophr_eval ( outv , ty ) -> fprintf ppf " [ @- : % a @ =@ % a ] . " @@ print_out_type ty print_out_value outv | Ophr_signature [ ] -> ( ) | Ophr_signature items -> fprintf ppf " [ @< v >% a ] . " @@ print_items items | Ophr_exception ( exn , outv ) -> print_out_exception ppf exn outv |
let identlike_keywords = let reverse_table = lazy ( let table = Hashtbl . create 7 in let flip_add k v = Hashtbl . add table v k in Hashtbl . iter flip_add Reason_declarative_lexer . keyword_table ; table ) in function | Parser . SIG -> Some " sig " | Parser . MODULE -> Some " module " | Parser . BEGIN -> Some " begin ... |
let keyword_confused_with_ident state token = match identlike_keywords token with | Some name when Raw . transitions_on_lident state || Raw . transitions_on_uident state -> ( name ^ " is a reserved keyword , it cannot be used as an identifier . Try ` " ^ name ^ " _ ` or ` _ " ^ name ^ " ` instead " ) | _ -> raise Not_f... |
let uppercased_instead_of_lowercased state token = match token with | Parser . UIDENT name when Raw . transitions_on_lident state -> let name = String . uncapitalize_ascii name in if Hashtbl . mem Reason_declarative_lexer . keyword_table name then " variables and labels should be lowercased " else Printf . sprintf " va... |
let semicolon_might_be_missing state _token = if Raw . transitions_on_semi state then " syntax error , consider adding a ` ; ' before " else raise Not_found |
let token_specific_message = function | Parser . UNDERSCORE -> " underscore is not a valid identifier . Use _ only in pattern matching and partial function application " | _ -> raise Not_found |
let unclosed_parenthesis is_opening_symbol closing_symbol check_function env = let state = Interp . current_state_number env in if check_function state then let rec find_opening_location = function | None -> None | Some env -> let found = match Interp . top env with | Some ( Interp . Element ( state , _ , startp , endp... |
let check_unclosed env = let check ( message , opening_symbols , closing_symbol , check_function ) = match unclosed_parenthesis ( fun x -> List . mem x opening_symbols ) closing_symbol check_function env with | None -> None | Some ( loc_start , _ ) -> Some ( Format . asprintf " Unclosed % S ( opened line % d , column %... |
let message env ( token , _ , _ ) = let state = Interp . current_state_number env in try keyword_confused_with_ident state token with Not_found -> try check_unclosed env with Not_found -> try uppercased_instead_of_lowercased state token with Not_found -> try semicolon_might_be_missing state token with Not_found -> try ... |
let commaTrail = Layout . SepFinal ( " , " , Reason_syntax_util . TrailingCommaMarker . string ) |
let commaSep = Layout . Sep ( " , " ) |
type ruleInfoData = { reducePrecedence : precedence ; shiftPrecedence : precedence ; } | FunctionApplication of Layout . t list | SpecificInfixPrecedence of ruleInfoData * resolvedRule | PotentiallyLowPrecedence of Layout . t | Simple of Layout . t | LayoutNode of Layout . t | InfixTree of string * resolvedRule * resol... |
type infixChain = | InfixToken of string | Layout of Layout . t |
let expression_extension_sugar x = if x . pexp_attributes != [ ] then None else match x . pexp_desc with | Pexp_extension ( name , PStr [ { pstr_desc = Pstr_eval ( expr , [ ] ) } ] ) when name . txt <> " bs . obj " -> Some ( name , expr ) | _ -> None |
let expression_immediate_extension_sugar x = match expression_extension_sugar x with | None -> ( None , x ) | Some ( name , expr ) -> match expr . pexp_desc with | Pexp_for _ | Pexp_while _ | Pexp_ifthenelse _ | Pexp_function _ | Pexp_newtype _ | Pexp_try _ | Pexp_match _ -> ( Some name , expr ) | _ -> ( None , x ) |
let expression_not_immediate_extension_sugar x = match expression_immediate_extension_sugar x with | ( Some _ , _ ) -> None | ( None , _ ) -> expression_extension_sugar x |
let add_extension_sugar keyword = function | None -> keyword | Some str -> keyword ^ " " % ^ str . txt |
let string_equal : string -> string -> bool = ( ) = |
let longident_same l1 l2 = let rec equal l1 l2 = match l1 , l2 with | Lident l1 , Lident l2 -> string_equal l1 l2 | Ldot ( path1 , l1 ) , Ldot ( path2 , l2 ) -> equal path1 path2 && string_equal l1 l2 | Lapply ( l11 , l12 ) , Lapply ( l21 , l22 ) -> equal l11 l21 && equal l12 l22 | _ -> false in equal l1 . txt l2 . txt |
let for_all2 ' pred l1 l2 = List . length l1 = List . length l2 && List . for_all2 pred l1 l2 |
let same_ast_modulo_varification_and_extensions t1 t2 = let rec loop t1 t2 = match ( t1 . ptyp_desc , t2 . ptyp_desc ) with | ( Ptyp_constr ( { txt = Lident s1 } , [ ] ) , Ptyp_var s2 ) -> string_equal s1 s2 | ( Ptyp_var s1 , Ptyp_constr ( { txt = Lident s2 } , [ ] ) ) -> string_equal s1 s2 | ( Ptyp_constr ( longident1... |
let expandLocation pos ~ expand ( : startPos , endPos ) = { pos with loc_start = { pos . loc_start with Lexing . pos_cnum = pos . loc_start . Lexing . pos_cnum + startPos } ; loc_end = { pos . loc_end with Lexing . pos_cnum = pos . loc_end . Lexing . pos_cnum + endPos } } |
let rec firstAttrLoc loc = function | ( ( attrLoc , _ ) : Ast_404 . Parsetree . attribute ) :: attrs -> if attrLoc . loc . loc_start . pos_lnum < loc . loc_start . pos_lnum && not attrLoc . loc . loc_ghost then firstAttrLoc attrLoc . loc attrs else firstAttrLoc loc attrs | [ ] -> loc |
let extractLocationFromValBindList expr vbs = let rec extract loc = function | x :: xs -> let { pvb_expr } = x in let loc = { loc with loc_end = pvb_expr . pexp_loc . loc_end } in extract loc xs | [ ] -> loc in let loc = match vbs with | x :: xs -> let { pvb_pat ; pvb_expr } = x in let loc = { pvb_pat . ppat_loc with l... |
let extractLocValBinding { pvb_pat ; pvb_expr ; pvb_attributes ; } = let estimatedLoc = firstAttrLoc pvb_pat . ppat_loc pvb_attributes in { estimatedLoc with loc_end = pvb_expr . pexp_loc . loc_end } |
let extractLocModuleBinding { pmb_expr ; pmb_attributes } = let estimatedLoc = firstAttrLoc pmb_expr . pmod_loc pmb_attributes in { estimatedLoc with loc_end = pmb_expr . pmod_loc . loc_end } |
let extractLocModDecl { pmd_type ; pmd_attributes } = let estimatedLoc = firstAttrLoc pmd_type . pmty_loc pmd_attributes in { estimatedLoc with loc_end = pmd_type . pmty_loc . loc_end } |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.