Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
djinni
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
djinni
Commits
18b37727
Commit
18b37727
authored
Jul 13, 2015
by
Miro Knejp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Distinguish between @import and @extern in IDL files
parent
4c062e36
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
8 deletions
+25
-8
src/source/ast.scala
src/source/ast.scala
+7
-1
src/source/parser.scala
src/source/parser.scala
+18
-7
No files found.
src/source/ast.scala
View file @
18b37727
...
@@ -21,7 +21,13 @@ import djinni.ast.Record.DerivingType.DerivingType
...
@@ -21,7 +21,13 @@ import djinni.ast.Record.DerivingType.DerivingType
import
djinni.meta.MExpr
import
djinni.meta.MExpr
import
djinni.syntax.Loc
import
djinni.syntax.Loc
case
class
IdlFile
(
imports
:
Seq
[
File
],
typeDecls
:
Seq
[
TypeDecl
])
case
class
IdlFile
(
imports
:
Seq
[
FileRef
],
typeDecls
:
Seq
[
TypeDecl
])
abstract
sealed
class
FileRef
{
val
file
:
File
}
case
class
IdlFileRef
(
override
val
file
:
File
)
extends
FileRef
case
class
ExternFileRef
(
override
val
file
:
File
)
extends
FileRef
case
class
Ident
(
name
:
String
,
file
:
File
,
loc
:
Loc
)
case
class
Ident
(
name
:
String
,
file
:
File
,
loc
:
Loc
)
class
ConstRef
(
ident
:
Ident
)
extends
Ident
(
ident
.
name
,
ident
.
file
,
ident
.
loc
)
class
ConstRef
(
ident
:
Ident
)
extends
Ident
(
ident
.
name
,
ident
.
file
,
ident
.
loc
)
...
...
src/source/parser.scala
View file @
18b37727
...
@@ -36,14 +36,20 @@ private object IdlParser extends RegexParsers {
...
@@ -36,14 +36,20 @@ private object IdlParser extends RegexParsers {
def
idlFile
(
origin
:
String
)
:
Parser
[
IdlFile
]
=
rep
(
importFile
)
~
rep
(
typeDecl
(
origin
))
^^
{
case
imp
~
types
=>
IdlFile
(
imp
,
types
)
}
def
idlFile
(
origin
:
String
)
:
Parser
[
IdlFile
]
=
rep
(
importFile
)
~
rep
(
typeDecl
(
origin
))
^^
{
case
imp
~
types
=>
IdlFile
(
imp
,
types
)
}
def
importFile
:
Parser
[
File
]
=
"@import \""
~>
filePath
<~
"\""
^^
{
def
importFile
:
Parser
[
File
Ref
]
=
(
"@"
~>
directive
)
~
(
"\""
~>
filePath
<~
"\""
)
^^
{
x
=>
{
case
"import"
~
x
=>
val
newPath
=
fileStack
.
top
.
getParent
()
+
"/"
+
x
val
newPath
=
fileStack
.
top
.
getParent
()
+
"/"
+
x
new
File
(
newPath
)
new
IdlFileRef
(
new
File
(
newPath
))
}
case
"extern"
~
x
=>
val
newPath
=
fileStack
.
top
.
getParent
()
+
"/"
+
x
new
ExternFileRef
(
new
File
(
newPath
))
}
}
def
filePath
=
"[^\"]*"
.
r
def
filePath
=
"[^\"]*"
.
r
def
directive
=
importDirective
|
externDirective
def
importDirective
=
"import"
.
r
def
externDirective
=
"extern"
.
r
def
typeDecl
(
origin
:
String
)
:
Parser
[
TypeDecl
]
=
doc
~
ident
~
typeList
(
ident
^^
TypeParam
)
~
"="
~
typeDef
^^
{
def
typeDecl
(
origin
:
String
)
:
Parser
[
TypeDecl
]
=
doc
~
ident
~
typeList
(
ident
^^
TypeParam
)
~
"="
~
typeDef
^^
{
case
doc
~
ident
~
typeParams
~
_
~
body
=>
TypeDecl
(
ident
,
typeParams
,
body
,
doc
,
origin
)
case
doc
~
ident
~
typeParams
~
_
~
body
=>
TypeDecl
(
ident
,
typeParams
,
body
,
doc
,
origin
)
}
}
...
@@ -222,11 +228,16 @@ def parseFile(idlFile: File, inFileListWriter: Option[Writer]): Seq[TypeDecl] =
...
@@ -222,11 +228,16 @@ def parseFile(idlFile: File, inFileListWriter: Option[Writer]): Seq[TypeDecl] =
case
Right
(
idl
)
=>
{
case
Right
(
idl
)
=>
{
var
types
=
idl
.
typeDecls
var
types
=
idl
.
typeDecls
idl
.
imports
.
foreach
(
x
=>
{
idl
.
imports
.
foreach
(
x
=>
{
if
(
fileStack
.
contains
(
x
))
{
if
(
fileStack
.
contains
(
x
.
file
))
{
throw
new
AssertionError
(
"Circular import detected!"
)
throw
new
AssertionError
(
"Circular import detected!"
)
}
}
if
(!
visitedFiles
.
contains
(
x
))
{
if
(!
visitedFiles
.
contains
(
x
.
file
))
{
types
=
parseFile
(
x
,
inFileListWriter
)
++
types
x
match
{
case
IdlFileRef
(
file
)
=>
types
=
parseFile
(
file
,
inFileListWriter
)
++
types
case
ExternFileRef
(
file
)
=>
types
}
}
}
})
})
types
types
...
...
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