Change 'interface' keyword to 'namespace'
This commit is contained in:
Родитель
3198caebe3
Коммит
73ddb6858b
|
@ -1,6 +1,6 @@
|
|||
import { visitChildren } from './parser.js';
|
||||
import { ADLSourceFile, Program } from './program.js';
|
||||
import { InterfaceStatementNode, ModelStatementNode, Node, SyntaxKind, TemplateParameterDeclarationNode } from './types.js';
|
||||
import { NamespaceStatementNode, ModelStatementNode, Node, SyntaxKind, TemplateParameterDeclarationNode } from './types.js';
|
||||
|
||||
// trying to avoid masking built-in Symbol
|
||||
export type Sym = DecoratorSymbol | TypeSymbol;
|
||||
|
@ -61,7 +61,7 @@ export function createBinder(): Binder {
|
|||
case SyntaxKind.ModelStatement:
|
||||
bindModelStatement(<any>node);
|
||||
break;
|
||||
case SyntaxKind.InterfaceStatement:
|
||||
case SyntaxKind.NamespaceStatement:
|
||||
bindInterfaceStatement(<any>node);
|
||||
break;
|
||||
case SyntaxKind.TemplateParameterDeclaration:
|
||||
|
@ -104,7 +104,7 @@ export function createBinder(): Binder {
|
|||
}
|
||||
|
||||
function bindInterfaceStatement(
|
||||
statement: InterfaceStatementNode
|
||||
statement: NamespaceStatementNode
|
||||
) {
|
||||
currentFile.symbols.set(statement.id.sv, {
|
||||
kind: 'type',
|
||||
|
|
|
@ -5,10 +5,10 @@ import {
|
|||
BooleanLiteralNode,
|
||||
BooleanLiteralType,
|
||||
IdentifierNode,
|
||||
InterfacePropertyNode,
|
||||
InterfaceStatementNode,
|
||||
InterfaceType,
|
||||
InterfaceTypeProperty,
|
||||
NamespacePropertyNode,
|
||||
NamespaceStatementNode,
|
||||
Namespace,
|
||||
NamespaceProperty,
|
||||
IntersectionExpressionNode,
|
||||
LiteralNode,
|
||||
LiteralType,
|
||||
|
@ -79,7 +79,7 @@ export function createChecker(program: Program) {
|
|||
checkProgram,
|
||||
getLiteralType,
|
||||
getTypeName,
|
||||
checkInterfaceProperty
|
||||
checkNamespaceProperty
|
||||
};
|
||||
|
||||
function getTypeForNode(node: Node): Type {
|
||||
|
@ -93,10 +93,10 @@ export function createChecker(program: Program) {
|
|||
return checkModel(<ModelStatementNode>node);
|
||||
case SyntaxKind.ModelProperty:
|
||||
return checkModelProperty(<ModelPropertyNode>node);
|
||||
case SyntaxKind.InterfaceStatement:
|
||||
return checkInterface(<InterfaceStatementNode>node);
|
||||
case SyntaxKind.InterfaceProperty:
|
||||
return checkInterfaceProperty(<InterfacePropertyNode>node);
|
||||
case SyntaxKind.NamespaceStatement:
|
||||
return checkNamespace(<NamespaceStatementNode>node);
|
||||
case SyntaxKind.NamespaceProperty:
|
||||
return checkNamespaceProperty(<NamespacePropertyNode>node);
|
||||
case SyntaxKind.Identifier:
|
||||
// decorator bindings presently return an empty binding
|
||||
return <any>checkIdentifier(<IdentifierNode>node);
|
||||
|
@ -254,9 +254,9 @@ export function createChecker(program: Program) {
|
|||
});
|
||||
}
|
||||
|
||||
function checkInterface(node: InterfaceStatementNode) {
|
||||
const type: InterfaceType = createType({
|
||||
kind: 'Interface',
|
||||
function checkNamespace(node: NamespaceStatementNode) {
|
||||
const type: Namespace = createType({
|
||||
kind: 'Namespace',
|
||||
name: node.id.sv,
|
||||
node: node,
|
||||
properties: new Map(),
|
||||
|
@ -264,15 +264,15 @@ export function createChecker(program: Program) {
|
|||
});
|
||||
|
||||
for (const prop of node.properties) {
|
||||
type.properties.set(prop.id.sv, checkInterfaceProperty(prop));
|
||||
type.properties.set(prop.id.sv, checkNamespaceProperty(prop));
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
function checkInterfaceProperty(prop: InterfacePropertyNode): InterfaceTypeProperty {
|
||||
function checkNamespaceProperty(prop: NamespacePropertyNode): NamespaceProperty {
|
||||
return createType({
|
||||
kind: 'InterfaceProperty',
|
||||
kind: 'NamespaceProperty',
|
||||
name: prop.id.sv,
|
||||
node: prop,
|
||||
parameters: <ModelType>getTypeForNode(prop.parameters),
|
||||
|
|
|
@ -38,7 +38,7 @@ export function parse(code: string) {
|
|||
return parseImportStatement();
|
||||
case Token.ModelKeyword:
|
||||
return parseModelStatement(decorators);
|
||||
case Token.InterfaceKeyword:
|
||||
case Token.NamespaceKeyword:
|
||||
return parseInterfaceStatement(decorators);
|
||||
case Token.Semicolon:
|
||||
if (decorators.length > 0) {
|
||||
|
@ -66,9 +66,9 @@ export function parse(code: string) {
|
|||
|
||||
function parseInterfaceStatement(
|
||||
decorators: Array<Types.DecoratorExpressionNode>
|
||||
): Types.InterfaceStatementNode {
|
||||
): Types.NamespaceStatementNode {
|
||||
const pos = tokenPos();
|
||||
parseExpected(Token.InterfaceKeyword);
|
||||
parseExpected(Token.NamespaceKeyword);
|
||||
const id = parseIdentifier();
|
||||
let parameters: Types.ModelExpressionNode | undefined;
|
||||
|
||||
|
@ -86,20 +86,20 @@ export function parse(code: string) {
|
|||
|
||||
|
||||
parseExpected(Token.OpenBrace);
|
||||
const properties: Array<Types.InterfacePropertyNode> = [];
|
||||
const properties: Array<Types.NamespacePropertyNode> = [];
|
||||
|
||||
do {
|
||||
if (token() == Token.CloseBrace) {
|
||||
break;
|
||||
}
|
||||
const memberDecorators = parseDecoratorList();
|
||||
properties.push(parseInterfaceProperty(memberDecorators));
|
||||
properties.push(parseNamespaceProperty(memberDecorators));
|
||||
} while (parseOptional(Token.Comma) || parseOptional(Token.Semicolon));
|
||||
|
||||
parseExpected(Token.CloseBrace);
|
||||
|
||||
return finishNode({
|
||||
kind: Types.SyntaxKind.InterfaceStatement,
|
||||
kind: Types.SyntaxKind.NamespaceStatement,
|
||||
decorators,
|
||||
id,
|
||||
parameters,
|
||||
|
@ -107,7 +107,7 @@ export function parse(code: string) {
|
|||
}, pos);
|
||||
}
|
||||
|
||||
function parseInterfaceProperty(decorators: Array<Types.DecoratorExpressionNode>): Types.InterfacePropertyNode {
|
||||
function parseNamespaceProperty(decorators: Array<Types.DecoratorExpressionNode>): Types.NamespacePropertyNode {
|
||||
const pos = tokenPos();
|
||||
const id = parseIdentifier();
|
||||
parseExpected(Token.OpenParen);
|
||||
|
@ -128,7 +128,7 @@ export function parse(code: string) {
|
|||
const returnType = parseExpression();
|
||||
|
||||
return finishNode({
|
||||
kind: Types.SyntaxKind.InterfaceProperty,
|
||||
kind: Types.SyntaxKind.NamespaceProperty,
|
||||
id,
|
||||
parameters,
|
||||
returnType,
|
||||
|
@ -637,16 +637,16 @@ export function visitChildren<T>(node: Types.Node, cb: NodeCb<T>): T | undefined
|
|||
case Types.SyntaxKind.ImportStatement:
|
||||
return visitNode(cb, (<Types.ImportStatementNode>node).id) ||
|
||||
visitEach(cb, (<Types.ImportStatementNode>node).as);
|
||||
case Types.SyntaxKind.InterfaceProperty:
|
||||
return visitEach(cb, (<Types.InterfacePropertyNode>node).decorators) ||
|
||||
visitNode(cb, (<Types.InterfacePropertyNode>node).id) ||
|
||||
visitNode(cb, (<Types.InterfacePropertyNode>node).parameters) ||
|
||||
visitNode(cb, (<Types.InterfacePropertyNode>node).returnType);
|
||||
case Types.SyntaxKind.InterfaceStatement:
|
||||
return visitEach(cb, (<Types.InterfaceStatementNode> node).decorators) ||
|
||||
visitNode(cb, (<Types.InterfaceStatementNode>node).id) ||
|
||||
visitNode(cb, (<Types.InterfaceStatementNode>node).parameters) ||
|
||||
visitEach(cb, (<Types.InterfaceStatementNode>node).properties);
|
||||
case Types.SyntaxKind.NamespaceProperty:
|
||||
return visitEach(cb, (<Types.NamespacePropertyNode>node).decorators) ||
|
||||
visitNode(cb, (<Types.NamespacePropertyNode>node).id) ||
|
||||
visitNode(cb, (<Types.NamespacePropertyNode>node).parameters) ||
|
||||
visitNode(cb, (<Types.NamespacePropertyNode>node).returnType);
|
||||
case Types.SyntaxKind.NamespaceStatement:
|
||||
return visitEach(cb, (<Types.NamespaceStatementNode> node).decorators) ||
|
||||
visitNode(cb, (<Types.NamespaceStatementNode>node).id) ||
|
||||
visitNode(cb, (<Types.NamespaceStatementNode>node).parameters) ||
|
||||
visitEach(cb, (<Types.NamespaceStatementNode>node).properties);
|
||||
case Types.SyntaxKind.IntersectionExpression:
|
||||
return visitEach(cb, (<Types.IntersectionExpressionNode>node).options);
|
||||
case Types.SyntaxKind.MemberExpression:
|
||||
|
|
|
@ -10,7 +10,7 @@ import { resolvePath } from './util.js';
|
|||
import {
|
||||
ADLScriptNode,
|
||||
DecoratorExpressionNode, IdentifierNode,
|
||||
InterfaceType,
|
||||
Namespace,
|
||||
LiteralType,
|
||||
ModelStatementNode,
|
||||
ModelType,
|
||||
|
@ -27,7 +27,7 @@ export interface Program {
|
|||
checker?: ReturnType<typeof createChecker>;
|
||||
evalAdlScript(adlScript: string, filePath?: string): void;
|
||||
onBuild(cb: (program: Program) => void): void;
|
||||
executeInterfaceDecorators(type: InterfaceType): void;
|
||||
executeInterfaceDecorators(type: Namespace): void;
|
||||
executeModelDecorators(type: ModelType): void;
|
||||
executeDecorators(type: Type): void;
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ export interface ADLSourceFile {
|
|||
path: string;
|
||||
symbols: SymbolTable;
|
||||
models: Array<ModelType>;
|
||||
interfaces: Array<InterfaceType>;
|
||||
interfaces: Array<Namespace>;
|
||||
}
|
||||
|
||||
export async function compile(rootDir: string, options?: CompilerOptions) {
|
||||
|
@ -71,7 +71,7 @@ export async function compile(rootDir: string, options?: CompilerOptions) {
|
|||
* does type checking.
|
||||
*/
|
||||
|
||||
function executeInterfaceDecorators(type: InterfaceType) {
|
||||
function executeInterfaceDecorators(type: Namespace) {
|
||||
const stmt = type.node;
|
||||
|
||||
for (const dec of stmt.decorators) {
|
||||
|
|
|
@ -48,7 +48,7 @@ export enum Token {
|
|||
// Keywords
|
||||
ImportKeyword,
|
||||
ModelKeyword,
|
||||
InterfaceKeyword,
|
||||
NamespaceKeyword,
|
||||
TrueKeyword,
|
||||
FalseKeyword
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ export enum Token {
|
|||
const keywords = new Map([
|
||||
['import', Token.ImportKeyword],
|
||||
['model', Token.ModelKeyword],
|
||||
['interface', Token.InterfaceKeyword],
|
||||
['namespace', Token.NamespaceKeyword],
|
||||
['true', Token.TrueKeyword],
|
||||
['false', Token.FalseKeyword]
|
||||
]);
|
||||
|
@ -610,4 +610,4 @@ export function createScanner(input: string, onError = throwOnError) {
|
|||
scanUntil(ch => !isIdentifierPart(ch));
|
||||
return token = keywords.get(getTokenValue()) ?? Token.Identifier;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ export type Type =
|
|||
| ModelType
|
||||
| ModelTypeProperty
|
||||
| TemplateParameterType
|
||||
| InterfaceType
|
||||
| InterfaceTypeProperty
|
||||
| Namespace
|
||||
| NamespaceProperty
|
||||
| StringLiteralType
|
||||
| NumericLiteralType
|
||||
| BooleanLiteralType
|
||||
|
@ -41,19 +41,19 @@ export interface ModelTypeProperty {
|
|||
optional: boolean;
|
||||
}
|
||||
|
||||
export interface InterfaceTypeProperty {
|
||||
kind: 'InterfaceProperty';
|
||||
node: InterfacePropertyNode;
|
||||
export interface NamespaceProperty {
|
||||
kind: 'NamespaceProperty';
|
||||
node: NamespacePropertyNode;
|
||||
name: string;
|
||||
parameters?: ModelType;
|
||||
returnType: Type;
|
||||
}
|
||||
|
||||
export interface InterfaceType extends BaseType {
|
||||
kind: 'Interface';
|
||||
export interface Namespace extends BaseType {
|
||||
kind: 'Namespace';
|
||||
name: string;
|
||||
node: InterfaceStatementNode;
|
||||
properties: Map<string, InterfaceTypeProperty>;
|
||||
node: NamespaceStatementNode;
|
||||
properties: Map<string, NamespaceProperty>;
|
||||
parameters?: ModelType;
|
||||
}
|
||||
|
||||
|
@ -109,8 +109,8 @@ export enum SyntaxKind {
|
|||
NamedImport,
|
||||
DecoratorExpression,
|
||||
MemberExpression,
|
||||
InterfaceStatement,
|
||||
InterfaceProperty,
|
||||
NamespaceStatement,
|
||||
NamespaceProperty,
|
||||
ModelStatement,
|
||||
ModelExpression,
|
||||
ModelProperty,
|
||||
|
@ -141,7 +141,7 @@ export interface ADLScriptNode extends Node {
|
|||
export type Statement =
|
||||
| ImportStatementNode
|
||||
| ModelStatementNode
|
||||
| InterfaceStatementNode;
|
||||
| NamespaceStatementNode;
|
||||
|
||||
export interface ImportStatementNode extends Node {
|
||||
kind: SyntaxKind.ImportStatement;
|
||||
|
@ -184,16 +184,16 @@ export interface MemberExpressionNode extends Node {
|
|||
base: MemberExpressionNode | IdentifierNode;
|
||||
}
|
||||
|
||||
export interface InterfaceStatementNode extends Node {
|
||||
kind: SyntaxKind.InterfaceStatement;
|
||||
export interface NamespaceStatementNode extends Node {
|
||||
kind: SyntaxKind.NamespaceStatement;
|
||||
id: IdentifierNode;
|
||||
parameters?: ModelExpressionNode;
|
||||
properties: Array<InterfacePropertyNode>;
|
||||
properties: Array<NamespacePropertyNode>;
|
||||
decorators: Array<DecoratorExpressionNode>;
|
||||
}
|
||||
|
||||
export interface InterfacePropertyNode extends Node {
|
||||
kind: SyntaxKind.InterfaceProperty;
|
||||
export interface NamespacePropertyNode extends Node {
|
||||
kind: SyntaxKind.NamespaceProperty;
|
||||
id: IdentifierNode;
|
||||
parameters: ModelExpressionNode;
|
||||
returnType: Expression;
|
||||
|
|
|
@ -154,7 +154,7 @@ export function getVisibility(target: Type): string | undefined {
|
|||
const listProperties = new Set<Type>();
|
||||
|
||||
export function list(program: Program, target: Type) {
|
||||
if (target.kind === "InterfaceProperty" || target.kind === "ModelProperty") {
|
||||
if (target.kind === "NamespaceProperty" || target.kind === "ModelProperty") {
|
||||
listProperties.add(target);
|
||||
} else {
|
||||
throw new Error("The @list decorator can only be applied to interface or model properties.");
|
||||
|
|
|
@ -4,7 +4,7 @@ import { Type } from "../compiler/types";
|
|||
const basePaths = new Map<Type, string>();
|
||||
|
||||
export function resource(program: Program, entity: Type, basePath = '') {
|
||||
if (entity.kind !== 'Interface') return;
|
||||
if (entity.kind !== 'Namespace') return;
|
||||
basePaths.set(entity, basePath);
|
||||
}
|
||||
|
||||
|
@ -75,7 +75,7 @@ interface OperationRoute {
|
|||
const operationRoutes = new Map<Type, OperationRoute>();
|
||||
|
||||
function setOperationRoute(entity: Type, verb: OperationRoute) {
|
||||
if (entity.kind === "InterfaceProperty") {
|
||||
if (entity.kind === "NamespaceProperty") {
|
||||
if (!operationRoutes.has(entity)) {
|
||||
operationRoutes.set(entity, verb);
|
||||
} else {
|
||||
|
|
|
@ -98,7 +98,7 @@ describe('syntax', () => {
|
|||
|
||||
describe('tuple model expressions', () => {
|
||||
parseEach([
|
||||
'interface A { b(param: [number, string]): [1, "hi"] }'
|
||||
'namespace A { b(param: [number, string]): [1, "hi"] }'
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -136,16 +136,16 @@ describe('syntax', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
describe('interface statements', () => {
|
||||
describe('namespace statements', () => {
|
||||
parseEach([
|
||||
'interface Store {}',
|
||||
'interface Store { read(): int32 }',
|
||||
'interface Store { read(): int32, write(v: int32): {} }',
|
||||
'interface Store { read(): int32; write(v: int32): {} }',
|
||||
'@foo interface Store { @dec read():number, @dec write(n: number): {} }',
|
||||
'@foo @bar interface Store { @foo @bar read(): number; }',
|
||||
'interface Store(apiKey: string, otherArg: number) { }',
|
||||
'interface Store(... apiKeys, x: string) { foo(... A, b: string, ...C, d: number): void }'
|
||||
'namespace Store {}',
|
||||
'namespace Store { read(): int32 }',
|
||||
'namespace Store { read(): int32, write(v: int32): {} }',
|
||||
'namespace Store { read(): int32; write(v: int32): {} }',
|
||||
'@foo namespace Store { @dec read():number, @dec write(n: number): {} }',
|
||||
'@foo @bar namespace Store { @foo @bar read(): number; }',
|
||||
'namespace Store(apiKey: string, otherArg: number) { }',
|
||||
'namespace Store(... apiKeys, x: string) { foo(... A, b: string, ...C, d: number): void }'
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -155,10 +155,10 @@ describe('syntax', () => {
|
|||
model B { }
|
||||
model C = A;
|
||||
;
|
||||
interface I {
|
||||
namespace I {
|
||||
foo(): number;
|
||||
}
|
||||
interface J {
|
||||
namespace J {
|
||||
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче