Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support for record types + parser test

* Supports the trailing semicolon
* No type extension yet
* I am voluntarily breaking *TestUnfinishedConstructs01* because I'm not
sure of how the error should be represented.
  • Loading branch information...
commit 56106d2d6fc141a406f29f145faa980d3a906fac 1 parent e83c5c5
@OkayX6 OkayX6 authored
View
12 src/fsharper/Psi.FSharp/Psi.FSharp.csproj
@@ -99,9 +99,13 @@
<Compile Include="src\Gen\Psi\FSharp\Impl\PrimaryNamespaceDeclaration.cs" />
<Compile Include="src\Gen\Psi\FSharp\Impl\QualifiedNamespaceUsage.cs" />
<Compile Include="src\Gen\Psi\FSharp\Impl\QualifiedTypeUsage.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\Impl\RecordField.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\Impl\RecordFieldList.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\Impl\RecordTypeDeclaration.cs" />
<Compile Include="src\Gen\Psi\FSharp\Impl\TokenType.cs" />
<Compile Include="src\Gen\Psi\FSharp\Impl\TypeArgumentList.cs" />
<Compile Include="src\Gen\Psi\FSharp\Impl\TypeConstraint.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\Impl\TypeName.cs" />
<Compile Include="src\Gen\Psi\FSharp\Impl\TypeParameterConstraintsClause.cs" />
<Compile Include="src\Gen\Psi\FSharp\Impl\TypeParameterDeclaration.cs" />
<Compile Include="src\Gen\Psi\FSharp\Impl\TypeParameterList.cs" />
@@ -112,10 +116,14 @@
<Compile Include="src\Gen\Psi\FSharp\IPrimaryNamespaceDeclaration.cs" />
<Compile Include="src\Gen\Psi\FSharp\IQualifiedNamespaceUsage.cs" />
<Compile Include="src\Gen\Psi\FSharp\IQualifiedTypeUsage.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\IRecordField.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\IRecordFieldList.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\IRecordTypeDeclaration.cs" />
<Compile Include="src\Gen\Psi\FSharp\ITypeArgumentList.cs" />
<Compile Include="src\Gen\Psi\FSharp\ITypeConstraint.cs" />
<Compile Include="src\Gen\Psi\FSharp\ITypeDeclaration.cs" />
<Compile Include="src\Gen\Psi\FSharp\ITypeExpression.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\ITypeName.cs" />
<Compile Include="src\Gen\Psi\FSharp\ITypeParameterConstraint.cs" />
<Compile Include="src\Gen\Psi\FSharp\ITypeParameterConstraintsClause.cs" />
<Compile Include="src\Gen\Psi\FSharp\ITypeParameterDeclaration.cs" />
@@ -130,12 +138,16 @@
<Compile Include="src\Gen\Psi\FSharp\PrimaryNamespaceDeclarationNavigator.cs" />
<Compile Include="src\Gen\Psi\FSharp\QualifiedNamespaceUsageNavigator.cs" />
<Compile Include="src\Gen\Psi\FSharp\QualifiedTypeUsageNavigator.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\RecordFieldListNavigator.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\RecordFieldNavigator.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\RecordTypeDeclarationNavigator.cs" />
<Compile Include="src\Gen\Psi\FSharp\TreeNodeVisitor.cs" />
<Compile Include="src\Gen\Psi\FSharp\TreeNodeVisitor`1.cs" />
<Compile Include="src\Gen\Psi\FSharp\TreeNodeVisitor`2.cs" />
<Compile Include="src\Gen\Psi\FSharp\TypeConstraintNavigator.cs" />
<Compile Include="src\Gen\Psi\FSharp\TypeDeclarationNavigator.cs" />
<Compile Include="src\Gen\Psi\FSharp\TypeExpressionNavigator.cs" />
+ <Compile Include="src\Gen\Psi\FSharp\TypeNameNavigator.cs" />
<Compile Include="src\Gen\Psi\FSharp\TypeParameterConstraintNavigator.cs" />
<Compile Include="src\Gen\Psi\FSharp\TypeParameterConstraintsClauseNavigator.cs" />
<Compile Include="src\Gen\Psi\FSharp\TypeParameterDeclarationNavigator.cs" />
View
4 src/fsharper/Psi.FSharp/src/Parsing/FSharpLexerGenerated.cs
@@ -10,9 +10,9 @@ namespace JetBrains.ReSharper.Psi.FSharp.Parsing
public partial class FSharpLexerGenerated : ILexer<FSharpLexerState>
{
private TokenNodeType currTokenType;
- protected static readonly Dictionary<string, TokenNodeType> keywords = new Dictionary<string, TokenNodeType>();
+ private static readonly Dictionary<string, TokenNodeType> keywords = new Dictionary<string, TokenNodeType>();
protected static readonly Dictionary<NodeType, string> tokenTypesToText = new Dictionary<NodeType, string>();
- private static HashSet<string> bangKeywords = new HashSet<string>();
+ private static readonly HashSet<string> bangKeywords = new HashSet<string>();
static FSharpLexerGenerated()
{
View
5 src/fsharper/Psi.FSharp/src/Parsing/ParserMessages.cs
@@ -6,7 +6,7 @@ namespace JetBrains.ReSharper.Psi.FSharp.Parsing
/// <summary>
/// Definitions taken from PsiPlugin (for now).
/// </summary>
- public class ParserMessages
+ public static class ParserMessages
{
private const string IDS_EXPECTED_SYMBOL = "{0} expected";
private const string IDS_EXPECTED_TWO_SYMBOLS = "{0} or {1} expected";
@@ -38,6 +38,9 @@ public class ParserMessages
public const string IDS_PARAMETERIZED_TYPE_REFERENCE = "parameterized type reference";
public const string IDS_PREFIX_SYMBOL = "symbol";
public const string IDS_SPECIFICATION = "specification";
+ public const string IDS_TYPE_DECLARATION = "type declaration";
+ public const string IDS_ABBREV_TYPE_DECLARATION = "type abbreviation declaration";
+ public const string IDS_RECORD_TYPE_DECLARATION = "record type declaration";
public const string IDS_TYPE_EXPRESSION = "expression";
public const string IDS_TYPE_INFORMATION = "type information";
public const string IDS_TYPE_PARAMETER_LIST = "parameter";
View
50 src/fsharper/Psi.FSharp/src/fsharp.psi
@@ -215,7 +215,7 @@ valueConstraint[typeParameterUsage typeParameter]
STRUCT_KEYWORD<KEYWORD, StructKeyword>
;
-private errorhandling typeName
+errorhandling typeName
:
attributeSectionList<ATTRIBUTES, Attributes>?
accessModifier<MODIFIER, AccessModifier>?
@@ -225,15 +225,51 @@ private errorhandling typeName
errorhandling interface typeDeclaration
:
- abbrevTypeDeclaration
- //| TODO: etc
+ !(#typeKeyword: TYPE_KEYWORD
+ #typeNameToken: typeName
+ #equals: EQUALS)
+ (
+ abbrevTypeDeclaration[typeKeyword, typeNameToken, equals] |
+ recordTypeDeclaration[typeKeyword, typeNameToken, equals]
+ //| TODO: etc
+ )
+ ;
+
+abbrevTypeDeclaration[TYPE_KEYWORD typeKeyword, typeName typeNameToken, EQUALS equals]
+ :
+ &typeKeyword<KEYWORD, TypeKeyword>
+ &typeNameToken<NAME, TypeName>
+ &equals<EQ, Eq>
+ typeExpression<TYPE, TypeExpression>
;
-abbrevTypeDeclaration
+recordTypeDeclaration[TYPE_KEYWORD typeKeyword, typeName typeNameToken, EQUALS equals]
:
- TYPE_KEYWORD<KEYWORD, TypeKeyword>
- typeName
- EQUALS<EQ, Eq>
+ &typeKeyword<KEYWORD, TypeKeyword>
+ &typeNameToken<NAME, TypeName>
+ &equals<EQ, Eq>
+ LBRACE<LBRACE, LBrace>
+ recordFieldList
+ RBRACE<RBRACE, RBrace>
+ // TODO - OkayX6: type-extension-elements (optional)
+ ;
+
+recordFieldList
+ :
+ recordField<FIELD, Field>
+ (
+ SEMICOLON<SEMICOLON, SemiColon>
+ recordFieldList?
+ )?
+ ;
+
+recordField
+ :
+ attributeSection<ATTRIBUTE, Attribute>?
+ MUTABLE_KEYWORD<KEYWORD, MutableKeyword>?
+ accessModifier<MODIFIER, AccessModifier>?
+ IDENTIFIER<NAME, NameIdentifier>
+ COLON<COLON, Colon>
typeExpression<TYPE, TypeExpression>
;
View
6 src/fsharper/Tests/FSharpParserTest.cs
@@ -32,6 +32,12 @@ public void TestTypeDeclaration02()
}
[Test]
+ public void TestTypeDeclaration03_RecordType()
+ {
+ DoNamedTest();
+ }
+
+ [Test]
public void TestTypeParameterConstraints01()
{
DoNamedTest();
View
3  test/data/parsing/TestTypeDeclaration01.fs.gold
@@ -6,7 +6,8 @@ IFSharpFile
IModuleBody
IAbbrevTypeDeclaration
FSharpTokenType+TypeKeywordTokenElement(type:TYPE_KEYWORD, text:type)
- Identifier(type:IDENTIFIER, text:YYY)
+ ITypeName
+ Identifier(type:IDENTIFIER, text:YYY)
FSharpTokenType+EqualsTokenElement(type:EQUALS, text:=)
IQualifiedTypeUsage
IQualifiedTypeUsage
View
60 test/data/parsing/TestTypeDeclaration02.fs.gold
@@ -9,14 +9,15 @@ IFSharpFile
Identifier(type:IDENTIFIER, text:YYY)
IAbbrevTypeDeclaration
FSharpTokenType+TypeKeywordTokenElement(type:TYPE_KEYWORD, text:type)
- IAccessModifier
- FSharpTokenType+PrivateKeywordTokenElement(type:PRIVATE_KEYWORD, text:private)
- Identifier(type:IDENTIFIER, text:A)
- ITypeParameterList
- FSharpTokenType+LessTokenElement(type:LESS, text:<)
- ITypeParameterDeclaration
- FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
- FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
+ ITypeName
+ IAccessModifier
+ FSharpTokenType+PrivateKeywordTokenElement(type:PRIVATE_KEYWORD, text:private)
+ Identifier(type:IDENTIFIER, text:A)
+ ITypeParameterList
+ FSharpTokenType+LessTokenElement(type:LESS, text:<)
+ ITypeParameterDeclaration
+ FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
+ FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
FSharpTokenType+EqualsTokenElement(type:EQUALS, text:=)
IQualifiedTypeUsage
Identifier(type:IDENTIFIER, text:List)
@@ -31,14 +32,15 @@ IFSharpFile
Identifier(type:IDENTIFIER, text:XXX1)
IAbbrevTypeDeclaration
FSharpTokenType+TypeKeywordTokenElement(type:TYPE_KEYWORD, text:type)
- IAccessModifier
- FSharpTokenType+PrivateKeywordTokenElement(type:PRIVATE_KEYWORD, text:private)
- Identifier(type:IDENTIFIER, text:A)
- ITypeParameterList
- FSharpTokenType+LessTokenElement(type:LESS, text:<)
- ITypeParameterDeclaration
- FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
- FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
+ ITypeName
+ IAccessModifier
+ FSharpTokenType+PrivateKeywordTokenElement(type:PRIVATE_KEYWORD, text:private)
+ Identifier(type:IDENTIFIER, text:A)
+ ITypeParameterList
+ FSharpTokenType+LessTokenElement(type:LESS, text:<)
+ ITypeParameterDeclaration
+ FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
+ FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
FSharpTokenType+EqualsTokenElement(type:EQUALS, text:=)
IQualifiedTypeUsage
IQualifiedTypeUsage
@@ -61,17 +63,18 @@ IFSharpFile
FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
IAbbrevTypeDeclaration
FSharpTokenType+TypeKeywordTokenElement(type:TYPE_KEYWORD, text:type)
- IAccessModifier
- FSharpTokenType+PrivateKeywordTokenElement(type:PRIVATE_KEYWORD, text:private)
- Identifier(type:IDENTIFIER, text:A1)
- ITypeParameterList
- FSharpTokenType+LessTokenElement(type:LESS, text:<)
- ITypeParameterDeclaration
- FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
- FSharpTokenType+CommaTokenElement(type:COMMA, text:,)
- ITypeParameterDeclaration
- FSharpGenericToken(type:TYPE_VARIABLE, text:'T1)
- FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
+ ITypeName
+ IAccessModifier
+ FSharpTokenType+PrivateKeywordTokenElement(type:PRIVATE_KEYWORD, text:private)
+ Identifier(type:IDENTIFIER, text:A1)
+ ITypeParameterList
+ FSharpTokenType+LessTokenElement(type:LESS, text:<)
+ ITypeParameterDeclaration
+ FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
+ FSharpTokenType+CommaTokenElement(type:COMMA, text:,)
+ ITypeParameterDeclaration
+ FSharpGenericToken(type:TYPE_VARIABLE, text:'T1)
+ FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
FSharpTokenType+EqualsTokenElement(type:EQUALS, text:=)
IQualifiedTypeUsage
IQualifiedTypeUsage
@@ -97,7 +100,8 @@ IFSharpFile
FSharpTokenType+GlobalKeywordTokenElement(type:GLOBAL_KEYWORD, text:global)
IAbbrevTypeDeclaration
FSharpTokenType+TypeKeywordTokenElement(type:TYPE_KEYWORD, text:type)
- Identifier(type:IDENTIFIER, text:B)
+ ITypeName
+ Identifier(type:IDENTIFIER, text:B)
FSharpTokenType+EqualsTokenElement(type:EQUALS, text:=)
IQualifiedTypeUsage
Identifier(type:IDENTIFIER, text:int)
View
11 test/data/parsing/TestTypeDeclaration03_RecordType.fs
@@ -0,0 +1,11 @@
+//{caret}
+module XXX
+
+type Record1 = {
+ mutable Field1 : int;
+}
+
+type Record2 = {
+ Field1 : int;
+ mutable Field2 : int
+}
View
43 test/data/parsing/TestTypeDeclaration03_RecordType.fs.gold
@@ -0,0 +1,43 @@
+Language: PsiLanguageType:FSHARP
+IFSharpFile
+ IPrimaryModuleDeclaration
+ FSharpTokenType+ModuleKeywordTokenElement(type:MODULE_KEYWORD, text:module)
+ Identifier(type:IDENTIFIER, text:XXX)
+ IModuleBody
+ IRecordTypeDeclaration
+ FSharpTokenType+TypeKeywordTokenElement(type:TYPE_KEYWORD, text:type)
+ ITypeName
+ Identifier(type:IDENTIFIER, text:Record1)
+ FSharpTokenType+EqualsTokenElement(type:EQUALS, text:=)
+ FSharpTokenType+LbraceTokenElement(type:LBRACE, text:{)
+ IRecordFieldList
+ IRecordField
+ FSharpTokenType+MutableKeywordTokenElement(type:MUTABLE_KEYWORD, text:mutable)
+ Identifier(type:IDENTIFIER, text:Field1)
+ FSharpTokenType+ColonTokenElement(type:COLON, text::)
+ IQualifiedTypeUsage
+ Identifier(type:IDENTIFIER, text:int)
+ FSharpTokenType+SemicolonTokenElement(type:SEMICOLON, text:;)
+ FSharpTokenType+RbraceTokenElement(type:RBRACE, text:})
+ IRecordTypeDeclaration
+ FSharpTokenType+TypeKeywordTokenElement(type:TYPE_KEYWORD, text:type)
+ ITypeName
+ Identifier(type:IDENTIFIER, text:Record2)
+ FSharpTokenType+EqualsTokenElement(type:EQUALS, text:=)
+ FSharpTokenType+LbraceTokenElement(type:LBRACE, text:{)
+ IRecordFieldList
+ IRecordField
+ Identifier(type:IDENTIFIER, text:Field1)
+ FSharpTokenType+ColonTokenElement(type:COLON, text::)
+ IQualifiedTypeUsage
+ Identifier(type:IDENTIFIER, text:int)
+ FSharpTokenType+SemicolonTokenElement(type:SEMICOLON, text:;)
+ IRecordFieldList
+ IRecordField
+ FSharpTokenType+MutableKeywordTokenElement(type:MUTABLE_KEYWORD, text:mutable)
+ Identifier(type:IDENTIFIER, text:Field2)
+ FSharpTokenType+ColonTokenElement(type:COLON, text::)
+ IQualifiedTypeUsage
+ Identifier(type:IDENTIFIER, text:int)
+ FSharpTokenType+RbraceTokenElement(type:RBRACE, text:})
+
View
79 test/data/parsing/TestTypeParameterConstraints01.fs.gold
@@ -6,50 +6,51 @@ IFSharpFile
IModuleBody
IAbbrevTypeDeclaration
FSharpTokenType+TypeKeywordTokenElement(type:TYPE_KEYWORD, text:type)
- IAttributeSectionList
- IAttributeSection
- FSharpTokenType+LbrackLessTokenElement(type:LBRACK_LESS, text:[<)
- Identifier(type:IDENTIFIER, text:Serializable)
- FSharpTokenType+GreaterRbrackTokenElement(type:GREATER_RBRACK, text:>])
- IAccessModifier
- FSharpTokenType+PublicKeywordTokenElement(type:PUBLIC_KEYWORD, text:public)
- Identifier(type:IDENTIFIER, text:A)
- ITypeParameterList
- FSharpTokenType+LessTokenElement(type:LESS, text:<)
- ITypeParameterDeclaration
- FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
- FSharpTokenType+CommaTokenElement(type:COMMA, text:,)
- ITypeParameterDeclaration
- FSharpGenericToken(type:TYPE_VARIABLE, text:'T1)
- ITypeParameterConstraintsClause
- FSharpTokenType+WhenKeywordTokenElement(type:WHEN_KEYWORD, text:when)
- ITypeConstraint
- ITypeParameterUsage
- FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
- FSharpTokenType+ColonGreaterTokenElement(type:COLON_GREATER, text::>)
- IQualifiedTypeUsage
+ ITypeName
+ IAttributeSectionList
+ IAttributeSection
+ FSharpTokenType+LbrackLessTokenElement(type:LBRACK_LESS, text:[<)
+ Identifier(type:IDENTIFIER, text:Serializable)
+ FSharpTokenType+GreaterRbrackTokenElement(type:GREATER_RBRACK, text:>])
+ IAccessModifier
+ FSharpTokenType+PublicKeywordTokenElement(type:PUBLIC_KEYWORD, text:public)
+ Identifier(type:IDENTIFIER, text:A)
+ ITypeParameterList
+ FSharpTokenType+LessTokenElement(type:LESS, text:<)
+ ITypeParameterDeclaration
+ FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
+ FSharpTokenType+CommaTokenElement(type:COMMA, text:,)
+ ITypeParameterDeclaration
+ FSharpGenericToken(type:TYPE_VARIABLE, text:'T1)
+ ITypeParameterConstraintsClause
+ FSharpTokenType+WhenKeywordTokenElement(type:WHEN_KEYWORD, text:when)
+ ITypeConstraint
+ ITypeParameterUsage
+ FSharpGenericToken(type:TYPE_VARIABLE, text:'T)
+ FSharpTokenType+ColonGreaterTokenElement(type:COLON_GREATER, text::>)
IQualifiedTypeUsage
IQualifiedTypeUsage
IQualifiedTypeUsage
- Identifier(type:IDENTIFIER, text:System)
+ IQualifiedTypeUsage
+ Identifier(type:IDENTIFIER, text:System)
+ FSharpTokenType+DotTokenElement(type:DOT, text:.)
+ Identifier(type:IDENTIFIER, text:Collections)
FSharpTokenType+DotTokenElement(type:DOT, text:.)
- Identifier(type:IDENTIFIER, text:Collections)
+ Identifier(type:IDENTIFIER, text:Generic)
FSharpTokenType+DotTokenElement(type:DOT, text:.)
- Identifier(type:IDENTIFIER, text:Generic)
- FSharpTokenType+DotTokenElement(type:DOT, text:.)
- Identifier(type:IDENTIFIER, text:IList)
- ITypeArgumentList
- FSharpTokenType+LessTokenElement(type:LESS, text:<)
- IQualifiedTypeUsage
- Identifier(type:IDENTIFIER, text:int)
- FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
- FSharpTokenType+AndKeywordTokenElement(type:AND_KEYWORD, text:&&)
- IValueConstraint
- ITypeParameterUsage
- FSharpGenericToken(type:TYPE_VARIABLE, text:'T1)
- FSharpTokenType+ColonTokenElement(type:COLON, text::)
- FSharpTokenType+StructKeywordTokenElement(type:STRUCT_KEYWORD, text:struct)
- FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
+ Identifier(type:IDENTIFIER, text:IList)
+ ITypeArgumentList
+ FSharpTokenType+LessTokenElement(type:LESS, text:<)
+ IQualifiedTypeUsage
+ Identifier(type:IDENTIFIER, text:int)
+ FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
+ FSharpTokenType+AndKeywordTokenElement(type:AND_KEYWORD, text:&&)
+ IValueConstraint
+ ITypeParameterUsage
+ FSharpGenericToken(type:TYPE_VARIABLE, text:'T1)
+ FSharpTokenType+ColonTokenElement(type:COLON, text::)
+ FSharpTokenType+StructKeywordTokenElement(type:STRUCT_KEYWORD, text:struct)
+ FSharpTokenType+GreaterTokenElement(type:GREATER, text:>)
FSharpTokenType+EqualsTokenElement(type:EQUALS, text:=)
IQualifiedTypeUsage
IQualifiedTypeUsage
Please sign in to comment.
Something went wrong with that request. Please try again.