implement-modules #43
@ -201,3 +201,23 @@ testString (test,
|
||||
[hello out:io::Writer] = ioutil::[writeString out 'hello']
|
||||
`)
|
||||
}
|
||||
|
||||
func TestSkim (test *testing.T) {
|
||||
testStringSkim (test,
|
||||
// correct
|
||||
`+ X:Int
|
||||
+ X.[pub]:Int
|
||||
+ X.[alreadyExternal]
|
||||
+ [alreadyExternal]
|
||||
+ [pub]:X`,
|
||||
// input
|
||||
`
|
||||
+ X:Int
|
||||
+ X.[pub]:Int = 5
|
||||
- X.[priv]:Int = 2
|
||||
+ X.[alreadyExternal]
|
||||
+ [alreadyExternal]
|
||||
[priv]
|
||||
+ [pub]:X = x:X
|
||||
`)
|
||||
}
|
||||
|
@ -8,13 +8,26 @@ import "git.tebibyte.media/sashakoshka/fspl/errors"
|
||||
import "git.tebibyte.media/sashakoshka/fspl/testcommon"
|
||||
|
||||
func testString (test *testing.T, correct string, input string) {
|
||||
testStringInternal(test, correct, input, false)
|
||||
}
|
||||
|
||||
func testStringSkim (test *testing.T, correct string, input string) {
|
||||
testStringInternal(test, correct, input, true)
|
||||
}
|
||||
|
||||
func testStringInternal (test *testing.T, correct string, input string, skim bool) {
|
||||
ast := Tree { }
|
||||
lx, err := lexer.LexReader("input.fspl", strings.NewReader(input))
|
||||
if err != nil && err != io.EOF{
|
||||
test.Error("lexer returned error:\n" + errors.Format(err))
|
||||
return
|
||||
}
|
||||
err = ast.Parse(lx)
|
||||
|
||||
if skim {
|
||||
err = ast.Skim(lx)
|
||||
} else {
|
||||
err = ast.Parse(lx)
|
||||
}
|
||||
if err != nil && err != io.EOF{
|
||||
test.Error("parser returned error:\n" + errors.Format(err))
|
||||
return
|
||||
|
@ -24,13 +24,15 @@ func (this *Tree) String () string {
|
||||
// Parse parses the output of the given lexer into the tree.
|
||||
func (this *Tree) Parse (lx lexer.Lexer) error {
|
||||
parser, err := newParser(lx)
|
||||
parser.skim = false
|
||||
if err != nil { return err }
|
||||
return parser.parseInto(this)
|
||||
}
|
||||
|
||||
// ParseDependency is like Parse, but does not keep code within functions and
|
||||
// methods, instead marking them as external.
|
||||
func (this *Tree) ParseDependency (lx lexer.Lexer) error {
|
||||
// Skim is like Parse, but does not keep code within functions and methods,
|
||||
// instead marking them as external. It also drops private functions and
|
||||
// methods.
|
||||
func (this *Tree) Skim (lx lexer.Lexer) error {
|
||||
parser, err := newParser(lx)
|
||||
parser.skim = true
|
||||
if err != nil { return err }
|
||||
|
Loading…
Reference in New Issue
Block a user