Skip to content

Commit

Permalink
support ./{ } syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
StunxFS committed Dec 27, 2023
1 parent 9a4f69f commit a592a03
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 1 addition & 2 deletions lib/rivet/src/ast/comptime.ri
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

import std/sys;

import ../token;
import ../report;
import ../{ token, report };

pub struct ComptimeIf {
mut branches: []mut ComptimeIfBranch;
Expand Down
11 changes: 9 additions & 2 deletions lib/rivet/src/parser/import.ri
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,20 @@ extend Parser {
mut sb := strings.Builder.new();
if self.accept(.Dot) {
sb.write_string("./");
self.expect(.Div);
if self.peek_tok.kind != .Lbrace {
self.expect(.Div);
}
} else {
while self.accept(.DotDot) {
sb.write_string("../");
self.expect(.Div);
if self.peek_tok.kind != .Lbrace {
self.expect(.Div);
}
}
}
if self.tok.kind == .Div && self.peek_tok.kind == .Lbrace {
return sb.to_string();
}
sb.write_string(self.parse_name());
while self.tok.kind == .Div && self.peek_tok.kind != .Lbrace {
self.expect(.Div);
Expand Down
8 changes: 6 additions & 2 deletions rivetc/src/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,11 +523,15 @@ def parse_import_path(self):
res = ""
if self.accept(Kind.Dot):
res += "./"
self.expect(Kind.Div)
if self.peek_tok.kind != Kind.Lbrace:
self.expect(Kind.Div)
else:
while self.accept(Kind.DotDot):
res += "../"
self.expect(Kind.Div)
if self.peek_tok.kind != Kind.Lbrace:
self.expect(Kind.Div)
if self.tok.kind == Kind.Div and self.peek_tok.kind == Kind.Lbrace:
return res
res += self.parse_name()
while self.tok.kind == Kind.Div and self.peek_tok.kind != Kind.Lbrace:
self.next()
Expand Down

0 comments on commit a592a03

Please sign in to comment.