Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

# Spelling, https://github.com/dotnet/fsharp/pull/16212
23e91e1322363a7e9c34baaeabbf0391c4b7eafd

# Remove all trailing whitespaces, https://github.com/dotnet/fsharp/pull/20355
b64623e8bb20ff2676e8c90813d2e2c72d9a81fb
2 changes: 1 addition & 1 deletion buildtools/AssemblyCheck/AssemblyCheck.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module AssemblyCheck =
printfn "All shipping assemblies had an embedded PDB."

// return code is the number of failures
failedVersionCheck.Length + failedCommitHash.Length + failedVerifyEmbeddedPdb.Length
failedVersionCheck.Length + failedCommitHash.Length + failedVerifyEmbeddedPdb.Length


[<EntryPoint>]
Expand Down
98 changes: 49 additions & 49 deletions buildtools/fslex/Arg.fs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// (c) Microsoft Corporation 2005-2009.
// (c) Microsoft Corporation 2005-2009.

namespace FSharp.Text

type ArgType =
type ArgType =
| ClearArg of bool ref
| FloatArg of (float -> unit)
| IntArg of (int -> unit)
Expand All @@ -19,22 +19,22 @@ type ArgType =
static member Unit r = UnitArg r


type ArgInfo (name,action,help) =
type ArgInfo (name,action,help) =
member x.Name = name
member x.ArgType = action
member x.HelpText = help

exception Bad of string
exception HelpText of string

[<Sealed>]
type ArgParser() =
static let getUsage specs u =
let sbuf = System.Text.StringBuilder 100
let pstring (s:string) = sbuf.Append s |> ignore
let pendline s = pstring s; pstring "\n"
type ArgParser() =
static let getUsage specs u =
let sbuf = System.Text.StringBuilder 100
let pstring (s:string) = sbuf.Append s |> ignore
let pendline s = pstring s; pstring "\n"
pendline u;
List.iter (fun (arg:ArgInfo) ->
List.iter (fun (arg:ArgInfo) ->
match arg.Name, arg.ArgType, arg.HelpText with
| s, (UnitArg _ | SetArg _ | ClearArg _), helpText -> pstring "\t"; pstring s; pstring ": "; pendline helpText
| s, StringArg _, helpText -> pstring "\t"; pstring s; pstring " <string>: "; pendline helpText
Expand All @@ -50,79 +50,79 @@ type ArgParser() =
static member ParsePartial(cursor,argv,arguments:seq<ArgInfo>,?otherArgs,?usageText) =
let other = defaultArg otherArgs (fun _ -> ())
let usageText = defaultArg usageText ""
let nargs = Array.length argv
let nargs = Array.length argv
incr cursor;
let argSpecs = arguments |> Seq.toList
let specs = argSpecs |> List.map (fun (arg:ArgInfo) -> arg.Name, arg.ArgType)
while !cursor < nargs do
let arg = argv.[!cursor]
let rec findMatchingArg args =
let arg = argv.[!cursor]
let rec findMatchingArg args =
match args with
| (s, action) :: _ when s = arg ->
let getSecondArg () =
if !cursor + 1 >= nargs then
| (s, action) :: _ when s = arg ->
let getSecondArg () =
if !cursor + 1 >= nargs then
raise(Bad("option "+s+" needs an argument.\n"+getUsage argSpecs usageText));
argv.[!cursor+1]
match action with
| UnitArg f ->
f ();
argv.[!cursor+1]

match action with
| UnitArg f ->
f ();
incr cursor
| SetArg f ->
f := true;
f := true;
incr cursor
| ClearArg f ->
f := false;
| ClearArg f ->
f := false;
incr cursor
| StringArg f->
let arg2 = getSecondArg()
f arg2;
| StringArg f->
let arg2 = getSecondArg()
f arg2;
cursor := !cursor + 2
| IntArg f ->
let arg2 = getSecondArg ()
let arg2 = try int32 arg2 with _ -> raise(Bad(getUsage argSpecs usageText)) in
| IntArg f ->
let arg2 = getSecondArg ()
let arg2 = try int32 arg2 with _ -> raise(Bad(getUsage argSpecs usageText)) in
f arg2;
cursor := !cursor + 2;
| FloatArg f ->
let arg2 = getSecondArg()
let arg2 = try float arg2 with _ -> raise(Bad(getUsage argSpecs usageText)) in
f arg2;
| FloatArg f ->
let arg2 = getSecondArg()
let arg2 = try float arg2 with _ -> raise(Bad(getUsage argSpecs usageText)) in
f arg2;
cursor := !cursor + 2;
| RestArg f ->
| RestArg f ->
incr cursor;
while !cursor < nargs do
f argv.[!cursor];
incr cursor;

| _ :: more -> findMatchingArg more
| [] ->
| _ :: more -> findMatchingArg more
| [] ->
if arg = "-help" || arg = "--help" || arg = "/help" || arg = "/help" || arg = "/?" then
raise (HelpText (getUsage argSpecs usageText))
// Note: for '/abc/def' does not count as an argument
// Note: '/abc' does
elif arg.Length>0 && (arg.[0] = '-' || (arg.[0] = '/' && not (arg.Length > 1 && arg.[1..].Contains "/"))) then
raise (Bad ("unrecognized argument: "+ arg + "\n" + getUsage argSpecs usageText))
else
else
other arg;
incr cursor
findMatchingArg specs
findMatchingArg specs

static member Usage (arguments, ?usage) =
static member Usage (arguments, ?usage) =
let usage = defaultArg usage ""
System.Console.Error.WriteLine (getUsage (Seq.toList arguments) usage)

#if FX_NO_COMMAND_LINE_ARGS
#else
static member Parse (arguments, ?otherArgs,?usageText) =
static member Parse (arguments, ?otherArgs,?usageText) =
let current = ref 0
let argv = System.Environment.GetCommandLineArgs()
let argv = System.Environment.GetCommandLineArgs()
try ArgParser.ParsePartial (current, argv, arguments, ?otherArgs=otherArgs, ?usageText=usageText)
with
| Bad h
| HelpText h ->
System.Console.Error.WriteLine h;
System.Console.Error.Flush();
System.Environment.Exit(1);
| _ ->
with
| Bad h
| HelpText h ->
System.Console.Error.WriteLine h;
System.Console.Error.Flush();
System.Environment.Exit(1);
| _ ->
reraise()
#endif
8 changes: 4 additions & 4 deletions buildtools/fslex/Arg.fsi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// (c) Microsoft Corporation 2005-2009.
// (c) Microsoft Corporation 2005-2009.

/// A simple command-line argument processor.
namespace FSharp.Text

/// The spec value describes the action of the argument,
/// and whether it expects a following parameter.
[<Sealed>]
type ArgType =
type ArgType =
static member Clear : bool ref -> ArgType
static member Float : (float -> unit) -> ArgType
static member Int : (int -> unit) -> ArgType
Expand All @@ -15,7 +15,7 @@ type ArgType =
static member String : (string -> unit) -> ArgType
static member Unit : (unit -> unit) -> ArgType

type ArgInfo =
type ArgInfo =
new : name:string * action:ArgType * help:string -> ArgInfo
/// Return the name of the argument
member Name : string
Expand All @@ -25,7 +25,7 @@ type ArgInfo =
member HelpText : string

[<Sealed>]
type ArgParser =
type ArgParser =
#if FX_NO_COMMAND_LINE_ARGS
#else

Expand Down
Loading
Loading