Skip to content
Permalink
Browse files

Add parser support for import (Java).

  • Loading branch information...
bhelyer committed May 19, 2011
1 parent e1eca1f commit 41d54a7a1fc57c3745493ee69b2be7bb59dc04c6
Showing with 35 additions and 3 deletions.
  1. +10 −2 src/sdc/ast/sdcimport.d
  2. +3 −0 src/sdc/gen/sdcimport.d
  3. +22 −1 src/sdc/parser/sdcimport.d
@@ -8,11 +8,19 @@ module sdc.ast.sdcimport;
import sdc.ast.base;


// static? import importList ;
// static? import (\(Identifier\) stringliterallist | importList);
class ImportDeclaration : Node
{
bool isStatic;
ImportList importList;
ImportList importList; // Not if the below exist.
Language language = Language.D; // Optional.
StringLiteral[] languageImports; // Optional.
}

enum Language
{
D,
Java,
}

enum ImportListType
@@ -55,6 +55,9 @@ ast.ImportDeclaration synthesiseImport(string modname)

void genImportDeclaration(ast.ImportDeclaration importDeclaration, Module mod)
{
if (importDeclaration.language != ast.Language.D) {
throw new CompilerPanic(importDeclaration.location, "import (Java) is unimplemented.");
}
return genImportList(importDeclaration.location, importDeclaration.importList, mod);
}

@@ -23,7 +23,28 @@ ImportDeclaration parseImportDeclaration(TokenStream tstream)
decl.isStatic = true;
}
match(tstream, TokenType.Import);
decl.importList = parseImportList(tstream);
if (tstream.peek.type == TokenType.OpenParen) {
match(tstream, TokenType.OpenParen);
auto ident = match(tstream, TokenType.Identifier);
switch (ident.value) {
case "Java":
decl.language = Language.Java;
break;
default:
throw new CompilerError(ident.location, format("expected 'Java', not '%s'.", ident.value));
}
match(tstream, TokenType.CloseParen);
do {
decl.languageImports ~= parseStringLiteral(tstream);
if (tstream.peek.type == TokenType.Comma) {
tstream.getToken();
continue;
}
break;
} while (true);
} else {
decl.importList = parseImportList(tstream);
}
match(tstream, TokenType.Semicolon);
return decl;
}

0 comments on commit 41d54a7

Please sign in to comment.
You can’t perform that action at this time.