Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
2e3f671c
Commit
2e3f671c
authored
Feb 16, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
class -> struct
parent
22a75445
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
54 additions
and
54 deletions
+54
-54
Compiler.hs
compiler/src/Compiler.hs
+19
-19
Grammar.hs
compiler/src/Grammar.hs
+1
-1
Lexer.hs
compiler/src/Lexer.hs
+1
-1
Parser.hs
compiler/src/Parser.hs
+9
-9
Semantics.hs
compiler/src/Semantics.hs
+23
-23
Token.hs
compiler/src/Token.hs
+1
-1
No files found.
compiler/src/Compiler.hs
View file @
2e3f671c
...
...
@@ -105,7 +105,7 @@ statusToMaybe (Failed _) = Nothing
-- | Look up a direct member of a descriptor by name.
descMember
name
(
DescFile
d
)
=
lookupMember
name
(
fileMemberMap
d
)
descMember
name
(
DescEnum
d
)
=
lookupMember
name
(
enumMemberMap
d
)
descMember
name
(
Desc
Class
d
)
=
lookupMember
name
(
class
MemberMap
d
)
descMember
name
(
Desc
Struct
d
)
=
lookupMember
name
(
struct
MemberMap
d
)
descMember
name
(
DescInterface
d
)
=
lookupMember
name
(
interfaceMemberMap
d
)
descMember
name
(
DescAlias
d
)
=
descMember
name
(
aliasTarget
d
)
descMember
_
_
=
Nothing
...
...
@@ -191,7 +191,7 @@ compileValue pos (BuiltinType BuiltinText) _ = makeExpectError pos "string"
compileValue
pos
(
BuiltinType
BuiltinBytes
)
_
=
makeExpectError
pos
"string"
compileValue
pos
(
EnumType
_
)
_
=
makeError
pos
"Unimplemented: enum default values"
compileValue
pos
(
ClassType
_
)
_
=
makeError
pos
"Unimplemented: class
default values"
compileValue
pos
(
StructType
_
)
_
=
makeError
pos
"Unimplemented: struct
default values"
compileValue
pos
(
InterfaceType
_
)
_
=
makeError
pos
"Interfaces can't have default values."
compileValue
pos
(
ListType
_
)
_
=
makeError
pos
"Unimplemented: array default values"
...
...
@@ -200,11 +200,11 @@ makeFileMemberMap desc = Map.fromList allMembers where
allMembers
=
[
(
aliasName
m
,
DescAlias
m
)
|
m
<-
fileAliases
desc
]
++
[
(
constantName
m
,
DescConstant
m
)
|
m
<-
fileConstants
desc
]
++
[
(
enumName
m
,
DescEnum
m
)
|
m
<-
fileEnums
desc
]
++
[
(
className
m
,
DescClass
m
)
|
m
<-
fileClasse
s
desc
]
++
[
(
structName
m
,
DescStruct
m
)
|
m
<-
fileStruct
s
desc
]
++
[
(
interfaceName
m
,
DescInterface
m
)
|
m
<-
fileInterfaces
desc
]
descAsType
_
(
DescEnum
desc
)
=
succeed
(
EnumType
desc
)
descAsType
_
(
Desc
Class
desc
)
=
succeed
(
Class
Type
desc
)
descAsType
_
(
Desc
Struct
desc
)
=
succeed
(
Struct
Type
desc
)
descAsType
_
(
DescInterface
desc
)
=
succeed
(
InterfaceType
desc
)
descAsType
_
(
DescBuiltinType
desc
)
=
succeed
(
BuiltinType
desc
)
descAsType
name
(
DescAlias
desc
)
=
descAsType
name
(
aliasTarget
desc
)
...
...
@@ -286,21 +286,21 @@ compileDecl scope (EnumValueDecl (Located _ name) (Located _ number) decls) =
,
enumValueOptions
=
options
})))
compileDecl
scope
(
Class
Decl
(
Located
_
name
)
decls
)
=
compileDecl
scope
(
Struct
Decl
(
Located
_
name
)
decls
)
=
CompiledMember
name
(
feedback
(
\
desc
->
do
(
members
,
memberMap
,
options
)
<-
compileChildDecls
desc
decls
return
(
Desc
Class
Class
Desc
{
class
Name
=
name
,
class
Parent
=
scope
,
class
Fields
=
[
d
|
DescField
d
<-
members
]
,
class
NestedAliases
=
[
d
|
DescAlias
d
<-
members
]
,
class
NestedConstants
=
[
d
|
DescConstant
d
<-
members
]
,
class
NestedEnums
=
[
d
|
DescEnum
d
<-
members
]
,
classNestedClasses
=
[
d
|
DescClass
d
<-
members
]
,
class
NestedInterfaces
=
[
d
|
DescInterface
d
<-
members
]
,
class
Options
=
options
,
class
Members
=
members
,
class
MemberMap
=
memberMap
return
(
Desc
Struct
Struct
Desc
{
struct
Name
=
name
,
struct
Parent
=
scope
,
struct
Fields
=
[
d
|
DescField
d
<-
members
]
,
struct
NestedAliases
=
[
d
|
DescAlias
d
<-
members
]
,
struct
NestedConstants
=
[
d
|
DescConstant
d
<-
members
]
,
struct
NestedEnums
=
[
d
|
DescEnum
d
<-
members
]
,
structNestedStructs
=
[
d
|
DescStruct
d
<-
members
]
,
struct
NestedInterfaces
=
[
d
|
DescInterface
d
<-
members
]
,
struct
Options
=
options
,
struct
Members
=
members
,
struct
MemberMap
=
memberMap
})))
compileDecl
scope
(
FieldDecl
(
Located
_
name
)
(
Located
_
number
)
typeExp
defaultValue
decls
)
=
...
...
@@ -329,7 +329,7 @@ compileDecl scope (InterfaceDecl (Located _ name) decls) =
,
interfaceNestedAliases
=
[
d
|
DescAlias
d
<-
members
]
,
interfaceNestedConstants
=
[
d
|
DescConstant
d
<-
members
]
,
interfaceNestedEnums
=
[
d
|
DescEnum
d
<-
members
]
,
interfaceNested
Classes
=
[
d
|
DescClass
d
<-
members
]
,
interfaceNested
Structs
=
[
d
|
DescStruct
d
<-
members
]
,
interfaceNestedInterfaces
=
[
d
|
DescInterface
d
<-
members
]
,
interfaceOptions
=
options
,
interfaceMembers
=
members
...
...
@@ -378,7 +378,7 @@ compileFile name decls =
,
fileAliases
=
[
d
|
DescAlias
d
<-
members
]
,
fileConstants
=
[
d
|
DescConstant
d
<-
members
]
,
fileEnums
=
[
d
|
DescEnum
d
<-
members
]
,
file
Classes
=
[
d
|
DescClass
d
<-
members
]
,
file
Structs
=
[
d
|
DescStruct
d
<-
members
]
,
fileInterfaces
=
[
d
|
DescInterface
d
<-
members
]
,
fileOptions
=
options
,
fileMembers
=
members
...
...
compiler/src/Grammar.hs
View file @
2e3f671c
...
...
@@ -47,7 +47,7 @@ data Declaration = AliasDecl (Located String) DeclName
|
ConstantDecl
(
Located
String
)
TypeExpression
(
Located
FieldValue
)
|
EnumDecl
(
Located
String
)
[
Declaration
]
|
EnumValueDecl
(
Located
String
)
(
Located
Integer
)
[
Declaration
]
|
Class
Decl
(
Located
String
)
[
Declaration
]
|
Struct
Decl
(
Located
String
)
[
Declaration
]
|
FieldDecl
(
Located
String
)
(
Located
Integer
)
TypeExpression
(
Maybe
(
Located
FieldValue
))
[
Declaration
]
|
InterfaceDecl
(
Located
String
)
[
Declaration
]
...
...
compiler/src/Lexer.hs
View file @
2e3f671c
...
...
@@ -35,7 +35,7 @@ keywords =
,
(
UsingKeyword
,
"using"
)
,
(
ConstKeyword
,
"const"
)
,
(
EnumKeyword
,
"enum"
)
,
(
ClassKeyword
,
"class
"
)
,
(
StructKeyword
,
"struct
"
)
,
(
InterfaceKeyword
,
"interface"
)
,
(
OptionKeyword
,
"option"
)
]
...
...
compiler/src/Parser.hs
View file @
2e3f671c
...
...
@@ -62,7 +62,7 @@ importKeyword = tokenParser (matchSimpleToken ImportKeyword)
usingKeyword
=
tokenParser
(
matchSimpleToken
UsingKeyword
)
constKeyword
=
tokenParser
(
matchSimpleToken
ConstKeyword
)
enumKeyword
=
tokenParser
(
matchSimpleToken
EnumKeyword
)
classKeyword
=
tokenParser
(
matchSimpleToken
Class
Keyword
)
structKeyword
=
tokenParser
(
matchSimpleToken
Struct
Keyword
)
interfaceKeyword
=
tokenParser
(
matchSimpleToken
InterfaceKeyword
)
optionKeyword
=
tokenParser
(
matchSimpleToken
OptionKeyword
)
...
...
@@ -111,7 +111,7 @@ constantDecl = do
return
(
ConstantDecl
name
typeName
value
)
typeDecl
statements
=
enumDecl
statements
<|>
class
Decl
statements
<|>
struct
Decl
statements
<|>
interfaceDecl
statements
enumDecl
statements
=
do
...
...
@@ -135,15 +135,15 @@ enumValueLine :: Maybe [Located Statement] -> TokenParser Declaration
enumValueLine
Nothing
=
optionDecl
enumValueLine
(
Just
_
)
=
fail
"Blocks not allowed here."
class
Decl
statements
=
do
class
Keyword
struct
Decl
statements
=
do
struct
Keyword
name
<-
located
identifier
children
<-
parseBlock
class
Line
statements
return
(
Class
Decl
name
children
)
children
<-
parseBlock
struct
Line
statements
return
(
Struct
Decl
name
children
)
class
Line
::
Maybe
[
Located
Statement
]
->
TokenParser
Declaration
class
Line
Nothing
=
optionDecl
<|>
constantDecl
<|>
fieldDecl
[]
class
Line
(
Just
statements
)
=
typeDecl
statements
<|>
fieldDecl
statements
struct
Line
::
Maybe
[
Located
Statement
]
->
TokenParser
Declaration
struct
Line
Nothing
=
optionDecl
<|>
constantDecl
<|>
fieldDecl
[]
struct
Line
(
Just
statements
)
=
typeDecl
statements
<|>
fieldDecl
statements
fieldDecl
statements
=
do
name
<-
located
identifier
...
...
compiler/src/Semantics.hs
View file @
2e3f671c
...
...
@@ -38,7 +38,7 @@ data Desc = DescFile FileDesc
|
DescConstant
ConstantDesc
|
DescEnum
EnumDesc
|
DescEnumValue
EnumValueDesc
|
Desc
Class
Class
Desc
|
Desc
Struct
Struct
Desc
|
DescField
FieldDesc
|
DescInterface
InterfaceDesc
|
DescMethod
MethodDesc
...
...
@@ -51,7 +51,7 @@ descName (DescAlias d) = aliasName d
descName
(
DescConstant
d
)
=
constantName
d
descName
(
DescEnum
d
)
=
enumName
d
descName
(
DescEnumValue
d
)
=
enumValueName
d
descName
(
Desc
Class
d
)
=
class
Name
d
descName
(
Desc
Struct
d
)
=
struct
Name
d
descName
(
DescField
d
)
=
fieldName
d
descName
(
DescInterface
d
)
=
interfaceName
d
descName
(
DescMethod
d
)
=
methodName
d
...
...
@@ -64,7 +64,7 @@ descParent (DescAlias d) = aliasParent d
descParent
(
DescConstant
d
)
=
constantParent
d
descParent
(
DescEnum
d
)
=
enumParent
d
descParent
(
DescEnumValue
d
)
=
enumValueParent
d
descParent
(
Desc
Class
d
)
=
class
Parent
d
descParent
(
Desc
Struct
d
)
=
struct
Parent
d
descParent
(
DescField
d
)
=
fieldParent
d
descParent
(
DescInterface
d
)
=
interfaceParent
d
descParent
(
DescMethod
d
)
=
methodParent
d
...
...
@@ -123,7 +123,7 @@ valueString (BytesDesc s) = show (map (chr . fromIntegral) s)
data
TypeDesc
=
BuiltinType
BuiltinType
|
EnumType
EnumDesc
|
ClassType
Class
Desc
|
StructType
Struct
Desc
|
InterfaceType
InterfaceDesc
|
ListType
TypeDesc
...
...
@@ -131,7 +131,7 @@ data TypeDesc = BuiltinType BuiltinType
typeName
::
Desc
->
TypeDesc
->
String
typeName
_
(
BuiltinType
t
)
=
builtinTypeName
t
-- TODO: Check for shadowing.
typeName
scope
(
EnumType
desc
)
=
descQualifiedName
scope
(
DescEnum
desc
)
typeName
scope
(
ClassType
desc
)
=
descQualifiedName
scope
(
DescClass
desc
)
typeName
scope
(
StructType
desc
)
=
descQualifiedName
scope
(
DescStruct
desc
)
typeName
scope
(
InterfaceType
desc
)
=
descQualifiedName
scope
(
DescInterface
desc
)
typeName
scope
(
ListType
t
)
=
"List("
++
typeName
scope
t
++
")"
...
...
@@ -159,7 +159,7 @@ data FileDesc = FileDesc
,
fileAliases
::
[
AliasDesc
]
,
fileConstants
::
[
ConstantDesc
]
,
fileEnums
::
[
EnumDesc
]
,
file
Classes
::
[
Class
Desc
]
,
file
Structs
::
[
Struct
Desc
]
,
fileInterfaces
::
[
InterfaceDesc
]
,
fileOptions
::
OptionMap
,
fileMembers
::
[
Desc
]
...
...
@@ -196,18 +196,18 @@ data EnumValueDesc = EnumValueDesc
,
enumValueOptions
::
OptionMap
}
data
ClassDesc
=
Class
Desc
{
class
Name
::
String
,
class
Parent
::
Desc
,
class
Fields
::
[
FieldDesc
]
,
class
NestedAliases
::
[
AliasDesc
]
,
class
NestedConstants
::
[
ConstantDesc
]
,
class
NestedEnums
::
[
EnumDesc
]
,
classNestedClasses
::
[
Class
Desc
]
,
class
NestedInterfaces
::
[
InterfaceDesc
]
,
class
Options
::
OptionMap
,
class
Members
::
[
Desc
]
,
class
MemberMap
::
MemberMap
data
StructDesc
=
Struct
Desc
{
struct
Name
::
String
,
struct
Parent
::
Desc
,
struct
Fields
::
[
FieldDesc
]
,
struct
NestedAliases
::
[
AliasDesc
]
,
struct
NestedConstants
::
[
ConstantDesc
]
,
struct
NestedEnums
::
[
EnumDesc
]
,
structNestedStructs
::
[
Struct
Desc
]
,
struct
NestedInterfaces
::
[
InterfaceDesc
]
,
struct
Options
::
OptionMap
,
struct
Members
::
[
Desc
]
,
struct
MemberMap
::
MemberMap
}
data
FieldDesc
=
FieldDesc
...
...
@@ -226,7 +226,7 @@ data InterfaceDesc = InterfaceDesc
,
interfaceNestedAliases
::
[
AliasDesc
]
,
interfaceNestedConstants
::
[
ConstantDesc
]
,
interfaceNestedEnums
::
[
EnumDesc
]
,
interfaceNested
Classes
::
[
Class
Desc
]
,
interfaceNested
Structs
::
[
Struct
Desc
]
,
interfaceNestedInterfaces
::
[
InterfaceDesc
]
,
interfaceOptions
::
OptionMap
,
interfaceMembers
::
[
Desc
]
...
...
@@ -273,9 +273,9 @@ descToCode indent (DescEnum desc) = printf "%senum %s {\n%s%s}\n" indent
indent
descToCode
indent
(
DescEnumValue
desc
)
=
printf
"%s%s = %d;
\n
"
indent
(
enumValueName
desc
)
(
enumValueNumber
desc
)
descToCode
indent
(
Desc
Class
desc
)
=
printf
"%sclass
%s {
\n
%s%s}
\n
"
indent
(
class
Name
desc
)
(
concatMap
(
descToCode
(
" "
++
indent
))
(
class
Members
desc
))
descToCode
indent
(
Desc
Struct
desc
)
=
printf
"%sstruct
%s {
\n
%s%s}
\n
"
indent
(
struct
Name
desc
)
(
concatMap
(
descToCode
(
" "
++
indent
))
(
struct
Members
desc
))
indent
descToCode
indent
(
DescField
desc
)
=
printf
"%s%s@%d: %s%s;
\n
"
indent
(
fieldName
desc
)
(
fieldNumber
desc
)
...
...
@@ -303,7 +303,7 @@ instance Show AliasDesc where { show desc = descToCode "" (DescAlias desc) }
instance
Show
ConstantDesc
where
{
show
desc
=
descToCode
""
(
DescConstant
desc
)
}
instance
Show
EnumDesc
where
{
show
desc
=
descToCode
""
(
DescEnum
desc
)
}
instance
Show
EnumValueDesc
where
{
show
desc
=
descToCode
""
(
DescEnumValue
desc
)
}
instance
Show
ClassDesc
where
{
show
desc
=
descToCode
""
(
DescClass
desc
)
}
instance
Show
StructDesc
where
{
show
desc
=
descToCode
""
(
DescStruct
desc
)
}
instance
Show
FieldDesc
where
{
show
desc
=
descToCode
""
(
DescField
desc
)
}
instance
Show
InterfaceDesc
where
{
show
desc
=
descToCode
""
(
DescInterface
desc
)
}
instance
Show
MethodDesc
where
{
show
desc
=
descToCode
""
(
DescMethod
desc
)
}
compiler/src/Token.hs
View file @
2e3f671c
...
...
@@ -45,7 +45,7 @@ data Token = Identifier String
|
UsingKeyword
|
ConstKeyword
|
EnumKeyword
|
Class
Keyword
|
Struct
Keyword
|
InterfaceKeyword
|
OptionKeyword
deriving
(
Show
,
Eq
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment