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
4d121574
Commit
4d121574
authored
Apr 19, 2013
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement annotations.
parent
7a7e0b64
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
44 deletions
+84
-44
Compiler.hs
compiler/src/Compiler.hs
+0
-0
Grammar.hs
compiler/src/Grammar.hs
+69
-33
Lexer.hs
compiler/src/Lexer.hs
+12
-10
Parser.hs
compiler/src/Parser.hs
+0
-0
Semantics.hs
compiler/src/Semantics.hs
+0
-0
Token.hs
compiler/src/Token.hs
+3
-1
No files found.
compiler/src/Compiler.hs
View file @
4d121574
This diff is collapsed.
Click to expand it.
compiler/src/Grammar.hs
View file @
4d121574
...
...
@@ -45,6 +45,10 @@ typeImports :: TypeExpression -> [Located String]
typeImports
(
TypeExpression
name
params
)
=
maybeToList
(
declNameImport
name
)
++
concatMap
typeImports
params
data
Annotation
=
Annotation
DeclName
(
Located
FieldValue
)
deriving
(
Show
)
annotationImports
(
Annotation
name
_
)
=
maybeToList
$
declNameImport
name
data
FieldValue
=
VoidFieldValue
|
BoolFieldValue
Bool
|
IntegerFieldValue
Integer
...
...
@@ -56,43 +60,75 @@ data FieldValue = VoidFieldValue
|
UnionFieldValue
String
FieldValue
deriving
(
Show
)
data
ParamDecl
=
ParamDecl
String
TypeExpression
[
Annotation
]
(
Maybe
(
Located
FieldValue
))
deriving
(
Show
)
paramImports
(
ParamDecl
_
t
ann
_
)
=
typeImports
t
++
concatMap
annotationImports
ann
data
AnnotationTarget
=
FileAnnotation
|
ConstantAnnotation
|
EnumAnnotation
|
EnumValueAnnotation
|
StructAnnotation
|
FieldAnnotation
|
UnionAnnotation
|
InterfaceAnnotation
|
MethodAnnotation
|
ParamAnnotation
|
AnnotationAnnotation
deriving
(
Eq
,
Ord
,
Bounded
,
Enum
)
instance
Show
AnnotationTarget
where
show
FileAnnotation
=
"file"
show
ConstantAnnotation
=
"const"
show
EnumAnnotation
=
"enum"
show
EnumValueAnnotation
=
"enumerant"
show
StructAnnotation
=
"struct"
show
FieldAnnotation
=
"field"
show
UnionAnnotation
=
"union"
show
InterfaceAnnotation
=
"interface"
show
MethodAnnotation
=
"method"
show
ParamAnnotation
=
"param"
show
AnnotationAnnotation
=
"annotation"
data
Declaration
=
AliasDecl
(
Located
String
)
DeclName
|
ConstantDecl
(
Located
String
)
TypeExpression
(
Located
FieldValue
)
|
EnumDecl
(
Located
String
)
[
Declaration
]
|
EnumValueDecl
(
Located
String
)
(
Located
Integer
)
[
Declar
ation
]
|
StructDecl
(
Located
String
)
[
Declaration
]
|
ConstantDecl
(
Located
String
)
TypeExpression
[
Annotation
]
(
Located
FieldValue
)
|
EnumDecl
(
Located
String
)
[
Annotation
]
[
Declaration
]
|
EnumValueDecl
(
Located
String
)
(
Located
Integer
)
[
Annot
ation
]
|
StructDecl
(
Located
String
)
[
Annotation
]
[
Declaration
]
|
FieldDecl
(
Located
String
)
(
Located
Integer
)
TypeExpression
(
Maybe
(
Located
FieldValue
))
|
UnionDecl
(
Located
String
)
(
Located
Integer
)
[
Declaration
]
|
InterfaceDecl
(
Located
String
)
[
Declaration
]
|
MethodDecl
(
Located
String
)
(
Located
Integer
)
[(
String
,
TypeExpression
,
Maybe
(
Located
FieldValue
))]
TypeExpression
[
Declaration
]
|
OptionDecl
DeclName
(
Located
FieldValue
)
TypeExpression
[
Annotation
]
(
Maybe
(
Located
FieldValue
))
|
UnionDecl
(
Located
String
)
(
Located
Integer
)
[
Annotation
]
[
Declaration
]
|
InterfaceDecl
(
Located
String
)
[
Annotation
]
[
Declaration
]
|
MethodDecl
(
Located
String
)
(
Located
Integer
)
[
ParamDecl
]
TypeExpression
[
Annotation
]
|
AnnotationDecl
(
Located
String
)
TypeExpression
[
Annotation
]
[
AnnotationTarget
]
deriving
(
Show
)
declarationName
::
Declaration
->
Maybe
(
Located
String
)
declarationName
(
AliasDecl
n
_
)
=
Just
n
declarationName
(
ConstantDecl
n
_
_
)
=
Just
n
declarationName
(
EnumDecl
n
_
)
=
Just
n
declarationName
(
EnumValueDecl
n
_
_
)
=
Just
n
declarationName
(
StructDecl
n
_
)
=
Just
n
declarationName
(
FieldDecl
n
_
_
_
)
=
Just
n
declarationName
(
UnionDecl
n
_
_
)
=
Just
n
declarationName
(
InterfaceDecl
n
_
)
=
Just
n
declarationName
(
MethodDecl
n
_
_
_
_
)
=
Just
n
declarationName
(
OptionDecl
_
_
)
=
Nothing
declarationName
(
AliasDecl
n
_
)
=
Just
n
declarationName
(
ConstantDecl
n
_
_
_
)
=
Just
n
declarationName
(
EnumDecl
n
_
_
)
=
Just
n
declarationName
(
EnumValueDecl
n
_
_
)
=
Just
n
declarationName
(
StructDecl
n
_
_
)
=
Just
n
declarationName
(
FieldDecl
n
_
_
_
_
)
=
Just
n
declarationName
(
UnionDecl
n
_
_
_
)
=
Just
n
declarationName
(
InterfaceDecl
n
_
_
)
=
Just
n
declarationName
(
MethodDecl
n
_
_
_
_
)
=
Just
n
declarationName
(
AnnotationDecl
n
_
_
_
)
=
Just
n
declImports
::
Declaration
->
[
Located
String
]
declImports
(
AliasDecl
_
name
)
=
maybeToList
$
declNameImport
name
declImports
(
ConstantDecl
_
t
_
)
=
typeImports
t
declImports
(
EnumDecl
_
decls
)
=
concatMap
declImports
decls
declImports
(
EnumValueDecl
_
_
decls
)
=
concatMap
declImports
decls
declImports
(
StructDecl
_
decls
)
=
concatMap
declImports
decls
declImports
(
FieldDecl
_
_
t
_
)
=
typeImports
t
declImports
(
UnionDecl
_
_
decls
)
=
concatMap
declImports
decls
declImports
(
InterfaceDecl
_
decls
)
=
concatMap
declImports
decls
declImports
(
MethodDecl
_
_
params
t
decls
)
=
concat
[
paramsImports
,
typeImports
t
,
concatMap
declImports
decls
]
where
paramsImports
=
concat
[
typeImports
pt
|
(
_
,
pt
,
_
)
<-
params
]
declImports
(
OptionDecl
name
_
)
=
maybeToList
$
declNameImport
name
declImports
(
AliasDecl
_
name
)
=
maybeToList
(
declNameImport
name
)
declImports
(
ConstantDecl
_
t
ann
_
)
=
typeImports
t
++
concatMap
annotationImports
ann
declImports
(
EnumDecl
_
ann
decls
)
=
concatMap
annotationImports
ann
++
concatMap
declImports
decls
declImports
(
EnumValueDecl
_
_
ann
)
=
concatMap
annotationImports
ann
declImports
(
StructDecl
_
ann
decls
)
=
concatMap
annotationImports
ann
++
concatMap
declImports
decls
declImports
(
FieldDecl
_
_
t
ann
_
)
=
typeImports
t
++
concatMap
annotationImports
ann
declImports
(
UnionDecl
_
_
ann
decls
)
=
concatMap
annotationImports
ann
++
concatMap
declImports
decls
declImports
(
InterfaceDecl
_
ann
decls
)
=
concatMap
annotationImports
ann
++
concatMap
declImports
decls
declImports
(
MethodDecl
_
_
params
t
ann
)
=
concat
[
concatMap
paramImports
params
,
typeImports
t
,
concatMap
annotationImports
ann
]
declImports
(
AnnotationDecl
_
t
ann
_
)
=
typeImports
t
++
concatMap
annotationImports
ann
compiler/src/Lexer.hs
View file @
4d121574
...
...
@@ -48,7 +48,7 @@ keywords =
,
(
StructKeyword
,
"struct"
)
,
(
UnionKeyword
,
"union"
)
,
(
InterfaceKeyword
,
"interface"
)
,
(
OptionKeyword
,
"op
tion"
)
,
(
AnnotationKeyword
,
"annota
tion"
)
]
languageDef
::
T
.
LanguageDef
st
...
...
@@ -114,15 +114,17 @@ tokenSequence = do
token
::
Parser
Token
token
=
keyword
<|>
identifier
<|>
liftM
ParenthesizedList
(
parens
(
sepBy
tokenSequence
(
symbol
","
)))
<|>
liftM
BracketedList
(
brackets
(
sepBy
tokenSequence
(
symbol
","
)))
<|>
liftM
toLiteral
naturalOrFloat
<|>
liftM
LiteralString
stringLiteral
<|>
liftM
(
const
AtSign
)
(
symbol
"@"
)
<|>
liftM
(
const
Colon
)
(
symbol
":"
)
<|>
liftM
(
const
Period
)
(
symbol
"."
)
<|>
liftM
(
const
EqualsSign
)
(
symbol
"="
)
<|>
liftM
(
const
MinusSign
)
(
symbol
"-"
)
<|>
liftM
ParenthesizedList
(
parens
(
sepBy
tokenSequence
(
symbol
","
)))
<|>
liftM
BracketedList
(
brackets
(
sepBy
tokenSequence
(
symbol
","
)))
<|>
liftM
toLiteral
naturalOrFloat
<|>
liftM
LiteralString
stringLiteral
<|>
liftM
(
const
AtSign
)
(
symbol
"@"
)
<|>
liftM
(
const
Colon
)
(
symbol
":"
)
<|>
liftM
(
const
DollarSign
)
(
symbol
"$"
)
<|>
liftM
(
const
Period
)
(
symbol
"."
)
<|>
liftM
(
const
EqualsSign
)
(
symbol
"="
)
<|>
liftM
(
const
MinusSign
)
(
symbol
"-"
)
<|>
liftM
(
const
Asterisk
)
(
symbol
"*"
)
<|>
liftM
(
const
ExclamationPoint
)
(
symbol
"!"
)
<?>
"token"
...
...
compiler/src/Parser.hs
View file @
4d121574
This diff is collapsed.
Click to expand it.
compiler/src/Semantics.hs
View file @
4d121574
This diff is collapsed.
Click to expand it.
compiler/src/Token.hs
View file @
4d121574
...
...
@@ -54,9 +54,11 @@ data Token = Identifier String
|
FalseKeyword
|
AtSign
|
Colon
|
DollarSign
|
Period
|
EqualsSign
|
MinusSign
|
Asterisk
|
ExclamationPoint
|
InKeyword
|
OfKeyword
-- We reserve some common, short English words for use as future keywords.
...
...
@@ -71,7 +73,7 @@ data Token = Identifier String
|
StructKeyword
|
UnionKeyword
|
InterfaceKeyword
|
Op
tionKeyword
|
Annota
tionKeyword
deriving
(
Data
,
Typeable
,
Show
,
Eq
)
data
Statement
=
Line
TokenSequence
...
...
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