Skip to content

Commit

Permalink
Migrate generator/new_parser/ to core/parser/ (#228)
Browse files Browse the repository at this point in the history
This change includes the following things:
  - Rename definition_info_map, definition_info with idl_type_map,
    idl_types
  - Sort IDL types matching with upstream (WebIDL2 parser) and add
    related links
  - Move generator/new_parser/ to core/parser/

ISSUE=#207
  • Loading branch information
romandev authored Jan 4, 2018
1 parent cca347a commit 1352e61
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 37 deletions.
12 changes: 6 additions & 6 deletions generator/index.ts → core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@
* limitations under the License.
*/

import {IDLTypeMap} from 'core/parser/idl_type_map';
import {DefinitionInfo} from 'core/parser/idl_types';
import {Parser} from 'core/parser/parser';
import * as file from 'generator/base/file';
import {DefinitionInfo} from 'generator/new_parser/definition_info';
import {DefinitionInfoMap} from 'generator/new_parser/definition_info_map';
import {Parser} from 'generator/new_parser/parser';

async function readAndParse(idlFilePath: string): Promise<void> {
const idlFragment: string = await file.read(idlFilePath);
const idlDefinitionInfos: DefinitionInfo[] = await Parser.parse(idlFragment);
DefinitionInfoMap.update(idlDefinitionInfos);
IDLTypeMap.update(idlDefinitionInfos);
}

async function buildDefinitionInfoMap(idlFilePaths: string[]): Promise<void> {
async function buildIDLTypeMap(idlFilePaths: string[]): Promise<void> {
const tasks: Promise<void>[] = [];
idlFilePaths.forEach((idlFilePath) => {
tasks.push(readAndParse(idlFilePath));
Expand All @@ -35,7 +35,7 @@ async function buildDefinitionInfoMap(idlFilePaths: string[]): Promise<void> {
}

export async function run(idlFilePaths: string[]): Promise<number> {
await buildDefinitionInfoMap(idlFilePaths);
await buildIDLTypeMap(idlFilePaths);

return 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import {
DefinitionInfo, DictionaryInfo, EnumInfo, InterfaceInfo
} from 'generator/new_parser/definition_info';
} from 'core/parser/idl_types';

interface DefinitionInfoStore {
[index: string]: DefinitionInfo;
Expand Down Expand Up @@ -92,9 +92,9 @@ function updateDefinitionInfo(info: DefinitionInfo): void {
}

/**
* Raw definition information mapping table (exposed to global scope)
* IDL Type information mapping table (exposed to global scope)
*/
export class DefinitionInfoMap {
export class IDLTypeMap {
public static update(definitionInfos: DefinitionInfo[]): void {
definitionInfos.forEach((info: DefinitionInfo) => {
updateDefinitionInfo(info);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
* limitations under the License.
*/

/**
* IDL Definition Information
*/
export type DefinitionInfo = InterfaceInfo | DictionaryInfo | EnumInfo;

/**
* IDL Type Information
*
* @see https://github.com/w3c/webidl2.js#idl-type
*/
export interface TypeInfo {
readonly sequence: boolean;
readonly generic?: string;
Expand All @@ -22,13 +32,11 @@ export interface TypeInfo {
readonly union: boolean;
}

export interface ArgumentInfo {
readonly optional: boolean;
readonly variadic: boolean;
readonly idlType: TypeInfo;
readonly name: string;
}

/**
* IDL Interface Information
*
* @see https://github.com/w3c/webidl2.js#interface
*/
export interface InterfaceInfo {
readonly type: 'interface';
readonly name: string;
Expand All @@ -37,18 +45,18 @@ export interface InterfaceInfo {
inheritance: string;
}

export interface OperationMemberInfo {
readonly type: 'operation';
readonly getter: boolean;
readonly setter: boolean;
readonly deleter: boolean;
readonly static: boolean;
readonly stringifier: boolean;
readonly idlType: TypeInfo;
readonly name: string;
readonly arguments: ArgumentInfo[];
}
/**
* IDL Interface Member Information
*
* @see https://github.com/w3c/webidl2.js#interface
*/
export type InterfaceMemberInfo = OperationMemberInfo;

/**
* IDL Dictionary Information
*
* @see https://github.com/w3c/webidl2.js#dictionary
*/
export interface DictionaryInfo {
readonly type: 'dictionary';
readonly name: string;
Expand All @@ -57,6 +65,11 @@ export interface DictionaryInfo {
inheritance: string;
}

/**
* IDL Dictionary Member Information
*
* @see @see https://github.com/w3c/webidl2.js#dictionary
*/
export interface DictionaryMemberInfo {
readonly type: 'field';
readonly name: string;
Expand All @@ -65,16 +78,52 @@ export interface DictionaryMemberInfo {
readonly default: TypeValue;
}

/**
* IDL Enum Information
*
* @see https://github.com/w3c/webidl2.js#enum
*/
export interface EnumInfo {
readonly type: 'enum';
readonly name: string;
readonly values: TypeValue[];
}

/**
* IDL Operation Member Information
*
* @see https://github.com/w3c/webidl2.js#enum
*/
export interface OperationMemberInfo {
readonly type: 'operation';
readonly getter: boolean;
readonly setter: boolean;
readonly deleter: boolean;
readonly static: boolean;
readonly stringifier: boolean;
readonly idlType: TypeInfo;
readonly name: string;
readonly arguments: ArgumentInfo[];
}

/**
* IDL Argument(e.g. for an operation) Information
*
* @see https://github.com/w3c/webidl2.js#arguments
*/
export interface ArgumentInfo {
readonly optional: boolean;
readonly variadic: boolean;
readonly idlType: TypeInfo;
readonly name: string;
}

/**
* IDL TypeValue Information
*
* @see https://github.com/w3c/webidl2.js#default-and-const-values
*/
export interface TypeValue {
readonly type: string;
readonly value: string;
}

export type InterfaceMemberInfo = OperationMemberInfo;
export type DefinitionInfo = InterfaceInfo | DictionaryInfo | EnumInfo;
3 changes: 1 addition & 2 deletions generator/new_parser/parser.ts → core/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* limitations under the License.
*/

import {DefinitionInfo} from 'generator/new_parser/definition_info';
import {DefinitionInfoMap} from 'generator/new_parser/definition_info_map';
import {DefinitionInfo} from 'core/parser/idl_types';
import * as webidl from 'webidl2';

/**
Expand Down
10 changes: 5 additions & 5 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as commandLineUsage from 'command-line-usage';
import * as generator from 'generator';
import * as core from 'core';
import * as globs from 'globs';
import * as gulp from 'gulp';
import * as shell from 'gulp-shell';
Expand Down Expand Up @@ -61,7 +61,7 @@ gulp.task('default', () => {
*/
gulp.task('build_webidl', (callback) => {
globs(['examples/**/*.idl', 'test/**/*.idl'], async(error, files) => {
callback(await generator.run(files));
callback(await core.run(files));
});
});

Expand Down Expand Up @@ -138,9 +138,9 @@ gulp.task('lint_ts', () => {

return gulp.src([
'gulpfile.ts',
'generator/index.ts',
'generator/base/**/*.ts',
'generator/new_parser/**/*.ts'
'core/index.ts',
'core/parser/**/*.ts',
'generator/base/**/*.ts'
])
.pipe(gulpTslint({
formatter: 'codeFrame',
Expand Down

0 comments on commit 1352e61

Please sign in to comment.