Skip to content

Commit 7b95ddc

Browse files
committed
Emit imports, fixing interop with xp-forge/partial. See #15
1 parent e0efb68 commit 7b95ddc

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ XP Compiler ChangeLog
33

44
## ?.?.? / ????-??-??
55

6+
## 1.1.2 / 2017-10-31
7+
8+
* Fixed issue #15: Interop with xp-forge/partial broken - @thekid
9+
610
## 1.1.1 / 2017-10-31
711

812
* Fixed map initialization with keys consisting of complex expressions

src/main/php/lang/ast/Emitter.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ protected function emitPackage($node) {
193193
}
194194

195195
protected function emitImport($node) {
196-
// NOOP
196+
$this->out->write('use '.implode(',', $node->value).';');
197197
}
198198

199199
protected function emitAnnotation($node) {

src/main/php/lang/ast/Parse.class.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,19 +402,23 @@ private function setup() {
402402
$this->token= $this->advance();
403403

404404
if ('{' === $this->token->symbol->id) {
405+
$types= [];
405406
while ('}' !== $this->token->symbol->id) {
406407
$this->token= $this->advance();
407-
$class= $this->token->value;
408-
$this->scope->import($import.$class);
408+
$class= $import.$this->token->value;
409+
$types[]= $class;
410+
$this->scope->import($class);
409411
$this->token= $this->advance();
410412
}
411413
$this->token= $this->advance();
412414
} else {
415+
$types= [$import];
413416
$this->scope->import($import);
414417
}
415418

416419
$this->token= $this->expect(';');
417420
$node->arity= 'import';
421+
$node->value= $types;
418422
return $node;
419423
});
420424

src/test/php/lang/ast/unittest/ScopeTest.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ public function resolve_in_package() {
3232
$this->assertEquals('\\test\\Parse', $s->resolve('Parse'));
3333
}
3434

35+
#[@test]
36+
public function resolve_relative_in_package() {
37+
$s= new Scope();
38+
$s->package('test');
39+
40+
$this->assertEquals('\\test\\ast\\Parse', $s->resolve('ast\\Parse'));
41+
}
42+
3543
#[@test]
3644
public function resolve_imported_in_package() {
3745
$s= new Scope();

src/test/php/lang/ast/unittest/parse/NamespacesTest.class.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ public function compound_namespace() {
1414

1515
#[@test]
1616
public function use_statement() {
17-
$this->assertNodes([['use' => 'use']], $this->parse('use lang\ast\Parse;'));
17+
$this->assertNodes([['use' => ['lang\ast\Parse']]], $this->parse('use lang\ast\Parse;'));
1818
}
1919

2020
#[@test]
2121
public function grouped_use_statement() {
22-
$this->assertNodes([['use' => 'use']], $this->parse('use lang\ast\{Parse, Emitter};'));
22+
$this->assertNodes(
23+
[['use' => ['lang\ast\Parse', 'lang\ast\Emitter']]],
24+
$this->parse('use lang\ast\{Parse, Emitter};')
25+
);
2326
}
2427
}

0 commit comments

Comments
 (0)