Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
eeddc8e7
Commit
eeddc8e7
authored
Mar 26, 2009
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- adjustments to match new token/scanner/ast
R=r OCL=26794 CL=26794
parent
5a72ca45
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
278 additions
and
243 deletions
+278
-243
usr/gri/pretty/compilation.go
usr/gri/pretty/compilation.go
+15
-13
usr/gri/pretty/gds.go
usr/gri/pretty/gds.go
+6
-6
usr/gri/pretty/parser.go
usr/gri/pretty/parser.go
+173
-140
usr/gri/pretty/printer.go
usr/gri/pretty/printer.go
+82
-82
usr/gri/pretty/typechecker.go
usr/gri/pretty/typechecker.go
+2
-2
No files found.
usr/gri/pretty/compilation.go
View file @
eeddc8e7
...
...
@@ -11,8 +11,9 @@ import (
"os"
;
"utils"
;
"platform"
;
"token"
;
"scanner"
;
Parser
"parser"
;
"parser"
;
"ast"
;
"typechecker"
;
"sort"
;
...
...
@@ -34,7 +35,7 @@ type Flags struct {
type
Error
struct
{
Loc
scanner
.
Loca
tion
;
Pos
token
.
Posi
tion
;
Msg
string
;
}
...
...
@@ -42,7 +43,7 @@ type Error struct {
type
ErrorList
[]
Error
func
(
list
ErrorList
)
Len
()
int
{
return
len
(
list
);
}
func
(
list
ErrorList
)
Less
(
i
,
j
int
)
bool
{
return
list
[
i
]
.
Loc
.
Pos
<
list
[
j
]
.
Loc
.
Pos
;
}
func
(
list
ErrorList
)
Less
(
i
,
j
int
)
bool
{
return
list
[
i
]
.
Pos
.
Offset
<
list
[
j
]
.
Pos
.
Offset
;
}
func
(
list
ErrorList
)
Swap
(
i
,
j
int
)
{
list
[
i
],
list
[
j
]
=
list
[
j
],
list
[
i
];
}
...
...
@@ -63,23 +64,23 @@ func (h *errorHandler) Init(filename string, src []byte, columns bool) {
}
func
(
h
*
errorHandler
)
Error
(
loc
scanner
.
Loca
tion
,
msg
string
)
{
func
(
h
*
errorHandler
)
Error
(
pos
token
.
Posi
tion
,
msg
string
)
{
// only report errors that are on a new line
// in the hope to avoid most follow-up errors
if
loc
.
Line
==
h
.
errline
{
if
pos
.
Line
==
h
.
errline
{
return
;
}
// report error
fmt
.
Printf
(
"%s:%d:"
,
h
.
filename
,
loc
.
Line
);
fmt
.
Printf
(
"%s:%d:"
,
h
.
filename
,
pos
.
Line
);
if
h
.
columns
{
fmt
.
Printf
(
"%d:"
,
loc
.
Col
);
fmt
.
Printf
(
"%d:"
,
pos
.
Column
);
}
fmt
.
Printf
(
" %s
\n
"
,
msg
);
// collect the error
h
.
errors
.
Push
(
Error
{
loc
,
msg
});
h
.
errline
=
loc
.
Line
;
h
.
errors
.
Push
(
Error
{
pos
,
msg
});
h
.
errline
=
pos
.
Line
;
}
...
...
@@ -96,10 +97,11 @@ func Compile(src_file string, flags *Flags) (*ast.Package, ErrorList) {
var
scanner
scanner
.
Scanner
;
scanner
.
Init
(
src
,
&
err
,
true
);
var
parser
Parser
.
Parser
;
parser
.
Init
(
&
scanner
,
&
err
,
flags
.
Verbose
);
prog
:=
parser
.
Parse
(
Parser
.
ParseEntirePackage
);
pflags
:=
uint
(
0
);
if
flags
.
Verbose
{
pflags
|=
parser
.
Trace
;
}
prog
:=
parser
.
Parse
(
&
scanner
,
&
err
,
parser
.
ParseEntirePackage
,
pflags
);
if
err
.
errors
.
Len
()
==
0
{
TypeChecker
.
CheckProgram
(
&
err
,
prog
);
...
...
usr/gri/pretty/gds.go
View file @
eeddc8e7
...
...
@@ -124,20 +124,20 @@ func printErrors(c *http.Conn, filename string, errors Compilation.ErrorList) {
fmt
.
Fprintf
(
c
,
"could not read file %s
\n
"
,
*
root
+
filename
);
return
;
}
po
s
:=
0
;
off
s
:=
0
;
for
i
,
e
:=
range
errors
{
if
0
<=
e
.
Loc
.
Pos
&&
e
.
Loc
.
Pos
<=
len
(
src
)
{
if
0
<=
e
.
Pos
.
Offset
&&
e
.
Pos
.
Offset
<=
len
(
src
)
{
// TODO handle Write errors
c
.
Write
(
src
[
pos
:
e
.
Loc
.
Pos
]);
c
.
Write
(
src
[
offs
:
e
.
Pos
.
Offset
]);
// TODO this should be done using a .css file
fmt
.
Fprintf
(
c
,
"<b><font color=red>%s >>></font></b>"
,
e
.
Msg
);
pos
=
e
.
Loc
.
Pos
;
offs
=
e
.
Pos
.
Offset
;
}
else
{
log
.
Stdoutf
(
"error position %d out of bounds (len = %d)"
,
e
.
Loc
.
Pos
,
len
(
src
));
log
.
Stdoutf
(
"error position %d out of bounds (len = %d)"
,
e
.
Pos
.
Offset
,
len
(
src
));
}
}
// TODO handle Write errors
c
.
Write
(
src
[
po
s
:
len
(
src
)]);
c
.
Write
(
src
[
off
s
:
len
(
src
)]);
}
});
}
...
...
usr/gri/pretty/parser.go
View file @
eeddc8e7
This diff is collapsed.
Click to expand it.
usr/gri/pretty/printer.go
View file @
eeddc8e7
This diff is collapsed.
Click to expand it.
usr/gri/pretty/typechecker.go
View file @
eeddc8e7
...
...
@@ -42,8 +42,8 @@ func assert(pred bool) {
}
func
(
s
*
state
)
Error
(
loc
scanner
.
Loca
tion
,
msg
string
)
{
s
.
err
.
Error
(
loc
,
msg
);
func
(
s
*
state
)
Error
(
pos
token
.
Posi
tion
,
msg
string
)
{
s
.
err
.
Error
(
pos
,
msg
);
}
...
...
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