Skip to content

Implements extended if grammar #55

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

mrange
Copy link
Contributor

@mrange mrange commented Jan 18, 2015

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.

@mrange
Copy link
Contributor Author

mrange commented Jan 18, 2015

Migrated from CodePlex (mainly because I wanted a clean-slate as the history of this PR is quite long)

@mrange
Copy link
Contributor Author

mrange commented Jan 18, 2015

After pouring through the F# parser on how to do error handling I have incorporated similar techniques now. The result should be a more stable preprocessor parser and with support for better error messages to the user.

I ran the test suites (including VS integration)

I saw no errors that were due to extended if grammar.

There are two "small" issues remaining:

Inside visual studio the squiggle for unrecognized characters are rendered in the wrong place:
#if COMPILED # COMPILED // Squiggle rendered here -->_
#endif

The error message from the compiler looks correct though but I think its due to that I consume all characters. If I go back to a previous pattern and simpler pattern it's probably fixed.

The unit test for:
#if (COMPILED ||)
#endif

This generates a parse error (and indication the preprocessor parser needs to be extended to handle this case). I have code that are supposed to handle it but it doesn't pick it up properly yet.

Conclusion:

  1. I added Positive test cases on the fsc level which test various scenarios
  2. I added a new unit test container for internal compiler tests that test positive and negative scenarios
  3. The visual studio unit tests are extended with some new test cases
  4. I have tested the behavior om the VS addin in VS2013 and I think it behaves reasonable (with the exception of unrecognized chars)
  5. I have tested from the command line and think it behaves reasonable (expect for the parse error for certain incomplete expressions.

Therefore to my current knowledge I think this could be good to merge and schedule some minor bug fixes for later.

| comment { PPParser.EOF }
| mcomment { fail args lexbuf (FSComp.SR.pplexExpectedSingleLineComment()) }
| _ {
let lex = lexeme lexbuf
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect consuming "rest" is what causes the squiggle to be rendered in the wrong place on this error. Should be ok with just consuming '_'

@mexx
Copy link
Contributor

mexx commented Jan 18, 2015

Please consider to revert the changes in lexhelp.fs and lexhelp.fsi as they're only formatting and don't add any real value.

@@ -0,0 +1,178 @@
# 3 "..\pplex.fsl"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be included in the commit

@dsyme
Copy link
Contributor

dsyme commented Jan 20, 2015

I think the code looks good - the addition of FSharp.Compiler.UnitTests as well as the actual implementation of the feature.

I'm not sure if this has made the Jan 16 deadline for F# 4.0 though?

@latkin
Copy link
Contributor

latkin commented Jan 20, 2015

This has been in-progress and earmarked for F# 4.0 for a long time. Given Marten's responsiveness to my requests and feedback over the past weeks/months (see original Codeplex thread) I think it's only fair to merge this for 4.0.

@dsyme
Copy link
Contributor

dsyme commented Jan 20, 2015

Great, let's do it :)

@mrange
Copy link
Contributor Author

mrange commented Jan 20, 2015

FYI: Updated PR

  1. Removed generated pp* files (@dsyme feedback)
  2. Reverted lexhelp.* files (@mexx feedback)
  3. Fixed ExtendedIfGrammar.fs busted reporting of failures

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.
@mrange mrange force-pushed the pr/extended_if_grammar branch from 417d3d1 to 42e0766 Compare January 20, 2015 18:11
@latkin latkin closed this in 438eae2 Jan 20, 2015
@latkin
Copy link
Contributor

latkin commented Jan 20, 2015

Applied! Fantastic, Marten. Thanks for your work on this over the past 3 months. 👏

if

@dsyme
Copy link
Contributor

dsyme commented Jan 21, 2015

Fantastic!!!

@dsyme
Copy link
Contributor

dsyme commented Jan 21, 2015

Hi @mrange,

We need to add a "Speclet" to this feature to this collection. The format should follow the others: Links, Aim, Background, Design, Specification and so on. The "specification" section should give a guide for how the F# Language Specification will be updated for this feature.

Could you submit a PR to that repo with an initial design/spec document please, and we'll iterate with you. If you need help doing the doc please let me know.

Thanks
Don

forki referenced this pull request in forki/visualfsharp Jan 21, 2015
closes #55

commit 677a7e799fd5350fd166411004a734f56e9c4e4b
Author: latkin <latkin@microsoft.com>
Date:   Tue Jan 20 11:34:49 2015 -0800

    Update DEVGUIDE and TESTGUIDE to include compiler unit test suite

commit 90f33737381c0932a478746fc566532da862f3c3
Author: latkin <latkin@microsoft.com>
Date:   Tue Jan 20 11:20:56 2015 -0800

    Simplifying ExtendedIfGrammar tests

commit 78b8ff4e325dc37a6d4ca0777b05a2abe85f961c
Author: latkin <latkin@microsoft.com>
Date:   Tue Jan 20 11:20:10 2015 -0800

    Adding compilerunit to RunTests.cmd usage

commit ba861296fe847faa217ab76ec1cb76aef7bc4d02
Merge: 28da5c0 42e0766
Author: latkin <latkin@microsoft.com>
Date:   Tue Jan 20 11:05:01 2015 -0800

    Merge branch 'pr/extended_if_grammar' of https://github.com/mrange/visualfsharp into mrange-pr/extended_if_grammar

    Conflicts:
    	tests/fsharpqa/Source/Conformance/LexicalAnalysis/ConditionalCompilation/ExtendedIfGrammar.fs

commit 28da5c0800a28cc2044a8d3bb4a22751803433aa
Author: latkin <latkin@microsoft.com>
Date:   Mon Jan 19 18:38:11 2015 -0800

    Removing generated .fs/.fsi files from repo

commit 47b61d5460f4c84c1b985d50ce96d944c8791efa
Author: latkin <latkin@microsoft.com>
Date:   Mon Jan 19 18:36:15 2015 -0800

    Use dedicated fsharp-compiler-unittests-build.proj so portable/net20 build of library unit tests is not broken

commit 95e1af8c8bac8b4bc6312a171e675392bff67626
Merge: c5e6699 5f8880c
Author: latkin <latkin@microsoft.com>
Date:   Mon Jan 19 18:14:12 2015 -0800

    Merge branch 'pr/extended_if_grammar' of https://github.com/mrange/visualfsharp into mrange-pr/extended_if_grammar

commit 5f8880c
Author: mrange <marten_range@hotmail.com>
Date:   Sun Jan 18 14:50:47 2015 +0100

    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.
@mrange
Copy link
Contributor Author

mrange commented Jan 21, 2015

@dsyme - I threw together a speclet: fsharp/fslang-design#40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants