2020-11-10 21:37:30 +00:00
|
|
|
/*
|
|
|
|
Serene --- Yet an other Lisp
|
|
|
|
|
|
|
|
Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2020-11-14 10:51:25 +00:00
|
|
|
// Package ast provides the functionality and data structures around the
|
|
|
|
// Serene's AST.
|
|
|
|
package ast
|
2020-11-10 21:37:30 +00:00
|
|
|
|
2020-11-14 10:51:25 +00:00
|
|
|
type NodeType int
|
|
|
|
|
|
|
|
const (
|
|
|
|
Nil NodeType = iota
|
2020-11-19 22:17:50 +00:00
|
|
|
Nothing
|
2020-11-24 18:27:48 +00:00
|
|
|
True
|
|
|
|
False
|
2020-11-14 10:51:25 +00:00
|
|
|
Symbol
|
2020-11-14 12:22:13 +00:00
|
|
|
Number
|
2020-11-14 10:51:25 +00:00
|
|
|
List
|
2020-11-19 19:14:06 +00:00
|
|
|
Fn
|
2020-11-19 22:17:50 +00:00
|
|
|
Block // Dont' mistake it with block from other programming languages
|
2020-11-14 10:51:25 +00:00
|
|
|
)
|
|
|
|
|
2020-11-23 12:30:02 +00:00
|
|
|
type Location struct {
|
|
|
|
start int
|
|
|
|
end int
|
|
|
|
source *[]string
|
|
|
|
knownLocation bool
|
|
|
|
}
|
|
|
|
|
2020-11-25 19:19:48 +00:00
|
|
|
func (l *Location) GetStart() int {
|
|
|
|
return l.start
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Location) GetEnd() int {
|
|
|
|
return l.end
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Location) GetSource() *[]string {
|
|
|
|
return l.source
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Location) IsKnownLocaiton() bool {
|
|
|
|
return l.knownLocation
|
|
|
|
}
|
|
|
|
|
2020-11-14 10:51:25 +00:00
|
|
|
type ILocatable interface {
|
2020-11-23 12:30:02 +00:00
|
|
|
GetLocation() Location
|
|
|
|
}
|
|
|
|
|
|
|
|
func MakeLocation(input *[]string, start int, end int) Location {
|
|
|
|
return Location{
|
|
|
|
source: input,
|
|
|
|
start: start,
|
|
|
|
end: end,
|
|
|
|
knownLocation: true,
|
|
|
|
}
|
2020-11-14 10:51:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ITypable interface {
|
|
|
|
GetType() NodeType
|
2020-11-10 21:37:30 +00:00
|
|
|
}
|
2020-11-23 12:30:02 +00:00
|
|
|
|
|
|
|
func MakeUnknownLocation() Location {
|
|
|
|
return Location{
|
|
|
|
knownLocation: false,
|
|
|
|
}
|
|
|
|
}
|