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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,8 @@ type TcConfigBuilder =
/// If true - every expression in quotations will be augmented with full debug info (fileName, location in file)
mutable emitDebugInfoInQuotations: bool

mutable strictIndentation: bool option

mutable exename: string option

// If true - the compiler will copy FSharp.Core.dll along the produced binaries
Expand Down Expand Up @@ -815,6 +817,7 @@ type TcConfigBuilder =
DumpGraph = false
}
dumpSignatureData = false
strictIndentation = None
}

member tcConfigB.FxResolver =
Expand Down Expand Up @@ -1215,6 +1218,7 @@ type TcConfig private (data: TcConfigBuilder, validate: bool) =
member _.bufferWidth = data.bufferWidth
member _.fsiMultiAssemblyEmit = data.fsiMultiAssemblyEmit
member _.FxResolver = data.FxResolver
member _.strictIndentation = data.strictIndentation
member _.primaryAssembly = data.primaryAssembly
member _.noFeedback = data.noFeedback
member _.stackReserveSize = data.stackReserveSize
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/Driver/CompilerConfig.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,8 @@ type TcConfigBuilder =

mutable emitDebugInfoInQuotations: bool

mutable strictIndentation: bool option

mutable exename: string option

mutable copyFSharpCore: CopyFSharpCoreFlag
Expand Down Expand Up @@ -808,6 +810,8 @@ type TcConfig =

member FxResolver: FxResolver

member strictIndentation: bool option

member ComputeIndentationAwareSyntaxInitialStatus: string -> bool

member GetTargetFrameworkDirectories: unit -> string list
Expand Down
11 changes: 10 additions & 1 deletion src/Compiler/Driver/CompilerOptions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1142,8 +1142,18 @@ let languageFlags tcConfigB =
None,
Some(FSComp.SR.optsChecked ())
)

CompilerOption("define", tagString, OptionString(defineSymbol tcConfigB), None, Some(FSComp.SR.optsDefine ()))

mlCompatibilityFlag tcConfigB

CompilerOption(
"strict-indentation",
tagNone,
OptionSwitch(fun switch -> tcConfigB.strictIndentation <- Some(switch = OptionSwitch.On)),
None,
Some(FSComp.SR.optsStrictIndentation ())
)
]

// OptionBlock: Advanced user options
Expand Down Expand Up @@ -1332,7 +1342,6 @@ let advancedFlagsFsc tcConfigB =
None,
Some(FSComp.SR.optsEmitDebugInfoInQuotations ())
)

]

// OptionBlock: Internal options (test use only)
Expand Down
6 changes: 3 additions & 3 deletions src/Compiler/Driver/ParseAndCheckInputs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ let parseInputStreamAux

// Set up the LexBuffer for the file
let lexbuf =
UnicodeLexing.StreamReaderAsLexbuf(not tcConfig.compilingFSharpCore, tcConfig.langVersion, reader)
UnicodeLexing.StreamReaderAsLexbuf(not tcConfig.compilingFSharpCore, tcConfig.langVersion, tcConfig.strictIndentation, reader)

// Parse the file drawing tokens from the lexbuf
ParseOneInputLexbuf(tcConfig, lexResourceManager, lexbuf, fileName, isLastCompiland, diagnosticsLogger)
Expand All @@ -726,7 +726,7 @@ let parseInputSourceTextAux
) =
// Set up the LexBuffer for the file
let lexbuf =
UnicodeLexing.SourceTextAsLexbuf(not tcConfig.compilingFSharpCore, tcConfig.langVersion, sourceText)
UnicodeLexing.SourceTextAsLexbuf(not tcConfig.compilingFSharpCore, tcConfig.langVersion, tcConfig.strictIndentation, sourceText)

