From 0143a7a06f979f04a47027bfdf4e43c8f5dc1dbd Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 15 Jun 2016 16:03:48 +0200 Subject: [PATCH 1/4] Remove unused permitFsharpKeywords switch --- src/fsharp/lexhelp.fs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/fsharp/lexhelp.fs b/src/fsharp/lexhelp.fs index 25f90ab688f..c0a7cf9257b 100644 --- a/src/fsharp/lexhelp.fs +++ b/src/fsharp/lexhelp.fs @@ -312,16 +312,13 @@ module Keywords = let KeywordToken s = keywordTable.[s] - /// ++GLOBAL MUTABLE STATE. Note this is a deprecated, undocumented command line option anyway, we can ignore it. - let mutable permitFsharpKeywords = true - let IdentifierToken args (lexbuf:UnicodeLexing.Lexbuf) (s:string) = if IsCompilerGeneratedName s then warning(Error(FSComp.SR.lexhlpIdentifiersContainingAtSymbolReserved(), lexbuf.LexemeRange)); args.resourceManager.InternIdentifierToken s let KeywordOrIdentifierToken args (lexbuf:UnicodeLexing.Lexbuf) s = - if not permitFsharpKeywords && List.contains s unreserveWords then + if List.contains s unreserveWords then // You can assume this condition never fires - this is a deprecated, undocumented command line option anyway, we can ignore it. IdentifierToken args lexbuf s else From 540a0fe0caa22d88ca53330e659a5d1d306eb336 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 15 Jun 2016 16:08:27 +0200 Subject: [PATCH 2/4] Remove deprecated condition from lexer --- src/fsharp/lexhelp.fs | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/src/fsharp/lexhelp.fs b/src/fsharp/lexhelp.fs index c0a7cf9257b..80ca5951edd 100644 --- a/src/fsharp/lexhelp.fs +++ b/src/fsharp/lexhelp.fs @@ -305,9 +305,9 @@ module Keywords = keywordList |> List.map (fun (_, w, _) -> w) let keywordTable = - // TODO: this doesn't need to be a multi-map, a dictionary will do let tab = System.Collections.Generic.Dictionary(100) - for (_mode,keyword,token) in keywordList do tab.Add(keyword,token) + for (_mode,keyword,token) in keywordList do + tab.Add(keyword,token) tab let KeywordToken s = keywordTable.[s] @@ -318,32 +318,30 @@ module Keywords = args.resourceManager.InternIdentifierToken s let KeywordOrIdentifierToken args (lexbuf:UnicodeLexing.Lexbuf) s = - if List.contains s unreserveWords then - // You can assume this condition never fires - this is a deprecated, undocumented command line option anyway, we can ignore it. - IdentifierToken args lexbuf s - else - let mutable v = Unchecked.defaultof<_> - if keywordTable.TryGetValue(s, &v) then - if (match v with RESERVED -> true | _ -> false) then - warning(ReservedKeyword(FSComp.SR.lexhlpIdentifierReserved(s), lexbuf.LexemeRange)); - IdentifierToken args lexbuf s - else v - else + let mutable v = Unchecked.defaultof<_> + if keywordTable.TryGetValue(s, &v) then + if (match v with RESERVED -> true | _ -> false) then + warning(ReservedKeyword(FSComp.SR.lexhlpIdentifierReserved(s), lexbuf.LexemeRange)); + IdentifierToken args lexbuf s + else v + else match s with | "__SOURCE_DIRECTORY__" -> let filename = fileOfFileIndex lexbuf.StartPos.FileIndex - let dirname = if filename = stdinMockFilename then - System.IO.Directory.GetCurrentDirectory() - else - filename |> FileSystem.GetFullPathShim (* asserts that path is already absolute *) - |> System.IO.Path.GetDirectoryName + let dirname = + if filename = stdinMockFilename then + System.IO.Directory.GetCurrentDirectory() + else + filename + |> FileSystem.GetFullPathShim (* asserts that path is already absolute *) + |> System.IO.Path.GetDirectoryName KEYWORD_STRING dirname | "__SOURCE_FILE__" -> - KEYWORD_STRING (System.IO.Path.GetFileName((fileOfFileIndex lexbuf.StartPos.FileIndex))) + KEYWORD_STRING (System.IO.Path.GetFileName((fileOfFileIndex lexbuf.StartPos.FileIndex))) | "__LINE__" -> - KEYWORD_STRING (string lexbuf.StartPos.Line) + KEYWORD_STRING (string lexbuf.StartPos.Line) | _ -> - IdentifierToken args lexbuf s + IdentifierToken args lexbuf s /// A utility to help determine if an identifier needs to be quoted let QuoteIdentifierIfNeeded (s : string) : string = From 9d003381e49cc4af0583896aaa02836a759080be Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 15 Jun 2016 16:11:16 +0200 Subject: [PATCH 3/4] use pattern matching in lexer --- src/fsharp/lexhelp.fs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/fsharp/lexhelp.fs b/src/fsharp/lexhelp.fs index 80ca5951edd..76e317797bf 100644 --- a/src/fsharp/lexhelp.fs +++ b/src/fsharp/lexhelp.fs @@ -306,7 +306,7 @@ module Keywords = let keywordTable = let tab = System.Collections.Generic.Dictionary(100) - for (_mode,keyword,token) in keywordList do + for _,keyword,token in keywordList do tab.Add(keyword,token) tab @@ -318,13 +318,14 @@ module Keywords = args.resourceManager.InternIdentifierToken s let KeywordOrIdentifierToken args (lexbuf:UnicodeLexing.Lexbuf) s = - let mutable v = Unchecked.defaultof<_> - if keywordTable.TryGetValue(s, &v) then - if (match v with RESERVED -> true | _ -> false) then + match keywordTable.TryGetValue s with + | true,v -> + match v with + | RESERVED -> warning(ReservedKeyword(FSComp.SR.lexhlpIdentifierReserved(s), lexbuf.LexemeRange)); IdentifierToken args lexbuf s - else v - else + | _ -> v + | _ -> match s with | "__SOURCE_DIRECTORY__" -> let filename = fileOfFileIndex lexbuf.StartPos.FileIndex From 6a60bd27525aa4a98441fb191dd474ee7dc8a25d Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Wed, 15 Jun 2016 16:14:44 +0200 Subject: [PATCH 4/4] Remove unused permitFsharpKeywords switch --- src/fsharp/CompileOptions.fs | 2 +- src/fsharp/lexhelp.fsi | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fsharp/CompileOptions.fs b/src/fsharp/CompileOptions.fs index 60f34d73267..11a178d9cea 100644 --- a/src/fsharp/CompileOptions.fs +++ b/src/fsharp/CompileOptions.fs @@ -891,7 +891,7 @@ let compilingFsLib20Flag (tcConfigB : TcConfigBuilder) = let compilingFsLib40Flag (tcConfigB : TcConfigBuilder) = CompilerOption("compiling-fslib-40", tagNone, OptionUnit (fun () -> tcConfigB.compilingFslib40 <- true; ), Some(InternalCommandLineOption("--compiling-fslib-40", rangeCmdArgs)), None) let mlKeywordsFlag = - CompilerOption("ml-keywords", tagNone, OptionUnit (fun () -> Lexhelp.Keywords.permitFsharpKeywords <- false), Some(DeprecatedCommandLineOptionNoDescription("--ml-keywords", rangeCmdArgs)), None) + CompilerOption("ml-keywords", tagNone, OptionUnit (fun () -> ()), Some(DeprecatedCommandLineOptionNoDescription("--ml-keywords", rangeCmdArgs)), None) let gnuStyleErrorsFlag tcConfigB = CompilerOption("gnu-style-errors", tagNone, OptionUnit (fun () -> tcConfigB.errorStyle <- ErrorStyle.EmacsErrors), Some(DeprecatedCommandLineOptionNoDescription("--gnu-style-errors", rangeCmdArgs)), None) diff --git a/src/fsharp/lexhelp.fsi b/src/fsharp/lexhelp.fsi index 4ef4e5edfbb..2d427760799 100644 --- a/src/fsharp/lexhelp.fsi +++ b/src/fsharp/lexhelp.fsi @@ -67,5 +67,4 @@ module Keywords = val KeywordOrIdentifierToken : lexargs -> UnicodeLexing.Lexbuf -> string -> Parser.token val IdentifierToken : lexargs -> UnicodeLexing.Lexbuf -> string -> Parser.token val QuoteIdentifierIfNeeded : string -> string - val mutable permitFsharpKeywords : bool val keywordNames : string list