Skip to content

Commit 5f8880c

Browse files
committed
Implements extended if grammar
Origin: https://fslang.uservoice.com/forums/245727-f-language/suggestions/6079342-allow-extended-if-grammar This commit adds the possibility to write condtional compilation expressions like this: #if SILVERLIGHT || NETFX #endif or a bit more advanced: #if (SILVERLIGHT || NETFX) && COMPILED || !DEBUG #endif This commit doesn't add #elif which is an orthogonal problem.
1 parent 0b20916 commit 5f8880c

27 files changed

+1427
-52
lines changed

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@ src/fsharp/FSharp.Compiler/ilpars.fsi
4545
src/fsharp/FSharp.Compiler/lex.fs
4646
src/fsharp/FSharp.Compiler/pars.fs
4747
src/fsharp/FSharp.Compiler/pars.fsi
48+
src/fsharp/FSharp.Compiler/pplex.fs
49+
src/fsharp/FSharp.Compiler/pppars.fs
50+
src/fsharp/FSharp.Compiler/pppars.fsi
4851
src/fsharp/FSharp.Compiler-proto/illex.fs
4952
src/fsharp/FSharp.Compiler-proto/ilpars.fs
5053
src/fsharp/FSharp.Compiler-proto/ilpars.fsi
5154
src/fsharp/FSharp.Compiler-proto/lex.fs
5255
src/fsharp/FSharp.Compiler-proto/pars.fs
5356
src/fsharp/FSharp.Compiler-proto/pars.fsi
57+
src/fsharp/FSharp.Compiler-proto/pplex.fs
58+
src/fsharp/FSharp.Compiler-proto/pppars.fs
59+
src/fsharp/FSharp.Compiler-proto/pppars.fsi
5460
*~
5561
tests/projects/Sample_VS2012_FSharp_ConsoleApp_net45_with_resource/Sample_VS2012_FSharp_ConsoleApp_net45/Sample_VS2012_FSharp_ConsoleApp_net45.sln
5662
tests/projects/Sample_VS2012_FSharp_ConsoleApp_net45_with_resource/Sample_VS2012_FSharp_ConsoleApp_net45/Sample_VS2012_FSharp_ConsoleApp_net45.userprefs

src/assemblyinfo/assemblyinfo.FSharp.Compiler.dll.fs

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ open System.Reflection
2222

2323
// Note: internals visible to unit test DLLs in Retail (and all) builds.
2424
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Test")>]
25+
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("FSharp.Compiler.Unittests")>]
2526
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Salsa")>]
2627
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Unittests")>]
2728
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("SystematicUnitTests")>]
@@ -45,6 +46,7 @@ open System.Reflection
4546
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Unittests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
4647
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("SystematicUnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
4748
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
49+
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("FSharp.Compiler.Unittests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007D1FA57C4AED9F0A32E84AA0FAEFD0DE9E8FD6AEC8F87FB03766C834C99921EB23BE79AD9D5DCC1DD9AD236132102900B723CF980957FC4E177108FC607774F29E8320E92EA05ECE4E821C0A5EFE8F1645C4C0C93C1AB99285D622CAA652C1DFAD63D745D6F2DE5F17E5EAF0FC4963D261C8A12436518206DC093344D5AD293")>]
4850
#endif
4951

5052
#if STRONG_NAME_FSHARP_COMPILER_WITH_TEST_KEY
@@ -62,6 +64,7 @@ open System.Reflection
6264
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Unittests, PublicKey=002400000480000094000000060200000024000052534131000400000100010077d32e043d184cf8cebf177201ec6fad091581a3a639a0534f1c4ebb3ab847a6b6636990224a04cf4bd1aec51ecec44cf0c8922eb5bb2ee65ec3fb9baa87e141042c96ce414f98af33508c7e24dab5b068aa802f6693881537ee0efcb5d3f1c9aaf8215ac42e92ba9a5a02574d6890d07464cb2f338b043b1c4ffe98efe069ee")>]
6365
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("SystematicUnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010077d32e043d184cf8cebf177201ec6fad091581a3a639a0534f1c4ebb3ab847a6b6636990224a04cf4bd1aec51ecec44cf0c8922eb5bb2ee65ec3fb9baa87e141042c96ce414f98af33508c7e24dab5b068aa802f6693881537ee0efcb5d3f1c9aaf8215ac42e92ba9a5a02574d6890d07464cb2f338b043b1c4ffe98efe069ee")>]
6466
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010077d32e043d184cf8cebf177201ec6fad091581a3a639a0534f1c4ebb3ab847a6b6636990224a04cf4bd1aec51ecec44cf0c8922eb5bb2ee65ec3fb9baa87e141042c96ce414f98af33508c7e24dab5b068aa802f6693881537ee0efcb5d3f1c9aaf8215ac42e92ba9a5a02574d6890d07464cb2f338b043b1c4ffe98efe069ee")>]
67+
[<assembly:System.Runtime.CompilerServices.InternalsVisibleTo("FSharp.Compiler.Unittests, PublicKey=002400000480000094000000060200000024000052534131000400000100010077d32e043d184cf8cebf177201ec6fad091581a3a639a0534f1c4ebb3ab847a6b6636990224a04cf4bd1aec51ecec44cf0c8922eb5bb2ee65ec3fb9baa87e141042c96ce414f98af33508c7e24dab5b068aa802f6693881537ee0efcb5d3f1c9aaf8215ac42e92ba9a5a02574d6890d07464cb2f338b043b1c4ffe98efe069ee")>]
6568
#endif
6669

6770

src/fsharp-library-unittests-build.proj

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<!-- Core library tests: all except compact framework (no nunit there) -->
1010
<ItemGroup Condition=" '$(TargetFramework)' != 'sl3-wp' and '$(TargetFramework)' != 'sl5'">
1111
<ProjectFiles Include="fsharp/FSharp.Core.Unittests/FSharp.Core.Unittests.fsproj"/>
12+
<ProjectFiles Include="fsharp/FSharp.Compiler.Unittests/FSharp.Compiler.Unittests.fsproj"/>
1213
</ItemGroup>
1314

1415
<Import Project="root.traversal.targets"/>

