Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-ref2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
5
Issues
5
List
Board
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mu
mu-impl-ref2
Commits
28426491
Commit
28426491
authored
Nov 09, 2015
by
Kunshan Wang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP: HAIL parser.
parent
9551ff05
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
405 additions
and
55 deletions
+405
-55
UIRTextReader.scala
src/main/scala/uvm/ir/textinput/UIRTextReader.scala
+28
-53
exceptions.scala
src/main/scala/uvm/refimpl/exceptions.scala
+3
-0
HailScriptLoader.scala
src/main/scala/uvm/refimpl/hail/HailScriptLoader.scala
+336
-2
AntlrHelpers.scala
src/main/scala/uvm/utils/AntlrHelpers.scala
+38
-0
No files found.
src/main/scala/uvm/ir/textinput/UIRTextReader.scala
View file @
28426491
...
...
@@ -13,6 +13,7 @@ import scala.collection.mutable.ArrayBuffer
import
scala.collection.immutable.Stream
import
java.io.StringWriter
import
java.nio.CharBuffer
import
uvm.utils.AntlrHelpers._
class
UIRTextReader
(
val
idFactory
:
IDFactory
)
{
import
UIRTextReader._
...
...
@@ -40,23 +41,6 @@ class UIRTextReader(val idFactory: IDFactory) {
read
(
sb
.
toString
(),
globalBundle
)
}
class
AccumulativeAntlrErrorListener
(
source
:
String
)
extends
BaseErrorListener
{
val
buf
=
new
ArrayBuffer
[
String
]()
var
hasError
=
false
lazy
val
sourceLines
=
ArrayBuffer
(
source
.
lines
.
toSeq
:
_
*
)
override
def
syntaxError
(
recognizer
:
Recognizer
[
_
,
_
],
offendingSymbol
:
Object
,
line
:
Int
,
charPositionInLine
:
Int
,
msg
:
String
,
e
:
RecognitionException
)
:
Unit
=
{
val
theLine
=
sourceLines
(
line
-
1
)
val
marker
=
" "
*
charPositionInLine
+
"^"
buf
.
add
(
"line %d:%d %s\n%s\n%s"
.
format
(
line
,
charPositionInLine
,
msg
,
theLine
,
marker
))
hasError
=
true
}
def
getMessages
()
:
String
=
buf
.
mkString
(
"\n"
)
}
def
read
(
source
:
String
,
ais
:
ANTLRInputStream
,
globalBundle
:
GlobalBundle
)
:
TrantientBundle
=
{
val
ea
=
new
AccumulativeAntlrErrorListener
(
source
)
...
...
@@ -128,15 +112,6 @@ class UIRTextReader(val idFactory: IDFactory) {
// Printing context information (line, column, near some token)
def
inCtx
(
ctx
:
ParserRuleContext
,
s
:
String
)
:
String
=
nearTok
(
ctx
.
getStart
,
s
)
def
inCtx
(
ctx
:
TerminalNode
,
s
:
String
)
:
String
=
nearTok
(
ctx
.
getSymbol
,
s
)
def
nearTok
(
tok
:
Token
,
s
:
String
)
:
String
=
{
val
line
=
tok
.
getLine
()
val
column
=
tok
.
getCharPositionInLine
()
val
near
=
tok
.
getText
()
return
"At %d:%d near '%s': %s"
.
format
(
line
,
column
,
near
,
s
)
}
def
catchIn
[
T
](
ctx
:
ParserRuleContext
,
s
:
String
)(
func
:
=>
T
)
:
T
=
try
{
func
...
...
src/main/scala/uvm/refimpl/exceptions.scala
View file @
28426491
...
...
@@ -23,3 +23,6 @@ class UvmDivisionByZeroException(message: String = null, cause: Throwable = null
/** Thrown when accessing Mu memory but the address is outside the allocated region. */
class
UvmIllegalMemoryAccessException
(
message
:
String
=
null
,
cause
:
Throwable
=
null
)
extends
UvmRuntimeException
(
message
,
cause
)
/** Thrown on syntax errors in HAIL scripts. */
class
UvmHailParsingException
(
message
:
String
=
null
,
cause
:
Throwable
=
null
)
extends
UvmRefImplException
(
message
,
cause
)
src/main/scala/uvm/refimpl/hail/HailScriptLoader.scala
View file @
28426491
This diff is collapsed.
Click to expand it.
src/main/scala/uvm/utils/AntlrHelpers.scala
0 → 100644
View file @
28426491
package
uvm.utils
import
org.antlr.v4.runtime.RecognitionException
import
scala.collection.mutable.ArrayBuffer
import
org.antlr.v4.runtime.Recognizer
import
org.antlr.v4.runtime.BaseErrorListener
import
org.antlr.v4.runtime.tree.TerminalNode
import
org.antlr.v4.runtime.ParserRuleContext
import
org.antlr.v4.runtime.Token
object
AntlrHelpers
{
class
AccumulativeAntlrErrorListener
(
source
:
String
)
extends
BaseErrorListener
{
val
buf
=
new
ArrayBuffer
[
String
]()
var
hasError
=
false
lazy
val
sourceLines
=
ArrayBuffer
(
source
.
lines
.
toSeq
:
_
*
)
override
def
syntaxError
(
recognizer
:
Recognizer
[
_
,
_
],
offendingSymbol
:
Object
,
line
:
Int
,
charPositionInLine
:
Int
,
msg
:
String
,
e
:
RecognitionException
)
:
Unit
=
{
val
theLine
=
sourceLines
(
line
-
1
)
val
marker
=
" "
*
charPositionInLine
+
"^"
buf
+=
"line %d:%d %s\n%s\n%s"
.
format
(
line
,
charPositionInLine
,
msg
,
theLine
,
marker
)
hasError
=
true
}
def
getMessages
()
:
String
=
buf
.
mkString
(
"\n"
)
}
def
inCtx
(
ctx
:
ParserRuleContext
,
s
:
String
)
:
String
=
nearTok
(
ctx
.
getStart
,
s
)
def
inCtx
(
ctx
:
TerminalNode
,
s
:
String
)
:
String
=
nearTok
(
ctx
.
getSymbol
,
s
)
def
nearTok
(
tok
:
Token
,
s
:
String
)
:
String
=
{
val
line
=
tok
.
getLine
()
val
column
=
tok
.
getCharPositionInLine
()
val
near
=
tok
.
getText
()
return
"At %d:%d near '%s': %s"
.
format
(
line
,
column
,
near
,
s
)
}
}
\ No newline at end of file
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