text stringlengths 0 601k |
|---|
let remove_stylistic_attrs_mapper_maker super = let open Ast_411 in let open Ast_mapper in expr = begin fun mapper expr -> let { Reason_attributes . stylisticAttrs ; arityAttrs ; docAttrs ; stdAttrs ; jsxAttrs } = Reason_attributes . partitionAttributes ~ allowUncurry : false expr . pexp_attributes in let expr = if sty... |
let escape_stars_slashes str = if String . contains str ' ' / then replace_string " " /* " " /\\* @@ replace_string " " */ " " *\\/ @@ replace_string " " // " " /\\/ @@ str else str |
let remove_stylistic_attrs_mapper = remove_stylistic_attrs_mapper_maker Ast_mapper . default_mapper |
let let_monad_symbols = [ ' ' ; $ ' ' ; & ' ' ; * ' ' ; + ' ' ; - ' ' ; / ' ' ; < ' ' ; = ' ' ; > ' ' ; @ ' ' ; ^ ' ' ; | ' . ' ; ' ' ] ! |
let is_letop s = String . length s > 3 # else String . length s > 5 # endif && s . [ 0 ] = ' l ' && s . [ 1 ] = ' e ' && s . [ 2 ] = ' t ' && List . mem s . [ 3 ] let_monad_symbols # else && s . [ 3 ] = ' _ ' && s . [ 4 ] = ' _ ' && List . mem s . [ 5 ] let_monad_symbols # endif |
let is_andop s = String . length s > 3 # else String . length s > 5 # endif && s . [ 0 ] = ' a ' && s . [ 1 ] = ' n ' && s . [ 2 ] = ' d ' && List . mem s . [ 3 ] let_monad_symbols # else && s . [ 3 ] = ' _ ' && s . [ 4 ] = ' _ ' && List . mem s . [ 5 ] let_monad_symbols # endif |
let noop_mapper super = let noop = fun _mapper x -> x in { super with expr = noop ; structure = noop ; structure_item = noop ; signature = noop ; signature_item = noop ; } |
let expand_letop_identifier s = s |
let compress_letop_identifier s = s # else let letop_table , reverse_letop_table = let create_hashtable n l = let t = Hashtbl . create n in let rev_t = Hashtbl . create n in List . iter ( fun ( k , v ) -> Hashtbl . add t k v ; Hashtbl . add rev_t v k ; ) l ; t , rev_t in create_hashtable 16 [ ' ' , ! " bang " ; ' ' , $... |
let backport_letopt_mapper super = let open Ast_411 in let open Ast_mapper in expr = fun mapper expr -> match expr . pexp_desc with | Pexp_letop { let_ ; ands ; body } -> let rec loop = function | [ ] -> assert false | { pbop_op ; pbop_pat ; pbop_exp } [ ] :: -> ( pbop_pat , pbop_exp , pbop_op ) | { pbop_op ; pbop_pat ... |
let escape_stars_slashes_mapper = identifier_mapper escape_stars_slashes |
let reason_to_ml_swap_operator_mapper = identifier_mapper reason_to_ml_swap |
let ml_to_reason_swap_operator_mapper = identifier_mapper ml_to_reason_swap |
let attribute_equals to_compare = function | { attr_name = { txt } ; _ } -> txt = to_compare |
let attribute_exists txt attributes = List . exists ( attribute_equals txt ) attributes |
let attributes_conflicted attribute1 attribute2 attributes = attribute_exists attribute1 attributes && attribute_exists attribute2 attributes |
let normalized_attributes attribute attributes = List . filter ( fun x -> not ( attribute_equals attribute x ) ) attributes |
let apply_mapper_to_structure s mapper = mapper . structure mapper s |
let apply_mapper_to_signature s mapper = mapper . signature mapper s |
let apply_mapper_to_type s mapper = mapper . typ mapper s |
let apply_mapper_to_expr s mapper = mapper . expr mapper s |
let apply_mapper_to_pattern s mapper = mapper . pat mapper s |
let apply_mapper_to_toplevel_phrase toplevel_phrase mapper = match toplevel_phrase with | Ptop_def x -> Ptop_def ( apply_mapper_to_structure x mapper ) | x -> x |
let apply_mapper_to_use_file use_file mapper = List . map ( fun x -> apply_mapper_to_toplevel_phrase x mapper ) use_file |
let map_first f = function | [ ] -> invalid_arg " Syntax_util . map_first : empty list " | x :: xs -> f x :: xs |
let map_last f l = match List . rev l with | [ ] -> invalid_arg " Syntax_util . map_last : empty list " | x :: xs -> List . rev ( f x :: xs ) |
let location_is_before loc1 loc2 = let open Location in loc1 . loc_end . Lexing . pos_cnum <= loc2 . loc_start . Lexing . pos_cnum |
let location_contains loc1 loc2 = let open Location in loc1 . loc_start . Lexing . pos_cnum <= loc2 . loc_start . Lexing . pos_cnum && loc1 . loc_end . Lexing . pos_cnum >= loc2 . loc_end . Lexing . pos_cnum |
let split_compiler_error ( err : Location . error ) = ( err . main . loc , Format . asprintf " % t " err . main . txt ) # else |
let split_compiler_error ( err : Location . error ) = ( err . loc , err . msg ) # endif |
let explode_str str = let rec loop acc i = if i < 0 then acc else loop ( str . [ i ] :: acc ) ( i - 1 ) in loop [ ] ( String . length str - 1 ) # endif |
module Clflags = struct include Clflags let fast = unsafe # endif end |
let parse_lid s = match Longident . unflatten ( String . split_on_char ' . ' s ) with | Some lid -> lid | None -> failwith ( Format . asprintf " parse_lid : unable to parse ' % s ' to longident " s ) # else Longident . parse s # endif |
let potentially_conflicts_with ~ keyword s = let s_length = String . length s in let keyword_length = String . length keyword in s_length >= keyword_length && ( try for i = 0 to keyword_length - 1 do if keyword . [ i ] <> s . [ i ] then raise Exit ; done ; for i = keyword_length to s_length - 1 do if s . [ i ] <> ' _ '... |
let string_add_suffix x = x ^ " _ " |
let string_drop_suffix x = String . sub x 0 ( String . length x - 1 ) |
let reason_to_ml_swap = function | " " ! -> " not " | " " ^ -> " " ! | " " ++ -> " " ^ | " " === -> " " == | " " == -> " " = | " " \\!== -> " " !== | " " \\=== -> " " === | " " != -> " " <> | " " !== -> " " != | x when ( potentially_conflicts_with ~ keyword " : match " x || potentially_conflicts_with ~ keyword " : meth... |
let ml_to_reason_swap = function | " not " -> " " ! | " " ! -> " " ^ | " " ^ -> " " ++ | " " == -> " " === | " " = -> " " == | " " !== -> " " \\!== | " " === -> " " \\=== | " " <> -> " " != | " " != -> " " !== | x when ( potentially_conflicts_with ~ keyword " : match_ " x || potentially_conflicts_with ~ keyword " : met... |
let escape_string str = let buf = Buffer . create ( String . length str ) in String . iter ( fun c -> match c with | ' \ t ' -> Buffer . add_string buf " \\ t " | ' \ r ' -> Buffer . add_string buf " \\ r " | ' \ n ' -> Buffer . add_string buf " \\ n " | ' ' \\ -> Buffer . add_string buf " " \\\\ | ' " ' -> Buffer . ad... |
module TrailingCommaMarker = struct let char = Char . chr 249 let string = String . make 1 char end |
module EOLMarker = struct let char = Char . chr 248 let string = String . make 1 char end |
let is_prefixed prefix str i = let len = String . length prefix in let j = ref 0 in while ! j < len && String . unsafe_get prefix ! j = String . unsafe_get str ( i + ! j ) do incr j done ; ( ! j = len ) |
let rec pick_while p = function | [ ] -> [ ] , [ ] | hd :: tl when p hd -> let ( satisfied , not_satisfied ) = pick_while p tl in hd :: satisfied , not_satisfied | l -> ( [ ] , l ) |
let find_substring sub str i = let len = String . length str - String . length sub in let found = ref false and i = ref i in while not ! found && ! i <= len do if is_prefixed sub str ! i then found := true else incr i ; done ; if not ! found then raise Not_found ; ! i |
let replace_string old_str new_str str = match find_substring old_str str 0 with | exception Not_found -> str | occurrence -> let buffer = Buffer . create ( String . length str + 15 ) in let rec loop i j = Buffer . add_substring buffer str i ( j - i ) ; Buffer . add_string buffer new_str ; let i = j + String . length o... |
let split_by ( ? keep_empty = false ) is_delim str = let len = String . length str in let rec loop acc last_pos pos = if pos = - 1 then if last_pos = 0 && not keep_empty then acc else String . sub str 0 last_pos :: acc else if is_delim str . [ pos ] then let new_len = ( last_pos - pos - 1 ) in if new_len <> 0 || keep_e... |
let rec trim_right_idx str idx = if idx = - 1 then 0 else match String . get str idx with | ' \ t ' | ' ' | ' \ n ' | ' \ r ' -> trim_right_idx str ( idx - 1 ) | _ -> idx + 1 |
let trim_right str = let length = String . length str in if length = 0 then " " else let index = trim_right_idx str ( length - 1 ) in if index = 0 then " " else if index = length then str else String . sub str 0 index |
let processLine line = let rightTrimmed = trim_right line in let trimmedLen = String . length rightTrimmed in if trimmedLen = 0 then rightTrimmed else let segments = split_by ~ keep_empty : false ( fun c -> c = TrailingCommaMarker . char ) rightTrimmed in let hadTrailingCommaMarkerBeforeNewline = String . get rightTrim... |
let processLineEndingsAndStarts str = split_by ~ keep_empty : true ( fun x -> x = ' \ n ' ) str |> List . map processLine |> String . concat " \ n " |> String . trim |
let isLineComment str = match String . index str ' \ n ' with | exception Not_found -> false | n -> n = String . length str - 1 |
let syntax_error_extension_node loc message = let str = Location . mkloc " merlin . syntax - error " loc in let payload = PStr [ { pstr_loc = Location . none ; pstr_desc = Pstr_eval ( { pexp_loc = Location . none ; pexp_desc = Pexp_constant ( Parsetree . Pconst_string ( message , None ) ) ; pexp_attributes = [ ] ; } , ... |
let identifier_mapper f super = expr = begin fun mapper expr -> let expr = match expr with | { pexp_desc = Pexp_ident ( { txt } as id ) } -> let swapped = match txt with | Lident s -> Lident ( f s ) | Ldot ( longPrefix , s ) -> Ldot ( longPrefix , f s ) | Lapply ( y , s ) -> Lapply ( y , s ) in { expr with pexp_desc = ... |
let remove_stylistic_attrs_mapper_maker super = let open Ast_404 in let open Ast_mapper in expr = begin fun mapper expr -> let { Reason_attributes . stylisticAttrs ; arityAttrs ; docAttrs ; stdAttrs ; jsxAttrs } = Reason_attributes . partitionAttributes ~ allowUncurry : false expr . pexp_attributes in let expr = if sty... |
let remove_stylistic_attrs_mapper = remove_stylistic_attrs_mapper_maker Ast_mapper . default_mapper |
let escape_stars_slashes_mapper = let escape_stars_slashes str = if String . contains str ' ' / then replace_string " " /* " " /\\* @@ replace_string " " */ " " *\\/ @@ replace_string " " // " " /\\/ @@ str else str in identifier_mapper escape_stars_slashes |
let reason_to_ml_swap_operator_mapper = identifier_mapper reason_to_ml_swap |
let ml_to_reason_swap_operator_mapper = identifier_mapper ml_to_reason_swap |
let attribute_equals to_compare = function | ( { txt } , _ ) -> txt = to_compare |
let attribute_exists txt attributes = List . exists ( attribute_equals txt ) attributes |
let attributes_conflicted attribute1 attribute2 attributes = attribute_exists attribute1 attributes && attribute_exists attribute2 attributes |
let normalized_attributes attribute attributes = List . filter ( fun x -> not ( attribute_equals attribute x ) ) attributes |
let apply_mapper_to_structure s mapper = mapper . structure mapper s |
let apply_mapper_to_signature s mapper = mapper . signature mapper s |
let apply_mapper_to_type s mapper = mapper . typ mapper s |
let apply_mapper_to_expr s mapper = mapper . expr mapper s |
let apply_mapper_to_pattern s mapper = mapper . pat mapper s |
let apply_mapper_to_toplevel_phrase toplevel_phrase mapper = match toplevel_phrase with | Ptop_def x -> Ptop_def ( apply_mapper_to_structure x mapper ) | x -> x |
let apply_mapper_to_use_file use_file mapper = List . map ( fun x -> apply_mapper_to_toplevel_phrase x mapper ) use_file |
type error = Syntax_error of string |
let report_error ppf ( Syntax_error err ) = Format . ( fprintf ppf " % s " err ) |
let ( ) = Location . register_error_of_exn ( function | Error ( loc , err ) -> Some ( Location . error_of_printer loc report_error err ) | _ -> None ) |
let map_first f = function | [ ] -> invalid_arg " Syntax_util . map_first : empty list " | x :: xs -> f x :: xs |
let map_last f l = match List . rev l with | [ ] -> invalid_arg " Syntax_util . map_last : empty list " | x :: xs -> List . rev ( f x :: xs ) |
type menhirMessagesError = { msg : string ; loc : Location . t ; } |
type menhirError = | NoMenhirMessagesError | MenhirMessagesError of menhirMessagesError |
let menhirMessagesError = ref [ NoMenhirMessagesError ] |
let findMenhirErrorMessage loc = let rec find messages = match messages with | MenhirMessagesError err :: _ when err . loc = loc -> MenhirMessagesError err | _ :: tail -> find tail | [ ] -> NoMenhirMessagesError in find ! menhirMessagesError |
let default_error_message = " < syntax error " > |
let add_error_message err = let msg = try ignore ( find_substring default_error_message err . msg 0 ) ; [ MenhirMessagesError { err with msg = " A syntax error occurred . Help us improve this message : https :// github . com / facebook / reason / blob / master / src / README . md # add - a - menhir - error - message " ... |
let location_is_before loc1 loc2 = let open Location in loc1 . loc_end . Lexing . pos_cnum <= loc2 . loc_start . Lexing . pos_cnum |
let location_contains loc1 loc2 = let open Location in loc1 . loc_start . Lexing . pos_cnum <= loc2 . loc_start . Lexing . pos_cnum && loc1 . loc_end . Lexing . pos_cnum >= loc2 . loc_end . Lexing . pos_cnum |
let explode_str str = let rec loop acc i = if i < 0 then acc else loop ( str . [ i ] :: acc ) ( i - 1 ) in loop [ ] ( String . length str - 1 ) |
* * WARNING : The " end " location is one greater than the actual final position ! * ( for both [ associatedTextLoc ] and [ commentLoc ] ) . * * Currently , the location information for comments is of the form : * * ( associatedTextLoc ) * * But we should quickly change it to be of the form : * * ( associatedTextLoc , ... |
let setup_lexbuf use_stdin filename = let lexbuf = match use_stdin with | true -> Lexing . from_channel stdin | false -> let file_chan = open_in filename in seek_in file_chan 0 ; Lexing . from_channel file_chan in Location . init lexbuf filename ; lexbuf |
module type Toolchain = sig val core_type_with_comments : Lexing . lexbuf -> ( Parsetree . core_type * Reason_comment . t list ) val implementation_with_comments : Lexing . lexbuf -> ( Parsetree . structure * Reason_comment . t list ) val interface_with_comments : Lexing . lexbuf -> ( Parsetree . signature * Reason_com... |
module type Toolchain_spec = sig val safeguard_parsing : Lexing . lexbuf -> ( unit -> ( ' a * Reason_comment . t list ) ) -> ( ' a * Reason_comment . t list ) type token module Lexer_impl : sig val init : unit -> unit val token : Lexing . lexbuf -> token val comments : unit -> ( String . t * Location . t ) list end val... |
let rec left_expand_comment should_scan_prev_line source loc_start = if loc_start = 0 then ( String . unsafe_get source 0 , true , 0 ) else let c = String . unsafe_get source ( loc_start - 1 ) in match c with | ' \ t ' | ' ' -> left_expand_comment should_scan_prev_line source ( loc_start - 1 ) | ' \ n ' when should_sca... |
let rec right_expand_comment should_scan_next_line source loc_start = if loc_start = String . length source then ( String . unsafe_get source ( String . length source - 1 ) , true , String . length source ) else let c = String . unsafe_get source loc_start in match c with | ' \ t ' | ' ' -> right_expand_comment should_... |
module Create_parse_entrypoint ( Toolchain_impl : Toolchain_spec ) : Toolchain = struct let buffer_add_lexbuf buf skip lexbuf = let bytes = lexbuf . Lexing . lex_buffer in let start = lexbuf . Lexing . lex_start_pos + skip in let stop = lexbuf . Lexing . lex_buffer_len in Buffer . add_subbytes buf bytes start ( stop - ... |
module OCaml_syntax = struct module Parser = LiquidOCamlParser module Lexer = LiquidOCamlLexer module Pprintast = LiquidOCamlPrinter let doc_comments_filter ( ) = let open Ast_mapper in let open Parsetree in let seen = Hashtbl . create 7 in let attribute mapper = function | ( { Location . txt = ( " ocaml . doc " | " oc... |
let insert_completion_ident : Lexing . position option ref = ref None |
module Reason_syntax = struct module I = Reason_parser . MenhirInterpreter module Lexer_impl = struct include Reason_lexer let init ( ) = init ? insert_completion_ident :! insert_completion_ident ( ) end type token = Reason_parser . token type tracking_supplier = { mutable last_token : ( token * Lexing . position * Lex... |
module ML = Create_parse_entrypoint ( OCaml_syntax ) |
module RE = Create_parse_entrypoint ( Reason_syntax ) |
let doc_comments_filter ( ) = let open Ast_mapper in let open Parsetree in let seen = Hashtbl . create 7 in let attribute mapper = function | { attr_name = { Location . txt = ( " ocaml . doc " | " ocaml . text " ) } ; attr_payload = PStr [ { pstr_desc = Pstr_eval ( { pexp_desc = Pexp_constant ( Pconst_string ( _text , ... |
module Lexer_impl = struct type t = Lexing . lexbuf let init ? insert_completion_ident : _ lexbuf = Lexer . init ( ) ; lexbuf let token = Lexer . token let filtered_comments = ref [ ] let filter_comments filter = filtered_comments := List . filter filter ( Lexer . comments ( ) ) let get_comments _lexbuf _docstrings = !... |
let parse_and_filter_doc_comments iter fn lexbuf = let it , filter = doc_comments_filter ( ) in let result = fn lexbuf in ignore ( iter it result ) ; Lexer_impl . filter_comments filter ; ( result , ( ) ) |
let implementation lexbuf = parse_and_filter_doc_comments ( fun it -> it . Ast_mapper . structure it ) ( fun lexbuf -> From_current . copy_structure ( Parser . implementation Lexer . token lexbuf ) ) lexbuf |
let core_type lexbuf = parse_and_filter_doc_comments ( fun it -> it . Ast_mapper . typ it ) ( fun lexbuf -> From_current . copy_core_type ( Parser . parse_core_type Lexer . token lexbuf ) ) lexbuf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.