src/fsharp.sln

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Data.TypeProviders",
3131
EndProject
3232
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FsiAnyCPU", "fsharp\fsiAnyCpu\FsiAnyCPU.fsproj", "{8B3E283D-B5FE-4055-9D80-7E3A32F3967B}"
3333
EndProject
34+
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Unittests", "fsharp\FSharp.Compiler.Unittests\FSharp.Compiler.Unittests.fsproj", "{A8D9641A-9170-4CF4-8FE0-6DB8C134E1B5}"
35+
EndProject
3436
Global
3537
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3638
Debug|Any CPU = Debug|Any CPU
@@ -75,6 +77,10 @@ Global
7577
{CB7D20C4-6506-406D-9144-5342C3595F03}.Release|Any CPU.Build.0 = Release|Any CPU
7678
{8B3E283D-B5FE-4055-9D80-7E3A32F3967B}.Debug|Any CPU.ActiveCfg = Debug|x86
7779
{8B3E283D-B5FE-4055-9D80-7E3A32F3967B}.Release|Any CPU.ActiveCfg = Release|x86
80+
{A8D9641A-9170-4CF4-8FE0-6DB8C134E1B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
81+
{A8D9641A-9170-4CF4-8FE0-6DB8C134E1B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
82+
{A8D9641A-9170-4CF4-8FE0-6DB8C134E1B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
83+
{A8D9641A-9170-4CF4-8FE0-6DB8C134E1B5}.Release|Any CPU.Build.0 = Release|Any CPU
7884
EndGlobalSection
7985
GlobalSection(SolutionProperties) = preSolution
8086
HideSolutionNode = FALSE

src/fsharp/FSComp.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ lexHashEndingNoMatchingIf,"#endif has no matching #if"
10641064
1169,lexHashIfMustHaveIdent,"#if directive should be immediately followed by an identifier"
10651065
1170,lexWrongNestedHashEndif,"Syntax error. Wrong nested #endif, unexpected tokens before it."
10661066
lexHashBangMustBeFirstInFile,"#! may only appear as the first line at the start of a file."
1067-
1171,lexExpectedSingleLineComment,"Expected single line comment or end of line"
1067+
1171,pplexExpectedSingleLineComment,"Expected single line comment or end of line"
10681068
1172,memberOperatorDefinitionWithNoArguments,"Infix operator member '%s' has no arguments. Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ..."
10691069
1173,memberOperatorDefinitionWithNonPairArgument,"Infix operator member '%s' has %d initial argument(s). Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ..."
10701070
1174,memberOperatorDefinitionWithCurriedArguments,"Infix operator member '%s' has extra curried arguments. Expected a tuple of 2 arguments, e.g. static member (+) (x,y) = ..."
@@ -1336,3 +1336,7 @@ descriptionUnavailable,"(description unavailable...)"
13361336
3180,abImplicitHeapAllocation,"The mutable local '%s' is implicitly allocated as a reference cell because it has been captured by a closure. This warning is for informational purposes only to indicate where implicit allocations are performed."
13371337
estApplyStaticArgumentsForMethodNotImplemented,"A type provider implemented GetStaticParametersForMethod, but ApplyStaticArgumentsForMethod was not implemented or invalid"
13381338
3181,etErrorApplyingStaticArgumentsToMethod,"An error occured applying the static arguments to a provided method"
1339+
3182,pplexUnexpectedChar,"Unexpected character '%s' in preprocessor expression"
1340+
3183,ppparsUnexpectedToken,"Unexpected token '%s' in preprocessor expression"
1341+
3184,ppparsIncompleteExpression,"Incomplete preprocessor expression"
1342+
3185,ppparsMissingToken,"Missing token '%s' in preprocessor expression"

src/fsharp/FSharp.Compiler-proto/FSharp.Compiler-proto.fsproj

+12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
<Link>FSComp.txt</Link>
2323
</FsSrGen>
2424
<EmbeddedResource Include="..\FSStrings.resx" />
25+
<FsLex Include="..\pplex.fsl">
26+
<OtherFlags>--lexlib Internal.Utilities.Text.Lexing</OtherFlags>
27+
<Link>pplex.fsl</Link>
28+
</FsLex>
29+
<FsYacc Include="..\pppars.fsy">
30+
<Module>Microsoft.FSharp.Compiler.PPParser</Module>
31+
<Open>Microsoft.FSharp.Compiler</Open>
32+
<OtherFlags>--internal --lexlib Internal.Utilities.Text.Lexing --parslib Internal.Utilities.Text.Parsing</OtherFlags>
33+
<Link>pppars.fsy</Link>
34+
</FsYacc>
2535
<FsLex Include="..\lex.fsl">
2636
<OtherFlags>--lexlib Internal.Utilities.Text.Lexing</OtherFlags>
2737
<Link>lex.fsl</Link>
@@ -250,13 +260,15 @@
250260
<Compile Include="..\ast.fs">
251261
<Link>ast.fs</Link>
252262
</Compile>
263+
<Compile Include="pppars.fs" />
253264
<Compile Include="pars.fs" />
254265
<Compile Include="..\lexhelp.fsi">
255266
<Link>lexhelp.fsi</Link>
256267
</Compile>
257268
<Compile Include="..\lexhelp.fs">
258269
<Link>lexhelp.fs</Link>
259270
</Compile>
271+
<Compile Include="pplex.fs" />
260272
<Compile Include="lex.fs" />
261273
<Compile Include="..\sreflect.fsi">
262274
<Link>sreflect.fsi</Link>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->
3+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
4+
<PropertyGroup>
5+
<FSharpSourcesRoot>..\..</FSharpSourcesRoot>
6+
<ProjectGuid>{a8d9641a-9170-4cf4-8fe0-6db8c134e1b5}</ProjectGuid>
7+
</PropertyGroup>
8+
<Import Project="$(FSharpSourcesRoot)\FSharpSource.Settings.targets" />
9+
<PropertyGroup>
10+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
11+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
12+
<SchemaVersion>2.0</SchemaVersion>
13+
<AllowCrossTargeting>true</AllowCrossTargeting>
14+
<ReferenceVsAssemblies>true</ReferenceVsAssemblies>
15+
<OutputType>Library</OutputType>
16+
<AssemblyName>FSharp.Compiler.Unittests</AssemblyName>
17+
<TargetFrameworkVersion Condition=" '$(TargetFramework)' == 'net20' ">v3.5</TargetFrameworkVersion>
18+
<Name>SystematicUnitTests</Name>
19+
<!-- Prevent compiler from inlining calls to FSharp.Core to improve code coverage accuracy -->
20+
<Optimize>false</Optimize>
21+
<Tailcalls>false</Tailcalls>
22+
<TargetProfile Condition=" '$(TargetFramework)' == 'portable7' or '$(TargetFramework)' == 'portable78' or '$(TargetFramework)' == 'portable259' ">netcore</TargetProfile>
23+
<!-- workaround for msbuild narrowing the assembly search paths when building portable libs -->
24+
<AssemblySearchPaths Condition="$(TargetFramework.Contains('portable'))">
25+
{CandidateAssemblyFiles};
26+
{TargetFrameworkDirectory};
27+
{Registry:Software\Microsoft\.NETFramework,v4.5,AssemblyFoldersEx};
28+
</AssemblySearchPaths>
29+
</PropertyGroup>
30+
<PropertyGroup>
31+
<DefineConstants Condition=" '$(TargetFramework)' == 'sl5' ">$(DefineConstants);SILVERLIGHT</DefineConstants>
32+
<DefineConstants>$(DefineConstants);EXTENSIONTYPING</DefineConstants>
33+
</PropertyGroup>
34+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
35+
<DebugSymbols>true</DebugSymbols>
36+
<DebugType>full</DebugType>
37+
<Optimize>false</Optimize>
38+
<OutputPath>bin\Debug\</OutputPath>
39+
<DefineConstants>DEBUG;TRACE</DefineConstants>
40+
<ErrorReport>prompt</ErrorReport>
41+
<WarningLevel>3</WarningLevel>
42+
</PropertyGroup>
43+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
44+
<DebugType>pdbonly</DebugType>
45+
<Optimize>true</Optimize>
46+
<OutputPath>bin\Release\</OutputPath>
47+
<DefineConstants>TRACE</DefineConstants>
48+
<ErrorReport>prompt</ErrorReport>
49+
<WarningLevel>3</WarningLevel>
50+
</PropertyGroup>
51+
<ItemGroup>
52+
<!-- need full name and SpecificVersion = true in order to convince msbuild to allow this reference when targeting portable47 -->
53+
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77" Condition="'$(TargetFramework)' != 'sl5' AND '$(TargetFramework)' != 'sl3-wp'">
54+
<SpecificVersion>true</SpecificVersion>
55+
</Reference>
56+
<Reference Include="NUnitFramework" Condition="'$(TargetFramework)' == 'sl5' OR '$(TargetFramework)' == 'sl3-wp'" />
57+
</ItemGroup>
58+
<ItemGroup Condition="!$(TargetFramework.Contains('portable'))">
59+
<Reference Include="mscorlib" />
60+
<Reference Include="System" />
61+
<Reference Include="System.Numerics" Condition="'$(TargetFramework)' == 'net40'" />
62+
<Reference Include="System.Core" />
63+
<Reference Include="System.Net" Condition="'$(TargetFramework)' == 'sl5' " />
64+
<Reference Include="System.Observable" Condition="'$(TargetFramework)' == 'sl3-wp' " />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<Compile Include="NUnitFrameworkShims.fs" Condition="'$(TargetFramework)' == 'sl3-wp'" />
68+
<Compile Include="HashIfExpression.fs" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<ProjectReference Include="$(FSharpSourcesRoot)\fsharp\FSharp.Compiler\FSharp.Compiler.fsproj">
72+
<Name>FSharp.Compiler</Name>
73+
<Project>{2e4d67b4-522d-4cf7-97e4-ba940f0b18f3}</Project>
74+
</ProjectReference>
75+
<ProjectReference Include="..\FSharp.Core\FSharp.Core.fsproj">
76+
<Name>FSharp.Core</Name>
77+
<Project>{ded3bbd7-53f4-428a-8c9f-27968e768605}</Project>
78+
<Private>True</Private>
79+
</ProjectReference>
80+
</ItemGroup>
81+
<Import Project="$(FSharpSourcesRoot)\FSharpSource.targets" />
82+
</Project>

0 commit comments

Comments
 (0)