// Parse the file drawing tokens from the lexbuf
ParseOneInputLexbuf(tcConfig, lexResourceManager, lexbuf, fileName, isLastCompiland, diagnosticsLogger)
Expand All @@ -738,7 +738,7 @@ let parseInputFileAux (tcConfig: TcConfig, lexResourceManager, fileName, isLastC

// Set up the LexBuffer for the file
let lexbuf =
UnicodeLexing.StreamReaderAsLexbuf(not tcConfig.compilingFSharpCore, tcConfig.langVersion, reader)
UnicodeLexing.StreamReaderAsLexbuf(not tcConfig.compilingFSharpCore, tcConfig.langVersion, tcConfig.strictIndentation, reader)

// Parse the file drawing tokens from the lexbuf
ParseOneInputLexbuf(tcConfig, lexResourceManager, lexbuf, fileName, isLastCompiland, diagnosticsLogger)
Expand Down
2 changes: 1 addition & 1 deletion src/Compiler/Driver/ScriptClosure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ module ScriptPreprocessClosure =
let tcConfig = TcConfig.Create(tcConfigB, false)

let lexbuf =
UnicodeLexing.SourceTextAsLexbuf(true, tcConfig.langVersion, sourceText)
UnicodeLexing.SourceTextAsLexbuf(true, tcConfig.langVersion, tcConfig.strictIndentation, sourceText)

// The root compiland is last in the list of compilands.
let isLastCompiland = (IsScript fileName, tcConfig.target.IsExe)
Expand Down
1 change: 1 addition & 0 deletions src/Compiler/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,7 @@ useSdkRefs,"Use reference assemblies for .NET framework references when availabl
optsGetLangVersions,"Display the allowed values for language version."
optsSetLangVersion,"Specify language version such as 'latest' or 'preview'."
optsSupportedLangVersions,"Supported language versions:"
optsStrictIndentation,"Override indentation rules implied by the language version"
nativeResourceFormatError,"Stream does not begin with a null resource and is not in '.RES' format."
nativeResourceHeaderMalformed,"Resource header beginning at offset %s is malformed."
formatDashItem," - %s"
Expand Down
35 changes: 25 additions & 10 deletions src/Compiler/Facilities/prim-lexing.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ type internal Position =

type internal LexBufferFiller<'Char> = LexBuffer<'Char> -> unit

and [<Sealed>] internal LexBuffer<'Char>(filler: LexBufferFiller<'Char>, reportLibraryOnlyFeatures: bool, langVersion: LanguageVersion) =
and [<Sealed>] internal LexBuffer<'Char>
(
filler: LexBufferFiller<'Char>,
reportLibraryOnlyFeatures: bool,
langVersion: LanguageVersion,
strictIndentation: bool option
) =
let context = Dictionary<string, obj>(1)
let mutable buffer = [||]
/// number of valid characters beyond bufferScanStart.
Expand Down Expand Up @@ -263,10 +269,18 @@ and [<Sealed>] internal LexBuffer<'Char>(filler: LexBufferFiller<'Char>, reportL

member _.SupportsFeature featureId = langVersion.SupportsFeature featureId

member _.StrictIndentation = strictIndentation

member _.CheckLanguageFeatureAndRecover featureId range =
FSharp.Compiler.DiagnosticsLogger.checkLanguageFeatureAndRecover langVersion featureId range

