Skip to content

Commit e697b61

Browse files
author
jared
committed
Undo fieldnames should be disjoint from keywords
1 parent 7d4526d commit e697b61

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

lambda-buffers-frontend/data/goldens/good/LambdaBuffers.lbf

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ record ClassDef = { name : ClassName
5252

5353
derive Eq ClassDef
5454

55-
record ClassConstraint = { classRef : ClassRef, args : List TyArg }
55+
record ClassConstraint = { class : ClassRef, args : List TyArg }
5656

5757
derive Eq ClassConstraint
5858

@@ -64,7 +64,7 @@ prod Derive = Constraint
6464

6565
derive Eq Derive
6666

67-
record Constraint = { classRef : ClassRef, args : List Ty }
67+
record Constraint = { class : ClassRef, args : List Ty }
6868

6969
derive Eq Constraint
7070

@@ -111,4 +111,4 @@ derive Eq ModuleNamePart
111111

112112
prod ClassName = Text
113113

114-
derive Eq ClassName
114+
derive Eq ClassName

lambda-buffers-frontend/src/LambdaBuffers/Frontend/Parsec.hs

+12-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import Data.Char qualified as Char
2222
import Data.Kind (Type)
2323
import Data.Maybe (fromJust, isJust)
2424
import Data.String (IsString (fromString))
25-
import Data.Text qualified as Text
2625
import LambdaBuffers.Compiler.NamingCheck (pClassName, pConstrName, pFieldName, pModuleNamePart, pTyName)
2726
import LambdaBuffers.Frontend.Syntax (ClassConstraint (ClassConstraint), ClassDef (ClassDef), ClassName (ClassName), ClassRef (ClassRef), ConstrName (ConstrName), Constraint (Constraint), Constructor (Constructor), Derive (Derive), Field (Field), FieldName (FieldName), Import (Import), InstanceClause (InstanceClause), Module (Module), ModuleAlias (ModuleAlias), ModuleName (ModuleName), ModuleNamePart (ModuleNamePart), Name (Name), Product (Product), Record (Record), SourceInfo (SourceInfo, to), SourcePos (SourcePos), Statement (StClassDef, StDerive, StInstanceClause, StTyDef), Sum (Sum), Ty (TyApp, TyRef', TyVar), TyArg (TyArg), TyBody (Opaque, ProductBody, RecordBody, SumBody), TyDef (TyDef), TyName (TyName), TyRef (TyRef), VarName (VarName), kwAs, kwClassDef, kwDerive, kwImport, kwInstance, kwModule, kwQualified, kwTyDefOpaque, kwTyDefProduct, kwTyDefRecord, kwTyDefSum, kws)
2827
import Text.Parsec (ParseError, ParsecT, SourceName, Stream, alphaNum, between, char, endOfLine, eof, getPosition, label, lower, many, many1, manyTill, notFollowedBy, optionMaybe, runParserT, satisfy, sepBy, sepEndBy, sourceColumn, sourceLine, sourceName, space, string, try, unexpected, (<?>))
@@ -207,10 +206,18 @@ tokenTyRef = token' parseTyRef
207206
parseFieldName :: Stream s m Char => Parser s m (FieldName SourceInfo)
208207
parseFieldName =
209208
withSourceInfo . label' "record field name" $ do
210-
v <- pFieldName
211-
-- Recall in the lexical specification that fieldnames are disjoint from keywords
212-
notKeyword $ Text.unpack v
213-
return $ FieldName v
209+
-- TODO(jaredponn): Technically, the specification says that field names
210+
-- are disjoint from keywords, but some of the other golden tests use this
211+
-- fact.
212+
-- We leave it in as a fairly harmless bug for now.
213+
--
214+
-- But the version that fixes this is as follows:
215+
--
216+
-- > v <- pFieldName
217+
-- > -- Recall in the lexical specification that fieldnames are disjoint from keywords
218+
-- > notKeyword $ Data.Text.unpack v
219+
-- > return $ FieldName v
220+
FieldName <$> pFieldName
214221

215222
tokenFieldName :: Stream s m Char => Parser s m (FieldName SourceInfo)
216223
tokenFieldName = token' parseFieldName

0 commit comments

Comments
 (0)