text stringlengths 0 601k |
|---|
let isStructureItemStart = function | Token . Open | Let | Typ | External | Import | Export | Exception | Include | Module | AtAt | PercentPercent | At -> true | t when isExprStart t -> true | _ -> false |
let isPatternStart = function | Token . Int _ | Float _ | String _ | Character _ | Backtick | True | False | Minus | Plus | Lparen | Lbracket | Lbrace | List | Underscore | Lident _ | Uident _ | Hash | Exception | Lazy | Percent | Module | At -> true | _ -> false |
let isParameterStart = function | Token . Typ | Tilde | Dot -> true | token when isPatternStart token -> true | _ -> false |
let isStringFieldDeclStart = function | Token . String _ | Lident _ | At | DotDotDot -> true | _ -> false |
let isFieldDeclStart = function | Token . At | Mutable | Lident _ -> true | Uident _ -> true | t when Token . isKeyword t -> true | _ -> false |
let isRecordDeclStart = function | Token . At | Mutable | Lident _ -> true | _ -> false |
let isTypExprStart = function | Token . At | SingleQuote | Underscore | Lparen | Lbracket | Uident _ | Lident _ | Module | Percent | Lbrace -> true | _ -> false |
let isTypeParameterStart = function | Token . Tilde | Dot -> true | token when isTypExprStart token -> true | _ -> false |
let isTypeParamStart = function | Token . Plus | Minus | SingleQuote | Underscore -> true | _ -> false |
let isFunctorArgStart = function | Token . At | Uident _ | Underscore | Percent | Lbrace | Lparen -> true | _ -> false |
let isModExprStart = function | Token . At | Percent | Uident _ | Lbrace | Lparen | Lident " unpack " -> true | _ -> false |
let isRecordRowStart = function | Token . DotDotDot -> true | Token . Uident _ | Lident _ -> true | t when Token . isKeyword t -> true | _ -> false |
let isRecordRowStringKeyStart = function | Token . String _ -> true | _ -> false |
let isArgumentStart = function | Token . Tilde | Dot | Underscore -> true | t when isExprStart t -> true | _ -> false |
let isPatternMatchStart = function | Token . Bar -> true | t when isPatternStart t -> true | _ -> false |
let isPatternOcamlListStart = function | Token . DotDotDot -> true | t when isPatternStart t -> true | _ -> false |
let isPatternRecordItemStart = function | Token . DotDotDot | Uident _ | Lident _ | Underscore -> true | _ -> false |
let isAttributeStart = function | Token . At -> true | _ -> false |
let isJsFfiImportStart = function | Token . Lident _ | At -> true | _ -> false |
let isBlockExprStart = function | Token . At | Hash | Percent | Minus | MinusDot | Plus | PlusDot | Bang | True | False | Float _ | Int _ | String _ | Character _ | Lident _ | Uident _ | Lparen | List | Lbracket | Lbrace | Forwardslash | Assert | Lazy | If | For | While | Switch | Open | Module | Exception | Let | Less... |
let isListElement grammar token = match grammar with | ExprList -> token = Token . DotDotDot || isExprStart token | ListExpr -> token = DotDotDot || isExprStart token | PatternList -> token = DotDotDot || isPatternStart token | ParameterList -> isParameterStart token | StringFieldDeclarations -> isStringFieldDeclStart ... |
let isListTerminator grammar token = match grammar , token with | _ , Token . Eof | ExprList , ( Rparen | Forwardslash | Rbracket ) | ListExpr , Rparen | ArgumentList , Rparen | TypExprList , ( Rparen | Forwardslash | GreaterThan | Equal ) | ModExprList , Rparen | ( PatternList | PatternOcamlList | PatternRecord ) , ( ... |
let isPartOfList grammar token = isListElement grammar token || isListTerminator grammar token |
type scope = | Global | Module of string | Scope of Longident . t |
type label_declaration = { jld_attributes : Parsetree . attributes ; [ @ live ] jld_name : string ; jld_alias : string ; jld_type : Parsetree . core_type ; jld_loc : Location . t } |
type importSpec = | Default of label_declaration | Spec of label_declaration list |
type import_description = { jid_loc : Location . t ; jid_spec : importSpec ; jid_scope : scope ; jid_attributes : Parsetree . attributes ; } |
let decl ~ attrs ~ loc ~ name ~ alias ~ typ = { jld_loc = loc ; jld_attributes = attrs ; jld_name = name ; jld_alias = alias ; jld_type = typ } |
let importDescr ~ attrs ~ scope ~ importSpec ~ loc = { jid_loc = loc ; jid_spec = importSpec ; jid_scope = scope ; jid_attributes = attrs ; } |
let toParsetree importDescr = let bsVal = ( Location . mknoloc " val " , Parsetree . PStr [ ] ) in let attrs = match importDescr . jid_scope with | Global -> [ bsVal ] | Module s -> let structure = [ Parsetree . Pconst_string ( s , None ) |> Ast_helper . Exp . constant |> Ast_helper . Str . eval ] in let genType = ( Lo... |
type t = { mutable buffer : bytes ; mutable position : int ; mutable length : int ; } |
let create n = let n = if n < 1 then 1 else n in let s = ( Bytes . create [ @ doesNotRaise ] ) n in { buffer = s ; position = 0 ; length = n } |
let contents b = ( Bytes . sub_string [ @ doesNotRaise ] ) b . buffer 0 b . position |
let resize_internal b more = let len = b . length in let new_len = ref len in while b . position + more > ! new_len do new_len := 2 * ! new_len done ; if ! new_len > Sys . max_string_length then begin if b . position + more <= Sys . max_string_length then new_len := Sys . max_string_length end ; let new_buffer = ( Byte... |
let add_char b c = let pos = b . position in if pos >= b . length then resize_internal b 1 ; Bytes . unsafe_set b . buffer pos c ; b . position <- pos + 1 |
let add_string b s = let len = String . length s in let new_position = b . position + len in if new_position > b . length then resize_internal b len ; Bytes . blit_string s 0 b . buffer b . position len [ @ doesNotRaise ] ; b . position <- new_position |
let flush_newline b = let position = ref ( b . position ) in while ( Bytes . unsafe_get b . buffer ( ! position - 1 ) ) = ' ' && ! position >= 0 do position := ! position - 1 ; done ; b . position <- ! position ; add_char b ' \ n ' |
let printRes ~ isInterface ~ filename = if isInterface then let parseResult = Res_driver . parsingEngine . parseInterface ~ forPrinter : true ~ filename in if parseResult . invalid then begin Res_diagnostics . printReport parseResult . diagnostics parseResult . source ; exit 1 end else Res_printer . printInterface ~ wi... |
let printMl ~ isInterface ~ filename = if isInterface then let parseResult = Res_driver_ml_parser . parsingEngine . parseInterface ~ forPrinter : true ~ filename in Res_printer . printInterface ~ width : defaultPrintWidth ~ comments : parseResult . comments ( From_current . copy_signature parseResult . parsetree ) else... |
let printReason ~ refmtPath ~ isInterface ~ filename = let ( tempFilename , chan ) = Filename . open_temp_file " refmt " ( if isInterface then " . rei " else " . re " ) in close_out chan ; IO . writeFile ~ filename : tempFilename ~ contents ( : IO . readFile ~ filename ) ; let cmd = Printf . sprintf " % s -- print = bi... |
let print language ~ input = let isInterface = let len = String . length input in len > 0 && String . unsafe_get input ( len - 1 ) = ' i ' in match language with | ` res -> printRes ~ isInterface ~ filename : input | ` ml -> printMl ~ isInterface ~ filename : input | ` refmt path -> printReason ~ refmtPath : path ~ isI... |
let rec unsafe_for_all_range s ~ start ~ finish p = start > finish || p ( String . unsafe_get s start ) && unsafe_for_all_range s ~ start ( : start + 1 ) ~ finish p |
let for_all_from s start p = let len = String . length s in unsafe_for_all_range s ~ start ~ finish ( : len - 1 ) p |
let isValidNumericPolyvarNumber ( x : string ) = let len = String . length x in len > 0 && ( let a = Char . code ( String . unsafe_get x 0 ) in a <= 57 && ( if len > 1 then a > 48 && for_all_from x 1 ( function ' 0 ' . . ' 9 ' -> true | _ -> false ) else a >= 48 ) ) |
let isArityIdent ident = if String . length ident >= 6 then ( String . sub [ @ doesNotRaise ] ) ident 0 5 = " arity " else false |
type identifierStyle = | ExoticIdent | NormalIdent |
let classifyIdentContent ~ allowUident txt = let len = String . length txt in let rec go i = if i == len then NormalIdent else let c = String . unsafe_get txt i in if i == 0 && not ( ( allowUident && ( c >= ' A ' && c <= ' Z ' ) ) || ( c >= ' a ' && c <= ' z ' ) || c = ' _ ' ) then ExoticIdent else if not ( ( c >= ' a ... |
let printIdentLike ~ allowUident txt = match classifyIdentContent ~ allowUident txt with | ExoticIdent -> Doc . concat [ Doc . text " " " ; \\\ Doc . text txt ; Doc . text " " " \ ] | NormalIdent -> Doc . text txt |
let printPolyVarIdent txt = if isValidNumericPolyvarNumber txt then Doc . text txt else match classifyIdentContent ~ allowUident : true txt with | ExoticIdent -> Doc . concat [ Doc . text " " " ; \ Doc . text txt ; Doc . text " " " \ ] | NormalIdent -> Doc . text txt let parenthesized_ident _name = true let escapeStrin... |
let wrap f g fmt x = g fmt ( f x ) let setup = lazy begin let open From_current in Oprint . out_value := wrap copy_out_value printOutValue ; Oprint . out_type := wrap copy_out_type printOutType ; Oprint . out_module_type := wrap copy_out_module_type printOutModuleType ; Oprint . out_sig_item := wrap copy_out_sig_item p... |
type kind = Parenthesized | Braced of Location . t | Nothing let expr expr = let optBraces , _ = ParsetreeViewer . processBracesAttr expr in match optBraces with | Some ( { Location . loc = bracesLoc } , _ ) -> Braced ( bracesLoc ) | _ -> begin match expr with | { Parsetree . pexp_desc = Pexp_constraint ( { pexp_desc =... |
let arrowReturnTypExpr typExpr = match typExpr . Parsetree . ptyp_desc with | Parsetree . Ptyp_arrow _ -> true | _ -> false |
let patternRecordRowRhs ( pattern : Parsetree . pattern ) = match pattern . ppat_desc with | Ppat_constraint ( { ppat_desc = Ppat_unpack _ } , { ptyp_desc = Ptyp_package _ } ) -> false | Ppat_constraint _ -> true | _ -> false |
type mode = ParseForTypeChecker | Default |
type regionStatus = Report | Silent |
type t = { mode : mode ; mutable scanner : Scanner . t ; mutable token : Token . t ; mutable startPos : Lexing . position ; mutable endPos : Lexing . position ; mutable prevEndPos : Lexing . position ; mutable breadcrumbs : ( Grammar . t * Lexing . position ) list ; mutable errors : Reporting . parseError list ; mutabl... |
let err ? startPos ? endPos p error = match p . regions with | { contents = Report } as region :: _ -> let d = Diagnostics . make ~ startPos ( : match startPos with | Some pos -> pos | None -> p . startPos ) ~ endPos ( : match endPos with | Some pos -> pos | None -> p . endPos ) error in ( p . diagnostics <- d :: p . d... |
let beginRegion p = p . regions <- ref Report :: p . regions |
let endRegion p = match p . regions with | [ ] -> ( ) | _ :: rest -> p . regions <- rest |
let rec next ? prevEndPos p = let prevEndPos = match prevEndPos with Some pos -> pos | None -> p . endPos in let ( startPos , endPos , token ) = Scanner . scan p . scanner in match token with | Comment c -> Comment . setPrevTokEndPos c p . endPos ; p . comments <- c :: p . comments ; p . prevEndPos <- p . endPos ; p . ... |
let nextTemplateLiteralToken p = let ( startPos , endPos , token ) = Scanner . scanTemplateLiteralToken p . scanner in p . token <- token ; p . prevEndPos <- p . endPos ; p . startPos <- startPos ; p . endPos <- endPos |
let checkProgress ~ prevEndPos ~ result p = if p . endPos == prevEndPos then None else Some result |
let make ( ? mode = ParseForTypeChecker ) src filename = let scanner = Scanner . make ~ filename src in let parserState = { mode ; scanner ; token = Token . Eof ; startPos = Lexing . dummy_pos ; prevEndPos = Lexing . dummy_pos ; endPos = Lexing . dummy_pos ; breadcrumbs = [ ] ; errors = [ ] ; diagnostics = [ ] ; commen... |
let leaveBreadcrumb p circumstance = let crumb = ( circumstance , p . startPos ) in p . breadcrumbs <- crumb :: p . breadcrumbs |
let eatBreadcrumb p = match p . breadcrumbs with | [ ] -> ( ) | _ :: crumbs -> p . breadcrumbs <- crumbs |
let optional p token = if p . token = token then let ( ) = next p in true else false |
let expect ? grammar token p = if p . token = token then next p else let error = Diagnostics . expected ? grammar p . prevEndPos token in err ~ startPos : p . prevEndPos p error |
let lookahead p callback = let err = p . scanner . err in let ch = p . scanner . ch in let offset = p . scanner . offset in let lineOffset = p . scanner . lineOffset in let lnum = p . scanner . lnum in let mode = p . scanner . mode in let token = p . token in let startPos = p . startPos in let endPos = p . endPos in le... |
let arrowType ct = let rec process attrsBefore acc typ = match typ with | { ptyp_desc = Ptyp_arrow ( Nolabel as lbl , typ1 , typ2 ) ; ptyp_attributes = [ ] } -> let arg = ( [ ] , lbl , typ1 ) in process attrsBefore ( arg :: acc ) typ2 | { ptyp_desc = Ptyp_arrow ( Nolabel as lbl , typ1 , typ2 ) ; ptyp_attributes = [ ( {... |
let functorType modtype = let rec process acc modtype = match modtype with | { pmty_desc = Pmty_functor ( lbl , argType , returnType ) ; pmty_attributes = attrs } -> let arg = ( attrs , lbl , argType ) in process ( arg :: acc ) returnType | modType -> ( List . rev acc , modType ) in process [ ] modtype |
let processUncurriedAttribute attrs = let rec process uncurriedSpotted acc attrs = match attrs with | [ ] -> ( uncurriedSpotted , List . rev acc ) | ( { Location . txt = " bs " } , _ ) :: rest -> process true acc rest | attr :: rest -> process uncurriedSpotted ( attr :: acc ) rest in process false [ ] attrs |
let collectListExpressions expr = let rec collect acc expr = match expr . pexp_desc with | Pexp_construct ( { txt = Longident . Lident " [ ] " } , _ ) -> ( List . rev acc , None ) | Pexp_construct ( { txt = Longident . Lident " " } , :: Some { pexp_desc = Pexp_tuple ( hd [ :: tail ] ) } ) -> collect ( hd :: acc ) tail ... |
let rewriteUnderscoreApply expr = match expr . pexp_desc with | Pexp_fun ( Nolabel , None , { ppat_desc = Ppat_var { txt " = __x " } } , ( { pexp_desc = Pexp_apply ( callExpr , args ) } as e ) ) -> let newArgs = List . map ( fun arg -> match arg with | ( lbl , ( { pexp_desc = Pexp_ident ( { txt = Longident . Lident " _... |
type funParamKind = | Parameter of { attrs : Parsetree . attributes ; lbl : Asttypes . arg_label ; defaultExpr : Parsetree . expression option ; pat : Parsetree . pattern ; } | NewTypes of { attrs : Parsetree . attributes ; locs : string Asttypes . loc list } |
let funExpr expr = let rec collectNewTypes acc returnExpr = match returnExpr with | { pexp_desc = Pexp_newtype ( stringLoc , returnExpr ) ; pexp_attributes = [ ] } -> collectNewTypes ( stringLoc :: acc ) returnExpr | returnExpr -> ( List . rev acc , returnExpr ) in let rec collect attrsBefore acc expr = match expr with... |
let processBracesAttr expr = match expr . pexp_attributes with | ( ( { txt = " ns . braces " } , _ ) as attr ) :: attrs -> ( Some attr , { expr with pexp_attributes = attrs } ) | _ -> ( None , expr ) |
let filterParsingAttrs attrs = List . filter ( fun attr -> match attr with | ( { Location . txt = ( " ns . ternary " | " ns . braces " | " bs " | " ns . iflet " | " ns . namedArgLoc " ) } , _ ) -> false | _ -> true ) attrs |
let isBlockExpr expr = match expr . pexp_desc with | Pexp_letmodule _ | Pexp_letexception _ | Pexp_let _ | Pexp_open _ | Pexp_sequence _ -> true | _ -> false |
let isBracedExpr expr = match processBracesAttr expr with | ( Some _ , _ ) -> true | _ -> false |
let isMultilineText txt = let len = String . length txt in let rec check i = if i >= len then false else let c = String . unsafe_get txt i in match c with | ' \ 010 ' | ' \ 013 ' -> true | ' ' \\ -> if ( i + 2 ) = len then false else check ( i + 2 ) | _ -> check ( i + 1 ) in check 0 |
let isHuggableExpression expr = match expr . pexp_desc with | Pexp_array _ | Pexp_tuple _ | Pexp_constant ( Pconst_string ( _ , Some _ ) ) | Pexp_construct ( { txt = Longident . Lident ( " " :: | " [ ] " ) } , _ ) | Pexp_extension ( { txt = " bs . obj " | " obj " } , _ ) | Pexp_record _ -> true | _ when isBlockExpr exp... |
let isHuggableRhs expr = match expr . pexp_desc with | Pexp_array _ | Pexp_tuple _ | Pexp_construct ( { txt = Longident . Lident ( " " :: | " [ ] " ) } , _ ) | Pexp_extension ( { txt = " bs . obj " | " obj " } , _ ) | Pexp_record _ -> true | _ when isBracedExpr expr -> true | _ -> false |
let isHuggablePattern pattern = match pattern . ppat_desc with | Ppat_array _ | Ppat_tuple _ | Ppat_record _ | Ppat_variant _ | Ppat_construct _ -> true | _ -> false |
let operatorPrecedence operator = match operator with | " " := -> 1 | " " || -> 2 | " " && -> 3 | " " = | " " == | " " < | " " > | " " != | " " <> | " " !== | " " <= | " " >= | " " |> -> 4 | " " + | " . " + | " " - | " . " - | " " ^ -> 5 | " " * | " . " * | " " / | " . " / -> 6 | " " ** -> 7 | " " # | " " ## | " . " | ... |
let isUnaryOperator operator = match operator with | " " ~+ | " . " ~+ | " " ~- | " . " ~- | " not " -> true | _ -> false |
let isUnaryExpression expr = match expr . pexp_desc with | Pexp_apply ( { pexp_desc = Pexp_ident { txt = Longident . Lident operator } } , [ Nolabel , _arg ] ) when isUnaryOperator operator -> true | _ -> false |
let isBinaryOperator operator = match operator with | " " := | " " || | " " && | " " = | " " == | " " < | " " > | " " != | " " !== | " " <= | " " >= | " " |> | " " + | " . " + | " " - | " . " - | " " ^ | " " * | " . " * | " " / | " . " / | " " ** | " . " | | " " <> -> true | _ -> false |
let isBinaryExpression expr = match expr . pexp_desc with | Pexp_apply ( { pexp_desc = Pexp_ident { txt = Longident . Lident operator ; loc = operatorLoc } } , [ ( Nolabel , _operand1 ) ; ( Nolabel , _operand2 ) ] ) when isBinaryOperator operator && not ( operatorLoc . loc_ghost && operator = " " ) ^ -> true | _ -> fal... |
let isEqualityOperator operator = match operator with | " " = | " " == | " " <> | " " != -> true | _ -> false |
let flattenableOperators parentOperator childOperator = let precParent = operatorPrecedence parentOperator in let precChild = operatorPrecedence childOperator in if precParent == precChild then not ( isEqualityOperator parentOperator && isEqualityOperator childOperator ) else false |
let rec hasIfLetAttribute attrs = match attrs with | [ ] -> false | ( { Location . txt " = ns . iflet " } , _ ) :: _ -> true | _ :: attrs -> hasIfLetAttribute attrs |
let isIfLetExpr expr = match expr with | { pexp_attributes = attrs ; pexp_desc = Pexp_match _ } when hasIfLetAttribute attrs -> true | _ -> false |
let hasAttributes attrs = List . exists ( fun attr -> match attr with | ( { Location . txt = " bs " | " ns . ternary " | " ns . braces " | " ns . iflet " } , _ ) -> false | ( { Location . txt " = warning " } , PStr [ { pstr_desc = Pstr_eval ( { pexp_desc = Pexp_constant ( Pconst_string ( " - 4 " , None ) ) } , _ ) } ] ... |
let isArrayAccess expr = match expr . pexp_desc with | Pexp_apply ( { pexp_desc = Pexp_ident { txt = Longident . Ldot ( Lident " Array " , " get " ) } } , [ Nolabel , _parentExpr ; Nolabel , _memberExpr ] ) -> true | _ -> false |
let collectIfExpressions expr = let rec collect acc expr = match expr . pexp_desc with | Pexp_ifthenelse ( ifExpr , thenExpr , Some elseExpr ) -> collect ( ( If ( ifExpr ) , thenExpr ) :: acc ) elseExpr | Pexp_ifthenelse ( ifExpr , thenExpr , ( None as elseExpr ) ) -> let ifs = List . rev ( ( If ( ifExpr ) , thenExpr )... |
let rec hasTernaryAttribute attrs = match attrs with | [ ] -> false | ( { Location . txt " = ns . ternary " } , _ ) :: _ -> true | _ :: attrs -> hasTernaryAttribute attrs |
let isTernaryExpr expr = match expr with | { pexp_attributes = attrs ; pexp_desc = Pexp_ifthenelse _ } when hasTernaryAttribute attrs -> true | _ -> false |
let collectTernaryParts expr = let rec collect acc expr = match expr with | { pexp_attributes = attrs ; pexp_desc = Pexp_ifthenelse ( condition , consequent , Some ( alternate ) ) } when hasTernaryAttribute attrs -> collect ( ( condition , consequent ) :: acc ) alternate | alternate -> ( List . rev acc , alternate ) in... |
let parametersShouldHug parameters = match parameters with | [ Parameter { attrs = [ ] ; lbl = Asttypes . Nolabel ; defaultExpr = None ; pat = pat } ] when isHuggablePattern pat -> true | _ -> false |
let filterTernaryAttributes attrs = List . filter ( fun attr -> match attr with ( { | Location . txt " = ns . ternary " } , _ ) -> false | _ -> true ) attrs |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.