forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pars.fsy
6940 lines (5577 loc) · 278 KB
/
pars.fsy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.
%{
#nowarn "1182" // generated code has lots of unused "parseState"
open System
open Internal.Utilities
open Internal.Utilities.Text.Parsing
open Internal.Utilities.Library
open Internal.Utilities.Library.Extras
open FSharp.Compiler
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.DiagnosticsLogger
open FSharp.Compiler.Features
open FSharp.Compiler.ParseHelpers
open FSharp.Compiler.Syntax
open FSharp.Compiler.SyntaxTrivia
open FSharp.Compiler.Syntax.PrettyNaming
open FSharp.Compiler.SyntaxTreeOps
open FSharp.Compiler.Text.Position
open FSharp.Compiler.Text.Range
open FSharp.Compiler.Xml
// This function is called by the generated parser code. Returning initiates error recovery
// It must be called precisely "parse_error_rich"
let parse_error_rich = Some(fun (ctxt: ParseErrorContext<_>) ->
errorR(SyntaxError(box ctxt, ctxt.ParseState.LexBuffer.LexemeRange)))
%}
// Producing these changes the lex state, e.g. string --> token, or nesting level of braces in interpolated strings
%token <byte[] * SynByteStringKind * ParseHelpers.LexerContinuation> BYTEARRAY
%token <string * SynStringKind * ParseHelpers.LexerContinuation> STRING
%token <string * SynStringKind * ParseHelpers.LexerContinuation> INTERP_STRING_BEGIN_END
%token <string * SynStringKind * ParseHelpers.LexerContinuation> INTERP_STRING_BEGIN_PART
%token <string * ParseHelpers.LexerContinuation> INTERP_STRING_PART
%token <string * ParseHelpers.LexerContinuation> INTERP_STRING_END
%token <ParseHelpers.LexerContinuation> LBRACE RBRACE
%token <string * string> KEYWORD_STRING // Like __SOURCE_DIRECTORY__
%token <string> IDENT
%token <string> HASH_IDENT
%token <string> INFIX_STAR_STAR_OP
%token <string> INFIX_COMPARE_OP
%token <string> INFIX_AT_HAT_OP
%token <string> INFIX_BAR_OP
%token <string> PREFIX_OP
%token <string> INFIX_STAR_DIV_MOD_OP
%token <string> INFIX_AMP_OP
%token <string> PLUS_MINUS_OP
%token <string> ADJACENT_PREFIX_OP
%token <string> FUNKY_OPERATOR_NAME
/* bool indicates if INT8 was 'bad' max_int+1, e.g. '128' */
%token <sbyte * bool> INT8
%token <int16 * bool> INT16
%token <int32 * bool> INT32 INT32_DOT_DOT
%token <int64 * bool> INT64
%token <int64 * bool> NATIVEINT
%token <byte> UINT8
%token <uint16> UINT16
%token <uint32> UINT32
%token <uint64> UINT64
%token <uint64> UNATIVEINT
%token <single> IEEE32
%token <double> IEEE64
%token <char> CHAR
%token <System.Decimal> DECIMAL
%token <(string * string)> BIGNUM
%token <bool> LET YIELD YIELD_BANG AND_BANG
%token <bool> LESS GREATER /* here the bool indicates if the tokens are part of a type application or type parameter declaration, e.g. C<int>, detected by the lex filter */
%token <string> PERCENT_OP BINDER
%token <string * bool> LQUOTE RQUOTE RQUOTE_DOT
%token BAR_BAR UPCAST DOWNCAST NULL RESERVED MODULE NAMESPACE DELEGATE CONSTRAINT BASE
%token AND AS ASSERT OASSERT ASR BEGIN DO DONE DOWNTO ELSE ELIF END DOT_DOT DOT_DOT_HAT
%token EXCEPTION FALSE FOR FUN FUNCTION IF IN JOIN_IN FINALLY DO_BANG
%token LAZY OLAZY MATCH MATCH_BANG MUTABLE NEW OF
%token OPEN OR REC THEN TO TRUE TRY TYPE VAL INLINE INTERFACE INSTANCE CONST
%token WHEN WHILE WHILE_BANG WITH HASH AMP AMP_AMP QUOTE LPAREN RPAREN RPAREN_COMING_SOON RPAREN_IS_HERE STAR COMMA RARROW GREATER_BAR_RBRACK LPAREN_STAR_RPAREN
%token QMARK QMARK_QMARK DOT COLON COLON_COLON COLON_GREATER COLON_QMARK_GREATER COLON_QMARK COLON_EQUALS SEMICOLON
%token SEMICOLON_SEMICOLON LARROW EQUALS LBRACK LBRACK_BAR LBRACE_BAR LBRACK_LESS
%token BAR_RBRACK BAR_RBRACE UNDERSCORE
%token BAR RBRACK RBRACE_COMING_SOON RBRACE_IS_HERE MINUS DOLLAR
%token GREATER_RBRACK STRUCT SIG
%token STATIC MEMBER CLASS ABSTRACT OVERRIDE DEFAULT CONSTRUCTOR INHERIT
%token EXTERN VOID PUBLIC PRIVATE INTERNAL GLOBAL
/* for parser 'escape hatch' out of expression context without consuming the 'recover' token */
%token TYPE_COMING_SOON TYPE_IS_HERE MODULE_COMING_SOON MODULE_IS_HERE
/* for high-precedence tyapps and apps */
%token HIGH_PRECEDENCE_BRACK_APP /* inserted for f[x], but not f [x] */
%token HIGH_PRECEDENCE_PAREN_APP /* inserted for f(x) and f<int>(x), but not f (x) */
%token HIGH_PRECEDENCE_TYAPP /* inserted for x<y>, but not x<y */
/* for offside rule */
%token <bool> OLET /* LexFilter #light converts 'LET' tokens to 'OLET' when starting (CtxtLetDecl(blockLet=true)) */
%token <string> OBINDER /* LexFilter #light converts 'BINDER' tokens to 'OBINDER' when starting (CtxtLetDecl(blockLet=true)) */
%token <bool> OAND_BANG /* LexFilter #light converts 'AND_BANG' tokens to 'OAND_BANG' when starting (CtxtLetDecl(blockLet=true)) */
%token ODO /* LexFilter #light converts 'DO' tokens to 'ODO' */
%token ODO_BANG /* LexFilter #light converts 'DO_BANG' tokens to 'ODO_BANG' */
%token OTHEN /* LexFilter #light converts 'THEN' tokens to 'OTHEN' */
%token OELSE /* LexFilter #light converts 'ELSE' tokens to 'OELSE' except if immeditely followed by 'if', when they become 'ELIF' */
%token OWITH /* LexFilter #light converts SOME (but not all) 'WITH' tokens to 'OWITH' */
%token OFUNCTION /* LexFilter #light converts 'FUNCTION' tokens to 'OFUNCTION' */
%token OFUN /* LexFilter #light converts 'FUN' tokens to 'OFUN' */
%token ORESET /* LexFilter uses internally to force a complete reset on a ';;' */
%token OBLOCKBEGIN /* LexFilter #light inserts for:
- just after first '=' or ':' when in 'CtxtModuleHead', i.e. after 'module' and sequence of dot/identifier/access tokens
- just after first '=' when in 'CtxtMemberHead'
- just after first '=' when in 'CtxtType'
- just after 'do' in any context (when opening CtxtDo)
- just after 'finally' in any context
- just after 'with' (when opening CtxtWithAsAugment)
- just after 'else' (when opening CtxtElse)
- just after 'then' (when opening CtxtThen)
- just after 'interface' (when pushing CtxtParen(INTERFACE), i.e. next token is DEFAULT | OVERRIDE | INTERFACE | NEW | TYPE | STATIC | END | MEMBER | ABSTRACT | INHERIT | LBRACK_LESS)
- just after 'class' (when pushing CtxtParen(CLASS)
- just after 'class'
But not when opening these CtxtSeqBlocks:
- just after first non-dot/identifier token past 'namespace'
- just after first '=' when in 'CtxtLetDecl' or 'CtxtWithAsLet'
- just after 'lazy' in any context
- just after '->' in any context
- when opening CtxtNamespaceHead, CtxtModuleHead
*/
%token OBLOCKSEP /* LexFilter #light inserts when transforming CtxtSeqBlock(NotFirstInSeqBlock, _, AddBlockEnd) to CtxtSeqBlock(FirstInSeqBlock, _, AddBlockEnd) on exact alignment */
/* LexFilter #light inserts these tokens when closing offside contexts */
%token OEND // CtxtFun, CtxtMatchClauses, CtxtWithAsLet _
%token <range> ODECLEND // CtxtDo and CtxtLetDecl(block)
%token <range> ORIGHT_BLOCK_END // CtxtSeqBlock(_, _, AddOneSidedBlockEnd)
%token <range> OBLOCKEND // CtxtSeqBlock(_, _, AddBlockEnd)
%token OBLOCKEND_COMING_SOON OBLOCKEND_IS_HERE // CtxtSeqBlock(_, _, AddBlockEnd)
%token OINTERFACE_MEMBER /* inserted for non-paranthetical use of 'INTERFACE', i.e. not INTERFACE/END */
%token FIXED
%token <token> ODUMMY
/* These are artificial */
%token <string> LEX_FAILURE
%token <ParseHelpers.LexerContinuation> COMMENT WHITESPACE HASH_LINE HASH_LIGHT INACTIVECODE LINE_COMMENT STRING_TEXT EOF
%token <range * string * ParseHelpers.LexerContinuation> HASH_IF HASH_ELSE HASH_ENDIF
%start signatureFile implementationFile interaction typedSequentialExprEOF typEOF
%type <SynExpr> typedSequentialExprEOF
%type <ParsedImplFile> implementationFile
%type <ParsedSigFile> signatureFile
%type <ParsedScriptInteraction> interaction
%type <Ident> ident
%type <SynType> typ typEOF
%type <SynTypeDefnSig list> tyconSpfnList
%type <SynArgPats * Range> atomicPatsOrNamePatPairs
%type <SynPat list> atomicPatterns
%type <Range * SynExpr> patternResult
%type <SynExpr> declExpr
%type <SynExpr> minusExpr
%type <SynExpr> appExpr
%type <SynExpr> argExpr
%type <SynExpr> declExprBlock
%type <SynPat> headBindingPattern
%type <SynType> atomTypeNonAtomicDeprecated
%type <SynExpr> atomicExprAfterType
%type <SynExpr> typedSequentialExprBlock
%type <SynExpr * bool> atomicExpr
%type <SynExpr list * range list> tupleExpr
%type <SynTypeDefnSimpleRepr> tyconDefnOrSpfnSimpleRepr
%type <Choice<SynEnumCase, SynUnionCase> list> unionTypeRepr
%type <range * SynMemberDefns> tyconDefnAugmentation
%type <SynExceptionDefn> exconDefn
%type <SynExceptionDefnRepr> exconCore
%type <SynModuleDecl list> moduleDefnsOrExprPossiblyEmptyOrBlock
%type <SynLongIdent> path
%type <SynLongIdent> pathOp
/* LESS GREATER parsedOk typeArgs m for each mWhole */
%type <range * range option * bool * SynType list * range list * range> typeArgsActual
/* LESS GREATER typeArgs m for each mWhole */
%type <range * range option * SynType list * range list * range> typeArgsNoHpaDeprecated
%type <SynTypar> typar
/* About precedence rules:
*
* Tokens and dummy-terminals are given precedence below (lowest first).
* A rule has precedence of the first token or the dummy terminal given after %prec.
* The precedence resolve shift/reduce conflicts:
* (a) If either rule has no precedence:
* S/R: shift over reduce, and
* R/R: reduce earlier rule over later rule.
* (b) If both rules have precedence:
* S/R: choose highest precedence action (precedence of reduce rule vs shift token)
* if same precedence: leftassoc gives reduce, rightassoc gives shift, nonassoc error.
* R/R: reduce the rule that comes first (textually first in the yacc file)
*
* Advice from: http://dinosaur.compilertools.net/yacc/
*
* 'Conflicts resolved by precedence are not counted in the number of S/R and R/R
* conflicts reported by Yacc. This means that mistakes in the moduleSpfn of
* precedences may disguise errors in the input grammar; it is a good idea to be
* sparing with precedences, and use them in an essentially ``cookbook'' fashion,
* until some experience has been gained'
*
* Observation:
* It is possible to eliminate conflicts by giving precedence to rules and tokens.
* Dummy tokens can be used for the rule and the tokens also need precedence.
* The danger is that giving precedence to the tokens may twist the grammar elsewhere.
* Maybe it would be good to assign precedence at given locations, e.g.
*
* order: precShort precLong
*
* rule: TokA TokB %@precShort {action1} -- assign prec to rule.
* | TokA TokB TokC@precLong TokD {action2} -- assign prec to TokC at this point.
*
* Observation: reduce/reduce
* If there is a common prefix with a reduce/reduce conflict,
* e.g "OPEN path" for topopens and moduleDefns then can factor
* opendef = "OPEN path" which can be on both paths.
*
* Debugging and checking precedence rules.
* - comment out a rule's %prec and see what conflicts are introduced.
*
* Dummy terminals (like prec_type_prefix) can assign precedence to a rule.
* Doc says rule and (shift) token precedence resolves shift/reduce conflict.
* It seems like dummy terminals can not assign precedence to the shift,
* but including the tokens in the precedences below will order them.
* e.g. prec_type_prefix lower precedence than RARROW, LBRACK, IDENT, STAR (all extend types).
*/
/* start with lowest */
%nonassoc prec_args_error /* less than RPAREN */
%nonassoc prec_atomexpr_lparen_error /* less than RPAREN */
%right AS
/* prec_wheretyp_prefix = "where typ" lower than extensions, i.e. "WHEN" */
%nonassoc prec_wheretyp_prefix /* lower than WHEN and RPAREN */
%nonassoc RPAREN RPAREN_COMING_SOON RPAREN_IS_HERE
%right WHEN
/* prec_pat_pat_action = "pattern when expr -> expr"
* Lower than match extensions - i.e. BAR.
*/
%nonassoc prec_pat_pat_action /* lower than BAR */
/* "a then b" as an object constructor is very low precedence */
/* Lower than "if a then b" */
%left prec_then_before
%nonassoc prec_then_if
%left BAR
%right SEMICOLON prec_semiexpr_sep OBLOCKSEP
%right prec_defn_sep
/* prec_atompat_pathop = precedence of at atomic pattern, e.g "Constructor".
* Lower than possible pattern extensions, so "pathOp . extension" does shift not reduce.
* possible extensions are:
* - constant terminals.
* - null
* - LBRACK = [
* - TRUE, FALSE
*/
%nonassoc prec_atompat_pathop
%nonassoc INT8 UINT8 INT16 UINT16 INT32 UINT32 INT64 UINT64 NATIVEINT UNATIVEINT IEEE32 IEEE64 CHAR KEYWORD_STRING STRING BYTEARRAY BIGNUM DECIMAL
%nonassoc INTERP_STRING_BEGIN INTERP_STRING_PART INTERP_STRING_END
%nonassoc LPAREN LBRACE LBRACK_BAR
%nonassoc TRUE FALSE UNDERSCORE NULL
/* prec_typ_prefix lower than "T -> T -> T" extensions.
* prec_tuptyp_prefix lower than "T * T * T * T" extensions.
* prec_tuptyptail_prefix lower than "T * T * T * T" extensions.
* Lower than possible extensions:
* - STAR, IDENT, RARROW
* - LBRACK = [ - for "base[]" types
* Shifts not reduces.
*/
%nonassoc prec_typ_prefix /* lower than STAR, IDENT, RARROW etc */
%nonassoc prec_tuptyp_prefix /* ditto */
%nonassoc prec_tuptyptail_prefix /* ditto */
%nonassoc prec_toptuptyptail_prefix /* ditto */
%right RARROW
%nonassoc IDENT LBRACK
/* prec_opt_attributes_none = precedence of no attributes
* These can prefix LET-moduleDefns.
* Committing to an opt_attribute (reduce) forces the decision that a following LET is a moduleDefn.
* At the top-level, it could turn out to be an expr, so prefer to shift and find out...
*/
%nonassoc prec_opt_attributes_none /* lower than LET, NEW */
/* LET, NEW higher than SEMICOLON so shift
* "seqExpr = seqExpr; . let x = y in z"
* "seqExpr = seqExpr; . new...."
*/
%nonassoc LET NEW
/* Redundant dummies: expr_let, expr_function, expr_fun, expr_match */
/* Resolves conflict: expr_try, expr_if */
%nonassoc expr_let
%nonassoc decl_let
%nonassoc expr_function expr_fun expr_match expr_try expr_do
%nonassoc decl_match decl_do
%nonassoc expr_if /* lower than ELSE to disambiguate "if _ then if _ then _ else _" */
%nonassoc ELSE
/* prec_atomtyp_path = precedence of atomType "path"
* Lower than possible extension "path<T1, T2>" to allow "path . <" shift.
* Extensions: LESS
*/
%nonassoc prec_atomtyp_path /* lower than LESS */
%nonassoc prec_atomtyp_get_path /* lower than LESS */
/* prec_no_more_attr_bindings = precedence of "moreLocalBindings = ."
* Lower precedence than AND so further bindings are shifted.
*/
%nonassoc prec_no_more_attr_bindings /* lower than AND */
%nonassoc OPEN
/* prec_interfaces_prefix - lower than extensions, i.e. INTERFACE */
%nonassoc prec_interfaces_prefix /* lower than INTERFACE */
%nonassoc INTERFACE
%right LARROW
%right COLON_EQUALS
%nonassoc pat_tuple expr_tuple
%left COMMA
%nonassoc open_range_expr
%left DOT_DOT /* for matrix.[1..2, 3..4] the ".." has higher precedence than expression "2 COMMA 3" */
%nonassoc interpolation_fill /* "...{3,N4}..." .NET style fill has higher precedence than "e COMMA e" */
%nonassoc paren_pat_colon
%nonassoc paren_pat_attribs
%left OR BAR_BAR JOIN_IN
%left AND
%left AND_BANG
%left AMP AMP_AMP
%nonassoc pat_conj
%nonassoc expr_not
%left COLON_GREATER COLON_QMARK_GREATER
%left INFIX_COMPARE_OP DOLLAR LESS GREATER EQUALS INFIX_BAR_OP INFIX_AMP_OP
%right INFIX_AT_HAT_OP
%right COLON_COLON
%nonassoc pat_isinst
%left COLON_QMARK
%left PLUS_MINUS_OP MINUS expr_prefix_plus_minus ADJACENT_PREFIX_OP
%left INFIX_STAR_DIV_MOD_OP STAR PERCENT_OP
%right INFIX_STAR_STAR_OP
%left QMARK_QMARK
%left head_expr_adjacent_minus
%left expr_app expr_assert expr_lazy LAZY ASSERT
%left arg_expr_adjacent_minus
%left expr_args
%right matching_bar
%left pat_app
%left pat_args
%left PREFIX_OP
%right dot_lambda
%left DOT QMARK
%left HIGH_PRECEDENCE_BRACK_APP
%left HIGH_PRECEDENCE_PAREN_APP
%left HIGH_PRECEDENCE_TYAPP
%nonassoc prec_interaction_empty
%%
/*--------------------------------------------------------------------------*/
/* F# Interactive */
/* A SEMICOLON_SEMICOLON (or EOF) will mark the end of all interaction blocks. */
/* The end of interaction blocks must be determined without needing to lookahead one more token. */
/* A lookahead token would be dropped between parser calls. See bug 1027. */
/* An interaction in F# Interactive */
interaction:
| interactiveItemsTerminator
{ ParsedScriptInteraction.Definitions($1, lhs parseState) }
| SEMICOLON
{ warning(Error(FSComp.SR.parsUnexpectedSemicolon(), rhs parseState 1))
ParsedScriptInteraction.Definitions([], lhs parseState) }
| OBLOCKSEP
{ ParsedScriptInteraction.Definitions([], lhs parseState) }
interactiveTerminator:
| SEMICOLON_SEMICOLON {}
| EOF { checkEndOfFileError $1 }
/* An group of items considered to be one interaction, plus a terminator */
/* Represents the sequence of items swallowed in one interaction by F# Interactive */
/* It is important to make this as large as possible given the chunk of input */
/* text. More or less identical to 'moduleDefns' but where SEMICOLON_SEMICOLON is */
/* not part of the grammar of topSeps and HASH interactions are not part of */
/* the swalloed blob, since things like #use must be processed separately. */
/* REVIEW: limiting the input chunks until the next # directive can lead to */
/* discrepencies between whole-file type checking in FSI and FSC. */
interactiveItemsTerminator:
| interactiveTerminator
{ [] }
| interactiveDefns interactiveTerminator
{ $1 }
| interactiveExpr interactiveTerminator
{ $1 }
| interactiveHash interactiveTerminator
{ $1 }
| interactiveDefns interactiveSeparators interactiveItemsTerminator
{ $1 @ $3 }
| interactiveExpr interactiveSeparators interactiveItemsTerminator
{ $1 @ $3 }
| interactiveHash interactiveSeparators interactiveItemsTerminator
{ $1 @ $3 }
/* A group of definitions as part of in one interaction in F# Interactive */
interactiveDefns:
| moduleDefn
{ $1 }
| moduleDefn interactiveDefns
{ $1 @ $2 }
/* An expression as part of one interaction in F# Interactive */
interactiveExpr:
| opt_attributes opt_access declExpr
{ match $2 with
| Some vis -> errorR(Error(FSComp.SR.parsUnexpectedVisibilityDeclaration(vis.ToString()), rhs parseState 3))
| _ -> ()
let attrDecls = if not (isNil $1) then [ SynModuleDecl.Attributes($1, rangeOfNonNilAttrs $1) ] else []
attrDecls @ [ mkSynExprDecl $3 ] }
/* A #directive interaction in F# Interactive */
interactiveHash:
| hashDirective
{ [SynModuleDecl.HashDirective($1, rhs parseState 1)] }
/* One or more separators between interactions in F# Interactive */
interactiveSeparators:
| interactiveSeparator { }
| interactiveSeparator interactiveSeparators { }
/* One separator between interactions in F# Interactive */
interactiveSeparator:
| SEMICOLON { }
| OBLOCKSEP { }
/*--------------------------------------------------------------------------*/
/* #directives - used by both F# Interactive directives and #nowarn etc. */
/* A #directive in a module, namespace or an interaction */
hashDirective:
| HASH IDENT hashDirectiveArgs
{ let m = match $3 with [] -> rhs2 parseState 1 2 | _ -> rhs2 parseState 1 3
ParsedHashDirective($2, $3, m) }
/* The arguments to a #directive */
hashDirectiveArgs:
| /* EMPTY */
{ [] }
| hashDirectiveArgs hashDirectiveArg
{ $1 @ [$2] }
/* One argument to a #directive */
hashDirectiveArg:
| string
{ let s, kind = $1
ParsedHashDirectiveArgument.String(s, kind, lhs parseState) }
| INT32
{ let n, _ = $1
ParsedHashDirectiveArgument.Int32(n, lhs parseState) }
| IDENT
{ let m = rhs parseState 1
ParsedHashDirectiveArgument.Ident(Ident($1, m), lhs parseState) }
| pathOp
{ let path = $1
ParsedHashDirectiveArgument.LongIdent(path, lhs parseState) }
| sourceIdentifier
{ let c, v = $1
ParsedHashDirectiveArgument.SourceIdentifier(c, v, lhs parseState) }
/*--------------------------------------------------------------------------*/
/* F# Language Proper - signature files */
/* The contents of a signature file */
signatureFile:
| fileNamespaceSpecs EOF
{ checkEndOfFileError $2; $1 }
| fileNamespaceSpecs error EOF
{ $1 }
/* If this rule fires it is kind of catastrophic: error recovery yields no results! */
/* This will result in NO intellisense for the file! Ideally we wouldn't need this rule */
/* Note: the compiler assumes there is at least one "fragment", so an empty one is used (see 4488) */
| error EOF
{ let emptySigFileFrag = ParsedSigFileFragment.AnonModule([], rhs parseState 1)
ParsedSigFile([], [emptySigFileFrag]) }
/* The start of a module declaration */
moduleIntro:
| moduleKeyword opt_attributes opt_access opt_rec path
{ if not (isNil $2) then
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AttributesToRightOfModuleKeyword (rhs parseState 4)
let mModule = rhs parseState 1
mModule, $4, $5.LongIdent, $3, $2 }
| moduleKeyword opt_attributes opt_access opt_rec OBLOCKSEP
{ if not (isNil $2) then
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AttributesToRightOfModuleKeyword (rhs parseState 4)
let mModule = rhs parseState 1
mModule, $4, [], $3, $2 }
| moduleKeyword opt_attributes opt_access opt_rec recover
{ if not (isNil $2) then
parseState.LexBuffer.CheckLanguageFeatureAndRecover LanguageFeature.AttributesToRightOfModuleKeyword (rhs parseState 4)
let mModule = rhs parseState 1
mModule, $4, [], $3, $2 }
/* The start of a namespace declaration */
namespaceIntro:
| NAMESPACE opt_rec path
{ let mNamespace = rhs parseState 1
mNamespace, $2, $3.LongIdent, grabXmlDoc(parseState, [], 1) }
| NAMESPACE opt_rec recover
{ let mNamespace = rhs parseState 1
mNamespace, $2, [], grabXmlDoc(parseState, [], 1) }
/* The contents of a signature file */
fileNamespaceSpecs:
| fileModuleSpec
{ ParsedSigFile([], [ ($1 (None, false, [], PreXmlDoc.Empty)) ]) }
| fileModuleSpec fileNamespaceSpecList
{ // If there are namespaces, the first fileModuleImpl may only contain # directives
let decls =
match ($1 (None, false, [], PreXmlDoc.Empty)) with
| ParsedSigFileFragment.AnonModule(decls, m) -> decls
| ParsedSigFileFragment.NamespaceFragment(decls = decls) -> decls
| ParsedSigFileFragment.NamedModule(SynModuleOrNamespaceSig(range = m)) ->
raiseParseErrorAt m (FSComp.SR.parsOnlyHashDirectivesAllowed())
let decls =
decls |> List.collect (function
| (SynModuleSigDecl.HashDirective(hd, _)) -> [hd]
| d ->
reportParseErrorAt d.Range (FSComp.SR.parsOnlyHashDirectivesAllowed())
[])
ParsedSigFile(decls, $2) }
fileNamespaceSpecList:
| fileNamespaceSpec fileNamespaceSpecList
{ $1 :: $2 }
| fileNamespaceSpec
{ [$1] }
fileNamespaceSpec:
| namespaceIntro deprecated_opt_equals fileModuleSpec
{ let mNamespace, isRec, path, xml = $1
$3 (Some mNamespace, isRec, path, xml) }
/* The single module declaration that can make up a signature file */
fileModuleSpec:
| opt_attributes opt_access moduleIntro moduleSpfnsPossiblyEmptyBlock
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
let m2 = rhs parseState 3
let mDeclsAndAttrs = (List.map (fun (a: SynAttributeList) -> a.Range) $1) @ (List.map (fun (d: SynModuleSigDecl) -> d.Range) $4)
let mModule, isRec, path2, vis, attribs2 = $3
let xmlDoc = grabXmlDoc(parseState, $1, 1)
let m = (m2, mDeclsAndAttrs) ||> unionRangeWithListBy id |> unionRangeWithXmlDoc xmlDoc
(fun (mNamespaceOpt, isRec2, path, _) ->
if not (isNil path) then errorR(Error(FSComp.SR.parsNamespaceOrModuleNotBoth(), m2))
let lid = path@path2
let trivia: SynModuleOrNamespaceSigTrivia = { LeadingKeyword = SynModuleOrNamespaceLeadingKeyword.Module mModule }
ParsedSigFileFragment.NamedModule(SynModuleOrNamespaceSig(lid, (isRec || isRec2), SynModuleOrNamespaceKind.NamedModule, $4, xmlDoc, $1 @ attribs2, vis, m, trivia))) }
| moduleSpfnsPossiblyEmptyBlock
{ let m = (rhs parseState 1)
(fun (mNamespaceOpt, isRec, path, xml) ->
match path with
| [] -> ParsedSigFileFragment.AnonModule($1, m)
| _ ->
let lastDeclRange = List.tryLast $1 |> Option.map (fun decl -> decl.Range) |> Option.defaultValue (rhs parseState 1)
let m = withStart (lhs parseState).Start lastDeclRange
xml.MarkAsInvalid()
let trivia: SynModuleOrNamespaceSigTrivia =
match mNamespaceOpt with
| None -> { LeadingKeyword = SynModuleOrNamespaceLeadingKeyword.None }
| Some mNamespace -> { LeadingKeyword = SynModuleOrNamespaceLeadingKeyword.Namespace mNamespace }
ParsedSigFileFragment.NamespaceFragment(path, isRec, SynModuleOrNamespaceKind.DeclaredNamespace, $1, PreXmlDoc.Empty, [], m, trivia)) }
moduleSpfnsPossiblyEmptyBlock:
| moduleSpfnsPossiblyEmpty
{ $1 }
| OBLOCKBEGIN moduleSpfnsPossiblyEmpty oblockend opt_OBLOCKSEP
{ $2 }
| OBLOCKBEGIN moduleSpfnsPossiblyEmpty recover
{ // The lex filter ensures we can only get a mismatch in OBLOCKBEGIN/OBLOCKEND tokens if there was some other kind of error, hence we don't need to report this error
// reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnClosedBlockInHashLight())
$2
}
| OBLOCKBEGIN error oblockend
{ [] }
moduleSpfnsPossiblyEmpty:
| moduleSpfns
{ $1 }
| error
{ [] }
| /* EMPTY */
{ [] }
moduleSpfns:
| moduleSpfn opt_topSeparators moduleSpfns
{ $1 :: $3 }
| error topSeparators moduleSpfns
{ (* silent recovery *) $3 }
| moduleSpfn opt_topSeparators
{ [$1] }
moduleSpfn:
| hashDirective
{ SynModuleSigDecl.HashDirective($1, rhs2 parseState 1 1) }
| valSpfn
{ $1 }
| opt_attributes opt_access moduleIntro colonOrEquals namedModuleAbbrevBlock
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
let mModule, isRec, path, vis, attribs2 = $3
if isRec then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsInvalidUseOfRec())
if not (isSingleton path) then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsModuleAbbreviationMustBeSimpleName())
if not (isNil $1) then raiseParseErrorAt (rhs parseState 1) (FSComp.SR.parsIgnoreAttributesOnModuleAbbreviation())
if not (isNil attribs2) then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsIgnoreAttributesOnModuleAbbreviation())
match vis with
| Some vis -> raiseParseErrorAt (rhs parseState 1) (FSComp.SR.parsIgnoreVisibilityOnModuleAbbreviationAlwaysPrivate(vis.ToString()))
| _ ->
let lid: SynLongIdent = $5
let m = unionRanges mModule lid.Range
SynModuleSigDecl.ModuleAbbrev(List.head path, lid.LongIdent, m) }
| opt_attributes opt_access moduleIntro colonOrEquals moduleSpecBlock
{ let mModule, isRec, path, vis, attribs2 = $3
let xmlDoc = grabXmlDoc(parseState, $1, 1)
if not (isSingleton path) then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsModuleDefnMustBeSimpleName())
if isRec then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsInvalidUseOfRec())
let info = SynComponentInfo($1 @ attribs2, None, [], path, xmlDoc, false, vis, rhs parseState 3)
if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
let decls, mOptEnd = $5
let m = (rhs2 parseState 1 4, decls)
||> unionRangeWithListBy (fun (d: SynModuleSigDecl) -> d.Range)
|> unionRangeWithXmlDoc xmlDoc
let m = match mOptEnd with | None -> m | Some mEnd -> unionRanges m mEnd
let trivia: SynModuleSigDeclNestedModuleTrivia = { ModuleKeyword = Some mModule; EqualsRange = $4 }
SynModuleSigDecl.NestedModule(info, isRec, decls, m, trivia) }
| opt_attributes opt_access moduleIntro error
{ let mModule, isRec, path, vis, attribs2 = $3
let xmlDoc = grabXmlDoc(parseState, $1, 1)
if not (isSingleton path) then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsModuleDefnMustBeSimpleName())
if isRec then raiseParseErrorAt (rhs parseState 3) (FSComp.SR.parsInvalidUseOfRec())
let info = SynComponentInfo($1 @ attribs2, None, [], path, xmlDoc, false, vis, rhs parseState 3)
if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
let mWhole = rhs2 parseState 1 3 |> unionRangeWithXmlDoc xmlDoc
let trivia: SynModuleSigDeclNestedModuleTrivia = { ModuleKeyword = Some mModule; EqualsRange = None }
SynModuleSigDecl.NestedModule(info, isRec, [], mWhole, trivia) }
| opt_attributes opt_access typeKeyword tyconSpfn tyconSpfnList
{ if Option.isSome $2 then errorR (Error (FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier (), rhs parseState 2))
let leadingKeyword = SynTypeDefnLeadingKeyword.Type(rhs parseState 3)
let (SynTypeDefnSig (SynComponentInfo (cas, a, cs, b, _xmlDoc, d, d2, d3), typeRepr, members, range, trivia)) = $4 leadingKeyword
_xmlDoc.MarkAsInvalid()
let attrs = $1 @ cas
let xmlDoc = grabXmlDoc(parseState, $1, 1)
let mDefn =
(d3, attrs) ||> unionRangeWithListBy (fun (a: SynAttributeList) -> a.Range)
|> unionRanges range
|> unionRangeWithXmlDoc xmlDoc
let tc = (SynTypeDefnSig(SynComponentInfo(attrs, a, cs, b, xmlDoc, d, d2, d3), typeRepr, members, mDefn, trivia))
let m = (mDefn, $5) ||> unionRangeWithListBy (fun (a: SynTypeDefnSig) -> a.Range) |> unionRanges (rhs parseState 3)
SynModuleSigDecl.Types(tc :: $5, m) }
| opt_attributes opt_access exconSpfn
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
let (SynExceptionSig(SynExceptionDefnRepr(cas, a, b, c, d, d2), withKeyword, members, range)) = $3
let xmlDoc = grabXmlDoc(parseState, $1, 1)
let mDefnReprWithAttributes = (d2, $1) ||> unionRangeWithListBy (fun a -> a.Range) |> unionRangeWithXmlDoc xmlDoc
let mWhole = (mDefnReprWithAttributes, members) ||> unionRangeWithListBy (fun (m: SynMemberSig) -> m.Range)
let synExnDefn = SynExceptionSig(SynExceptionDefnRepr($1@cas, a, b, xmlDoc, d, mDefnReprWithAttributes), withKeyword, members, mWhole)
SynModuleSigDecl.Exception(synExnDefn, mWhole) }
| openDecl
{ SynModuleSigDecl.Open $1 }
valSpfn:
| opt_attributes opt_access VAL opt_attributes opt_inline opt_mutable opt_access nameop opt_explicitValTyparDecls COLON topTypeWithTypeConstraints optLiteralValueSpfn
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
let attr1, attr2, isInline, isMutable, vis2, id, doc, explicitValTyparDecls, (ty, arity), (mEquals, konst: SynExpr option) = ($1), ($4), (Option.isSome $5), (Option.isSome $6), ($7), ($8), grabXmlDoc(parseState, $1, 1), ($9), ($11), ($12)
if not (isNil attr2) then errorR(Deprecated(FSComp.SR.parsAttributesMustComeBeforeVal(), rhs parseState 4))
let m =
rhs2 parseState 1 11
|> unionRangeWithXmlDoc doc
|> fun m ->
match konst with
| None -> m
| Some e -> unionRanges m e.Range
let mVal = rhs parseState 3
let trivia: SynValSigTrivia = { LeadingKeyword = SynLeadingKeyword.Val mVal; InlineKeyword = $5; WithKeyword = None; EqualsRange = mEquals }
let valSpfn = SynValSig((attr1@attr2), id, explicitValTyparDecls, ty, arity, isInline, isMutable, doc, vis2, konst, m, trivia)
SynModuleSigDecl.Val(valSpfn, m)
}
/* The optional literal value on a literal specification in a signature */
optLiteralValueSpfn:
| /* EMPTY */
{ None, None }
| EQUALS declExpr
{ let mEquals = rhs parseState 1
Some(mEquals), Some($2) }
| EQUALS OBLOCKBEGIN declExpr oblockend opt_ODECLEND
{ let mEquals = rhs parseState 1
Some(mEquals), Some($3) }
/* A block of definitions in a module in a signature file */
moduleSpecBlock:
/* #light-syntax, with no sig/end or begin/end */
| OBLOCKBEGIN moduleSpfns oblockend
{ $2, None }
/* #light-syntax, with sig/end or begin/end */
| OBLOCKBEGIN sigOrBegin moduleSpfnsPossiblyEmpty END oblockend
{ let mEnd = rhs parseState 4
$3, Some mEnd }
/* non-#light-syntax, with sig/end or begin/end */
| sigOrBegin moduleSpfnsPossiblyEmpty END
{ let mEnd = rhs parseState 3
$2, Some mEnd }
tyconSpfnList:
| AND tyconSpfn tyconSpfnList
{ let xmlDoc = grabXmlDoc(parseState, [], 1)
let tyconSpfn =
let leadingKeyword = SynTypeDefnLeadingKeyword.And(rhs parseState 1)
let (SynTypeDefnSig(componentInfo, typeRepr, members, range, trivia) as typeDefnSig) = $2 leadingKeyword
let (SynComponentInfo(a, typars, c, lid, _xmlDoc, fixity, vis, mLongId)) = componentInfo
if xmlDoc.IsEmpty then
if _xmlDoc.IsEmpty then typeDefnSig else
let range = unionRangeWithXmlDoc _xmlDoc range
SynTypeDefnSig(componentInfo, typeRepr, members, range, trivia)
else
_xmlDoc.MarkAsInvalid()
let range = unionRangeWithXmlDoc xmlDoc range
let componentInfo = SynComponentInfo (a, typars, c, lid, xmlDoc, fixity, vis, mLongId)
SynTypeDefnSig(componentInfo, typeRepr, members, range, trivia)
tyconSpfn :: $3 }
|
{ [] }
/* A type definition in a signature */
tyconSpfn:
| typeNameInfo EQUALS tyconSpfnRhsBlock
{ let mLhs = rhs parseState 1
let mEquals = rhs parseState 2
fun leadingKeyword -> $3 leadingKeyword mLhs $1 (Some mEquals) }
| typeNameInfo opt_classSpfn
{ let mWithKwd, members = $2
let (SynComponentInfo(range = range)) = $1
let m =
match members with
| [] ->
match mWithKwd with
| None -> range
| Some mWithKwd -> unionRanges range mWithKwd
| decls ->
(range, decls) ||> unionRangeWithListBy (fun (s: SynMemberSig) -> s.Range)
fun leadingKeyword ->
let trivia: SynTypeDefnSigTrivia = { LeadingKeyword = leadingKeyword; EqualsRange = None; WithKeyword = mWithKwd }
SynTypeDefnSig($1, SynTypeDefnSigRepr.Simple(SynTypeDefnSimpleRepr.None m, m), members, m, trivia) }
/* The right-hand-side of a type definition in a signature */
tyconSpfnRhsBlock:
/* This rule allows members to be given for record and union types in the #light syntax */
/* without the use of 'with' ... 'end'. For example: */
/* type R = */
/* { a: int } */
/* member r.A = a */
/* It also takes into account that any existing 'with' */
/* block still needs to be considered and may occur indented or undented from the core type */
/* representation. */
| OBLOCKBEGIN tyconSpfnRhs opt_OBLOCKSEP classSpfnMembers opt_classSpfn oblockend opt_classSpfn
{ let m = lhs parseState
(fun leadingKeyword mLhs nameInfo mEquals ->
let members = $4 @ (snd $5)
$2 leadingKeyword mLhs nameInfo mEquals (checkForMultipleAugmentations m members (snd $7))) }
| tyconSpfnRhs opt_classSpfn
{ let m = lhs parseState
(fun leadingKeyword mLhs nameInfo mEquals ->
let _, members = $2
$1 leadingKeyword mLhs nameInfo mEquals members) }
/* The right-hand-side of a type definition in a signature */
tyconSpfnRhs:
| tyconDefnOrSpfnSimpleRepr
{ (fun leadingKeyword mLhs nameInfo mEquals augmentation ->
let declRange = unionRanges mLhs $1.Range
let mWhole = (declRange, augmentation) ||> unionRangeWithListBy (fun (mem: SynMemberSig) -> mem.Range)
let trivia: SynTypeDefnSigTrivia = { LeadingKeyword = leadingKeyword; WithKeyword = None; EqualsRange = mEquals }
SynTypeDefnSig(nameInfo, SynTypeDefnSigRepr.Simple($1, $1.Range), augmentation, mWhole, trivia)) }
| tyconClassSpfn
{ let needsCheck, (kind, decls) = $1
let objectModelRange =
match decls with
| [] -> lhs parseState
| decls ->
let start = mkSynRange parseState.ResultStartPosition parseState.ResultStartPosition
(start, decls) ||> unionRangeWithListBy (fun (s: SynMemberSig) -> s.Range)
(fun leadingKeyword nameRange nameInfo mEquals augmentation ->
if needsCheck && isNil decls then
reportParseErrorAt nameRange (FSComp.SR.parsEmptyTypeDefinition())
let declRange = unionRanges nameRange objectModelRange
let mWhole = (declRange, augmentation) ||> unionRangeWithListBy (fun (mem: SynMemberSig) -> mem.Range)
let trivia: SynTypeDefnSigTrivia = { LeadingKeyword = leadingKeyword; WithKeyword = None; EqualsRange = mEquals }
SynTypeDefnSig(nameInfo, SynTypeDefnSigRepr.ObjectModel(kind, decls, objectModelRange), augmentation, mWhole, trivia)) }
| DELEGATE OF topType
{ let m = lhs parseState
let ty, arity = $3
let flags = AbstractMemberFlags true SynMemberKind.Member
let valSig = SynValSig([], (SynIdent(mkSynId m "Invoke", None)), inferredTyparDecls, ty, arity, false, false, PreXmlDoc.Empty, None, None, m, SynValSigTrivia.Zero)
let invoke = SynMemberSig.Member(valSig, flags, m, SynMemberSigMemberTrivia.Zero)
(fun leadingKeyword nameRange nameInfo mEquals augmentation ->
if not (isNil augmentation) then raiseParseErrorAt m (FSComp.SR.parsAugmentationsIllegalOnDelegateType())
let mWhole = unionRanges nameRange m
let trivia: SynTypeDefnSigTrivia = { LeadingKeyword = leadingKeyword; WithKeyword = None; EqualsRange = mEquals }
SynTypeDefnSig(nameInfo, SynTypeDefnSigRepr.ObjectModel(SynTypeDefnKind.Delegate(ty, arity), [invoke], m), [], mWhole, trivia)) }
/* The right-hand-side of an object type definition in a signature */
tyconClassSpfn:
| classSpfnBlockKindUnspecified
{ let needsCheck, decls = $1
needsCheck, (SynTypeDefnKind.Unspecified, decls) }
| classOrInterfaceOrStruct classSpfnBlock END
{ false, ($1, $2) }
| classOrInterfaceOrStruct classSpfnBlock recover
{ reportParseErrorAt (rhs parseState 1) (FSComp.SR.parsUnmatchedClassInterfaceOrStruct())
false, ($1, $2) }
| classOrInterfaceOrStruct error END
{ // silent recovery
false, ($1, []) }
/* The right-hand-side of an object type definition in a signature with no explicit kind */
classSpfnBlockKindUnspecified:
| OBLOCKBEGIN classSpfnMembers oblockend
{ true, $2 }
| OBLOCKBEGIN classSpfnMembers recover
{ if not $3 then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsUnexpectedEndOfFileTypeSignature())
false, $2 }
/* NOTE: these rules enable the non-#light syntax to omit the kind of a type. */
| BEGIN classSpfnBlock END
{ false, $2 }
| BEGIN classSpfnBlock recover
{ false, $2 }
/* The right-hand-side of an object type definition in a signature */
classSpfnBlock:
| OBLOCKBEGIN classSpfnMembers oblockend
{ $2 }
| OBLOCKBEGIN classSpfnMembers recover
{ if not $3 then reportParseErrorAt (rhs parseState 3) (FSComp.SR.parsUnexpectedEndOfFileTypeSignature())
$2 }
| classSpfnMembers
{ $1 }
/* The members of an object type definition in a signature, possibly empty */
classSpfnMembers:
| classSpfnMembersAtLeastOne
{ $1 }
| /* EMPTY */
{ [] }
/* The members of an object type definition in a signature */
classSpfnMembersAtLeastOne:
| classMemberSpfn opt_seps classSpfnMembers
{ $1 :: $3 }
/* A object member in a signature */
classMemberSpfn:
| opt_attributes opt_access memberSpecFlags opt_inline opt_access nameop opt_explicitValTyparDecls COLON topTypeWithTypeConstraints classMemberSpfnGetSet optLiteralValueSpfn
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
let isInline, doc, vis2, id, explicitValTyparDecls, (ty, arity), (mEquals, optLiteralValue) = (Option.isSome $4), grabXmlDoc(parseState, $1, 1), $5, $6, $7, $9, $11
let mWith, (getSet, getSetRangeOpt) = $10
let getSetAdjuster arity = match arity, getSet with SynValInfo([], _), SynMemberKind.Member -> SynMemberKind.PropertyGet | _ -> getSet
let mWhole =
let m = rhs parseState 3
match getSetRangeOpt with
| None -> unionRanges m ty.Range
| Some gs -> unionRanges m (gs: GetSetKeywords).Range
|> fun m -> (m, $1) ||> unionRangeWithListBy (fun (a: SynAttributeList) -> a.Range)
|> unionRangeWithXmlDoc doc
|> fun m ->
match optLiteralValue with
| None -> m
| Some e -> unionRanges m e.Range
let flags, leadingKeyword = $3
let flags = flags (getSetAdjuster arity)
let trivia = { LeadingKeyword = leadingKeyword; InlineKeyword = $4; WithKeyword = mWith; EqualsRange = mEquals }
let valSpfn = SynValSig($1, id, explicitValTyparDecls, ty, arity, isInline, false, doc, vis2, optLiteralValue, mWhole, trivia)
let trivia: SynMemberSigMemberTrivia = { GetSetKeywords = getSetRangeOpt }
SynMemberSig.Member(valSpfn, flags, mWhole, trivia) }
| opt_attributes opt_access interfaceMember appType
{ if Option.isSome $2 then errorR(Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier(), rhs parseState 2))
SynMemberSig.Interface($4, unionRanges (rhs parseState 3) ($4).Range) }
| opt_attributes opt_access INHERIT appType
{ if Option.isSome $2 then errorR (Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier (), rhs parseState 2))
SynMemberSig.Inherit($4, unionRanges (rhs parseState 1) $4.Range) }
| opt_attributes opt_access INHERIT recover
{ if Option.isSome $2 then errorR (Error(FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier (), rhs parseState 2))
let mInherit = rhs parseState 3
let ty = SynType.FromParseError(mInherit.EndRange)
SynMemberSig.Inherit(ty, unionRanges (rhs parseState 1) mInherit) }
| opt_attributes opt_access VAL fieldDecl
{ if Option.isSome $2 then
errorR (Error (FSComp.SR.parsVisibilityDeclarationsShouldComePriorToIdentifier (), rhs parseState 2))
let mStart = rhs parseState 1
let mVal = rhs parseState 3