Skip to content

Commit

Permalink
fix: include stdlib sub path bug
Browse files Browse the repository at this point in the history
  • Loading branch information
joetifa2003 committed Apr 5, 2022
1 parent 5dbc01f commit b09b61e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,12 @@ let greeter = fn() {

```swift
// main.wind
include "test.wind";
include "./test.wind";

greeter(); // Hello 👋

// You can also alias includes
include "test.wind" as test;
include "./test.wind" as test;

test.greeter(); // Hello 👋
```
Expand Down
2 changes: 1 addition & 1 deletion evaluator/stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package evaluator

func GetStdlib(filePath string) (*Environment, bool) {
switch filePath {
case "stdlib\\strings.go":
case "stdlib/strings":
return StdlibStrings(), true
}

Expand Down
7 changes: 6 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/joetifa2003/windlang/ast"
"github.com/joetifa2003/windlang/lexer"
Expand Down Expand Up @@ -255,7 +256,11 @@ func (p *Parser) parseIncludeStatement() *ast.IncludeStatement {

p.nextToken()

stmt.Path = filepath.Join(filepath.Dir(p.filePath), p.curToken.Literal)
if strings.Contains(p.curToken.Literal, "./") || strings.Contains(p.curToken.Literal, "./") {
stmt.Path = filepath.Join(filepath.Dir(p.filePath), p.curToken.Literal)
} else {
stmt.Path = p.curToken.Literal
}

p.nextToken()

Expand Down

0 comments on commit b09b61e

Please sign in to comment.