Skip to content

Commit cad6ec2

Browse files
authored
Merge pull request #1263 from forki/clean-lex
Clean lexer
2 parents 94e125a + 6a60bd2 commit cad6ec2

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

src/fsharp/CompileOptions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,7 @@ let compilingFsLib20Flag (tcConfigB : TcConfigBuilder) =
891891
let compilingFsLib40Flag (tcConfigB : TcConfigBuilder) =
892892
CompilerOption("compiling-fslib-40", tagNone, OptionUnit (fun () -> tcConfigB.compilingFslib40 <- true; ), Some(InternalCommandLineOption("--compiling-fslib-40", rangeCmdArgs)), None)
893893
let mlKeywordsFlag =
894-
CompilerOption("ml-keywords", tagNone, OptionUnit (fun () -> Lexhelp.Keywords.permitFsharpKeywords <- false), Some(DeprecatedCommandLineOptionNoDescription("--ml-keywords", rangeCmdArgs)), None)
894+
CompilerOption("ml-keywords", tagNone, OptionUnit (fun () -> ()), Some(DeprecatedCommandLineOptionNoDescription("--ml-keywords", rangeCmdArgs)), None)
895895

896896
let gnuStyleErrorsFlag tcConfigB =
897897
CompilerOption("gnu-style-errors", tagNone, OptionUnit (fun () -> tcConfigB.errorStyle <- ErrorStyle.EmacsErrors), Some(DeprecatedCommandLineOptionNoDescription("--gnu-style-errors", rangeCmdArgs)), None)

src/fsharp/lexhelp.fs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -305,48 +305,44 @@ module Keywords =
305305
keywordList |> List.map (fun (_, w, _) -> w)
306306

307307
let keywordTable =
308-
// TODO: this doesn't need to be a multi-map, a dictionary will do
309308
let tab = System.Collections.Generic.Dictionary<string,token>(100)
310-
for (_mode,keyword,token) in keywordList do tab.Add(keyword,token)
309+
for _,keyword,token in keywordList do
310+
tab.Add(keyword,token)
311311
tab
312312

313313
let KeywordToken s = keywordTable.[s]
314314

315-
/// ++GLOBAL MUTABLE STATE. Note this is a deprecated, undocumented command line option anyway, we can ignore it.
316-
let mutable permitFsharpKeywords = true
317-
318315
let IdentifierToken args (lexbuf:UnicodeLexing.Lexbuf) (s:string) =
319316
if IsCompilerGeneratedName s then
320317
warning(Error(FSComp.SR.lexhlpIdentifiersContainingAtSymbolReserved(), lexbuf.LexemeRange));
321318
args.resourceManager.InternIdentifierToken s
322319

323320
let KeywordOrIdentifierToken args (lexbuf:UnicodeLexing.Lexbuf) s =
324-
if not permitFsharpKeywords && List.contains s unreserveWords then
325-
// You can assume this condition never fires - this is a deprecated, undocumented command line option anyway, we can ignore it.
326-
IdentifierToken args lexbuf s
327-
else
328-
let mutable v = Unchecked.defaultof<_>
329-
if keywordTable.TryGetValue(s, &v) then
330-
if (match v with RESERVED -> true | _ -> false) then
331-
warning(ReservedKeyword(FSComp.SR.lexhlpIdentifierReserved(s), lexbuf.LexemeRange));
332-
IdentifierToken args lexbuf s
333-
else v
334-
else
321+
match keywordTable.TryGetValue s with
322+
| true,v ->
323+
match v with
324+
| RESERVED ->
325+
warning(ReservedKeyword(FSComp.SR.lexhlpIdentifierReserved(s), lexbuf.LexemeRange));
326+
IdentifierToken args lexbuf s
327+
| _ -> v
328+
| _ ->
335329
match s with
336330
| "__SOURCE_DIRECTORY__" ->
337331
let filename = fileOfFileIndex lexbuf.StartPos.FileIndex
338-
let dirname = if filename = stdinMockFilename then
339-
System.IO.Directory.GetCurrentDirectory()
340-
else
341-
filename |> FileSystem.GetFullPathShim (* asserts that path is already absolute *)
342-
|> System.IO.Path.GetDirectoryName
332+
let dirname =
333+
if filename = stdinMockFilename then
334+
System.IO.Directory.GetCurrentDirectory()
335+
else
336+
filename
337+
|> FileSystem.GetFullPathShim (* asserts that path is already absolute *)
338+
|> System.IO.Path.GetDirectoryName
343339
KEYWORD_STRING dirname
344340
| "__SOURCE_FILE__" ->
345-
KEYWORD_STRING (System.IO.Path.GetFileName((fileOfFileIndex lexbuf.StartPos.FileIndex)))
341+
KEYWORD_STRING (System.IO.Path.GetFileName((fileOfFileIndex lexbuf.StartPos.FileIndex)))
346342
| "__LINE__" ->
347-
KEYWORD_STRING (string lexbuf.StartPos.Line)
343+
KEYWORD_STRING (string lexbuf.StartPos.Line)
348344
| _ ->
349-
IdentifierToken args lexbuf s
345+
IdentifierToken args lexbuf s
350346

351347
/// A utility to help determine if an identifier needs to be quoted
352348
let QuoteIdentifierIfNeeded (s : string) : string =

src/fsharp/lexhelp.fsi

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,4 @@ module Keywords =
6767
val KeywordOrIdentifierToken : lexargs -> UnicodeLexing.Lexbuf -> string -> Parser.token
6868
val IdentifierToken : lexargs -> UnicodeLexing.Lexbuf -> string -> Parser.token
6969
val QuoteIdentifierIfNeeded : string -> string
70-
val mutable permitFsharpKeywords : bool
7170
val keywordNames : string list

0 commit comments

Comments
 (0)