static member FromFunction(reportLibraryOnlyFeatures, langVersion, f: 'Char[] * int * int -> int) : LexBuffer<'Char> =
static member FromFunction
(
reportLibraryOnlyFeatures,
langVersion,
strictIndentation,
f: 'Char[] * int * int -> int
) : LexBuffer<'Char> =
let extension = Array.zeroCreate 4096

let filler (lexBuffer: LexBuffer<'Char>) =
Expand All @@ -275,32 +289,33 @@ and [<Sealed>] internal LexBuffer<'Char>(filler: LexBufferFiller<'Char>, reportL
Array.blit extension 0 lexBuffer.Buffer lexBuffer.BufferScanPos n
lexBuffer.BufferMaxScanLength <- lexBuffer.BufferScanLength + n

new LexBuffer<'Char>(filler, reportLibraryOnlyFeatures, langVersion)
new LexBuffer<'Char>(filler, reportLibraryOnlyFeatures, langVersion, strictIndentation)

// Important: This method takes ownership of the array
static member FromArrayNoCopy(reportLibraryOnlyFeatures, langVersion, buffer: 'Char[]) : LexBuffer<'Char> =
static member FromArrayNoCopy(reportLibraryOnlyFeatures, langVersion, strictIndentation, buffer: 'Char[]) : LexBuffer<'Char> =
let lexBuffer =
new LexBuffer<'Char>((fun _ -> ()), reportLibraryOnlyFeatures, langVersion)
new LexBuffer<'Char>((fun _ -> ()), reportLibraryOnlyFeatures, langVersion, strictIndentation)

lexBuffer.Buffer <- buffer
lexBuffer.BufferMaxScanLength <- buffer.Length
lexBuffer

// Important: this method does copy the array
static member FromArray(reportLibraryOnlyFeatures, langVersion, s: 'Char[]) : LexBuffer<'Char> =
static member FromArray(reportLibraryOnlyFeatures, langVersion, strictIndentation, s: 'Char[]) : LexBuffer<'Char> =
let buffer = Array.copy s
LexBuffer<'Char>.FromArrayNoCopy (reportLibraryOnlyFeatures, langVersion, buffer)
LexBuffer<'Char>.FromArrayNoCopy (reportLibraryOnlyFeatures, langVersion, strictIndentation, buffer)

// Important: This method takes ownership of the array
static member FromChars(reportLibraryOnlyFeatures, langVersion, arr: char[]) =
LexBuffer.FromArrayNoCopy(reportLibraryOnlyFeatures, langVersion, arr)
static member FromChars(reportLibraryOnlyFeatures, langVersion, strictIndentation, arr: char[]) =
LexBuffer.FromArrayNoCopy(reportLibraryOnlyFeatures, langVersion, strictIndentation, arr)

static member FromSourceText(reportLibraryOnlyFeatures, langVersion, sourceText: ISourceText) =
static member FromSourceText(reportLibraryOnlyFeatures, langVersion, strictIndentation, sourceText: ISourceText) =
let mutable currentSourceIndex = 0

LexBuffer<char>.FromFunction
(reportLibraryOnlyFeatures,
langVersion,
strictIndentation,
fun (chars, start, length) ->
let lengthToCopy =
if currentSourceIndex + length <= sourceText.Length then
Expand Down
14 changes: 11 additions & 3 deletions src/Compiler/Facilities/prim-lexing.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,29 @@ type internal LexBuffer<'Char> =
/// True if the specified language feature is supported.
member SupportsFeature: LanguageFeature -> bool

member StrictIndentation: bool option

/// Logs a recoverable error if a language feature is unsupported, at the specified range.
member CheckLanguageFeatureAndRecover: LanguageFeature -> range -> unit

/// Create a lex buffer suitable for Unicode lexing that reads characters from the given array.
/// Important: does take ownership of the array.
static member FromChars: reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * char[] -> LexBuffer<char>
static member FromChars:
reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * strictIndentation: bool option * char[] ->
LexBuffer<char>

/// Create a lex buffer that reads character or byte inputs by using the given function.
static member FromFunction:
reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * ('Char[] * int * int -> int) ->
reportLibraryOnlyFeatures: bool *
langVersion: LanguageVersion *
strictIndentation: bool option *
('Char[] * int * int -> int) ->
LexBuffer<'Char>

/// Create a lex buffer backed by source text.
static member FromSourceText:
reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * ISourceText -> LexBuffer<char>
reportLibraryOnlyFeatures: bool * langVersion: LanguageVersion * strictIndentation: bool option * ISourceText ->
LexBuffer<char>

/// The type of tables for an unicode lexer generated by <c>fslex.exe</c>.
[<Sealed>]
Expand Down
17 changes: 13 additions & 4 deletions src/Compiler/Interactive/fsi.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3512,6 +3512,7 @@ type FsiStdinLexerProvider
UnicodeLexing.FunctionAsLexbuf(
true,
tcConfigB.langVersion,
tcConfigB.strictIndentation,
(fun (buf: char[], start, len) ->
//fprintf fsiConsoleOutput.Out "Calling ReadLine\n"
let inputOption =
Expand Down Expand Up @@ -3604,12 +3605,16 @@ type FsiStdinLexerProvider

// Create a new lexer to read an "included" script file
member _.CreateIncludedScriptLexer(sourceFileName, reader, diagnosticsLogger) =
let lexbuf = UnicodeLexing.StreamReaderAsLexbuf(true, tcConfigB.langVersion, reader)
let lexbuf =
UnicodeLexing.StreamReaderAsLexbuf(true, tcConfigB.langVersion, tcConfigB.strictIndentation, reader)

CreateLexerForLexBuffer(sourceFileName, lexbuf, diagnosticsLogger)

// Create a new lexer to read a string
member _.CreateStringLexer(sourceFileName, source, diagnosticsLogger) =
let lexbuf = UnicodeLexing.StringAsLexbuf(true, tcConfigB.langVersion, source)
let lexbuf =
UnicodeLexing.StringAsLexbuf(true, tcConfigB.langVersion, tcConfigB.strictIndentation, source)

CreateLexerForLexBuffer(sourceFileName, lexbuf, diagnosticsLogger)

member _.ConsoleInput = fsiConsoleInput
Expand Down Expand Up @@ -4224,7 +4229,9 @@ type FsiInteractionProcessor
use _ = UseBuildPhase BuildPhase.Interactive
use _ = UseDiagnosticsLogger diagnosticsLogger
use _scope = SetCurrentUICultureForThread fsiOptions.FsiLCID
let lexbuf = UnicodeLexing.StringAsLexbuf(true, tcConfigB.langVersion, sourceText)

let lexbuf =
UnicodeLexing.StringAsLexbuf(true, tcConfigB.langVersion, tcConfigB.strictIndentation, sourceText)

let tokenizer =
fsiStdinLexerProvider.CreateBufferLexer(scriptFileName, lexbuf, diagnosticsLogger)
Expand All @@ -4244,7 +4251,9 @@ type FsiInteractionProcessor
use _unwind1 = UseBuildPhase BuildPhase.Interactive
use _unwind2 = UseDiagnosticsLogger diagnosticsLogger
use _scope = SetCurrentUICultureForThread fsiOptions.FsiLCID
let lexbuf = UnicodeLexing.StringAsLexbuf(true, tcConfigB.langVersion, sourceText)

let lexbuf =
UnicodeLexing.StringAsLexbuf(true, tcConfigB.langVersion, tcConfigB.strictIndentation, sourceText)

let tokenizer =
fsiStdinLexerProvider.CreateBufferLexer(scriptFileName, lexbuf, diagnosticsLogger)
Expand Down
12 changes: 8 additions & 4 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2170,6 +2170,7 @@ type FSharpParsingOptions =
LangVersionText: string
IsInteractive: bool
IndentationAwareSyntax: bool option
StrictIndentation: bool option
CompilingFSharpCore: bool
IsExe: bool
}
Expand All @@ -2187,6 +2188,7 @@ type FSharpParsingOptions =
LangVersionText = LanguageVersion.Default.VersionText
IsInteractive = false
IndentationAwareSyntax = None
StrictIndentation = None
CompilingFSharpCore = false
IsExe = false
}
Expand All @@ -2200,6 +2202,7 @@ type FSharpParsingOptions =
LangVersionText = tcConfig.langVersion.VersionText
IsInteractive = isInteractive
IndentationAwareSyntax = tcConfig.indentationAwareSyntax
StrictIndentation = tcConfig.strictIndentation
CompilingFSharpCore = tcConfig.compilingFSharpCore
IsExe = tcConfig.target.IsExe
}
Expand All @@ -2213,6 +2216,7 @@ type FSharpParsingOptions =
LangVersionText = tcConfigB.langVersion.VersionText
IsInteractive = isInteractive
IndentationAwareSyntax = tcConfigB.indentationAwareSyntax
StrictIndentation = tcConfigB.strictIndentation
CompilingFSharpCore = tcConfigB.compilingFSharpCore
IsExe = tcConfigB.target.IsExe
}
Expand Down Expand Up @@ -2341,8 +2345,8 @@ module internal ParseAndCheckFile =

(fun _ -> tokenizer.GetToken())

let createLexbuf langVersion sourceText =
UnicodeLexing.SourceTextAsLexbuf(true, LanguageVersion(langVersion), sourceText)
let createLexbuf langVersion strictIndentation sourceText =
UnicodeLexing.SourceTextAsLexbuf(true, LanguageVersion(langVersion), strictIndentation, sourceText)

let matchBraces (sourceText: ISourceText, fileName, options: FSharpParsingOptions, userOpName: string, suggestNamesForErrors: bool) =
// Make sure there is an DiagnosticsLogger installed whenever we do stuff that might record errors, even if we ultimately ignore the errors
Expand All @@ -2354,7 +2358,7 @@ module internal ParseAndCheckFile =

let matchingBraces = ResizeArray<_>()

usingLexbufForParsing (createLexbuf options.LangVersionText sourceText, fileName) (fun lexbuf ->
usingLexbufForParsing (createLexbuf options.LangVersionText options.StrictIndentation sourceText, fileName) (fun lexbuf ->
let errHandler =
DiagnosticsHandler(false, fileName, options.DiagnosticOptions, sourceText, suggestNamesForErrors, false)

Expand Down Expand Up @@ -2466,7 +2470,7 @@ module internal ParseAndCheckFile =
use _ = UseBuildPhase BuildPhase.Parse

let parseResult =
usingLexbufForParsing (createLexbuf options.LangVersionText sourceText, fileName) (fun lexbuf ->
usingLexbufForParsing (createLexbuf options.LangVersionText options.StrictIndentation sourceText, fileName) (fun lexbuf ->

let lexfun = createLexerFunction fileName options lexbuf errHandler

Expand Down
2 changes: 2 additions & 0 deletions src/Compiler/Service/FSharpCheckerResults.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ type public FSharpParsingOptions =

IndentationAwareSyntax: bool option

StrictIndentation: bool option

CompilingFSharpCore: bool

IsExe: bool
Expand Down
Loading