Skip to content

Commit

Permalink
Revert parser adding new line symbol to source
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed Sep 20, 2017
1 parent 5d098c4 commit 8789950
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/fsharp/vs/service.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,10 +1480,15 @@ module internal Parser =
let tokenizer = LexFilter.LexFilter(lightSyntaxStatus, options.CompilingFsLib, Lexer.token lexargs true, lexbuf)
tokenizer.Lexer

// Adding this new-line character at the end of the source seems odd but is required for some unit tests
// Todo: fix tests
let addNewLine (source: string) =
if source.Length = 0 || not (source.[source.Length - 1] = '\n') then source + "\n" else source

let matchBraces(source, fileName, options: FSharpParsingOptions, userOpName: string) =
Trace.TraceInformation("FCS: {0}.{1} ({2})", userOpName, "matchBraces", fileName)
let matchingBraces = new ResizeArray<_>()
Lexhelp.usingLexbufForParsing(UnicodeLexing.StringAsLexbuf(source), fileName) (fun lexbuf ->
Lexhelp.usingLexbufForParsing(UnicodeLexing.StringAsLexbuf(addNewLine source), fileName) (fun lexbuf ->
let errHandler = ErrorHandler(false, fileName, options.ErrorSeverityOptions, source)
let lexfun = createLexerFunction fileName options lexbuf errHandler
let parenTokensBalance t1 t2 =
Expand Down Expand Up @@ -1519,7 +1524,7 @@ module internal Parser =
use unwindBP = PushThreadBuildPhaseUntilUnwind BuildPhase.Parse

let parseResult =
Lexhelp.usingLexbufForParsing(UnicodeLexing.StringAsLexbuf(source), fileName) (fun lexbuf ->
Lexhelp.usingLexbufForParsing(UnicodeLexing.StringAsLexbuf(addNewLine source), fileName) (fun lexbuf ->
let lexfun = createLexerFunction fileName options lexbuf errHandler
let isLastCompiland =
fileName.Equals(options.LastFileName, StringComparison.CurrentCultureIgnoreCase) ||
Expand Down
4 changes: 2 additions & 2 deletions tests/service/InteractiveCheckerTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ let input =
let ``Test ranges - namespace`` () =
let res = parseAndExtractRanges input
printfn "Test ranges - namespace, res = %A" res
res |> shouldEqual [("N", ((4, 4), (5, 4))); ("Sample", ((4, 9), (4, 15)))]
res |> shouldEqual [("N", ((4, 4), (6, 0))); ("Sample", ((4, 9), (4, 15)))]

let input2 =
"""
Expand All @@ -97,4 +97,4 @@ let input3 =
let ``Test ranges - global namespace`` () =
let res = parseAndExtractRanges input3
printfn "Test ranges - global namespace, res = %A" res
res |> shouldEqual [("", ((4, 4), (5, 4))); ("Sample", ((4, 9), (4, 15)))]
res |> shouldEqual [("", ((4, 4), (6, 0))); ("Sample", ((4, 9), (4, 15)))]

0 comments on commit 8789950

Please sign in to comment.