Skip to content

Commit

Permalink
added some changes
Browse files Browse the repository at this point in the history
with 3 failures
  • Loading branch information
EthanThatOneKid committed Dec 23, 2021
1 parent 4dd562a commit 85beff3
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
15 changes: 13 additions & 2 deletions lib/transpile/cartridge/cartridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ export type CartridgeEventReturnType = (
| null
);

// TODO: Refactor PropertyDefinition interface to be more strict using the
// list of possible definitions as a guide.
// Possible Property Definitions
// - example: string
// - example?: string
// - example: { nestedExample: string }
// - example: async % string; Promise<string>
// - example: fn % async % string; () => Promise<string>
// - example: fn % (a: string, async % string); (a: string) => Promise<string>
// - example: fn % (cb: fn % (async % _), number); (cb: () => Promise<void>) => number

export interface PropertyDefinition {
optional?: boolean;
modifier?: string;
Expand Down Expand Up @@ -177,11 +188,11 @@ export class Cartridge {
return executionResult ?? null;
}

public getType(type: string): string | undefined {
public getType(type?: string): string | undefined {
return this.typemap[type as ReservedType];
}

public getMod(mod: string): ModHandler | undefined {
public getMod(mod?: string): ModHandler | undefined {
return this.typemap[mod as Modifier];
}
}
2 changes: 2 additions & 0 deletions lib/transpile/cartridge/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ export type {
CartridgeEventContext,
CartridgeHandler,
CartridgeHandlerMap,
ModHandler,
Modifier,
PropertyDefinition,
} from "./cartridge.ts";
58 changes: 53 additions & 5 deletions lib/transpile/transpile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Lexicon, Token, tokenize } from "./tokenize/mod.ts";
import { Cartridge, CartridgeEvent } from "./cartridge/mod.ts";
import type { PropertyDefinition } from "./cartridge/mod.ts";
import type {
ModHandler,
Modifier,
PropertyDefinition,
} from "./cartridge/mod.ts";
import { TextBuilder } from "./text_builder/mod.ts";
// import { Lang } from "../constants/lang.ts";
import { assertKind } from "./utils.ts";
Expand Down Expand Up @@ -40,6 +44,43 @@ export class TranspilationContext {
return curr.value;
}

public nextMod(currentToken?: Token): PropertyDefinition["value"] {
const initialToken = currentToken ?? this.nextToken();
const mods: ModHandler[] = [];
let mod = this.cartridge.getMod(initialToken?.value);
while (mod !== undefined) {
mods.push(mod);
const modSymbol = assertKind(this.nextToken(), Lexicon.Modifier);
const wildToken = this.nextToken();

switch (wildToken?.kind) {
case Lexicon.Identifier: {
const result = mods.reduceRight(
(result: string, modify: ModHandler) => modify(result),
wildToken.value,
);
return result;
}

case Lexicon.TupleOpener: {
const results =
}

}
mod = this.cartridge.getMod(this.nextToken()?.value);
}
}

// public computeMods(
// tokens: Token[],
// ...mods: ModHandler[]
// ): string | undefined {
// return mods.reduceRight(
// (result: string[], mod: ModHandler) => [mod(...result)],
// tokens.map(({ value }) => this.cartridge.getType(value) ?? value),
// ).pop();
// }

/**
* Consumes the next struct, tuple, or value.
*/
Expand All @@ -63,6 +104,7 @@ export class TranspilationContext {
// if (modifier !== undefined) {
// if ident is known modifier, await nextModifier();
// }

def.value = wildToken.value;
break;
}
Expand All @@ -86,20 +128,26 @@ export class TranspilationContext {
const result: PropertyDefinition["struct"] = {};

while (true) {
// expects identifier or '}'
const ident = assertKind(
this.nextToken(),
Lexicon.Identifier,
Lexicon.StructCloser,
);
if (ident.kind === Lexicon.StructCloser) break;

if (ident.is(Lexicon.StructCloser)) {
break;
}

// expects ':' or '?:'
const propertyDefiner = assertKind(
this.nextToken(),
Lexicon.PropertyDefiner,
Lexicon.PropertyOptionalDefiner,
);

// 1st token of right-hand expression
// 1st token of right-hand expression (e.g. identifier, text literal, or
// '{').
const wildToken = await this.nextToken();

switch (wildToken?.kind) {
Expand All @@ -121,7 +169,7 @@ export class TranspilationContext {

default: {
throw new Error(
`Expected struct opener, tuple opener, or type value, but got ${wildToken}`,
`Expected struct opener or type value, but got ${wildToken}`,
);
}
}
Expand All @@ -133,7 +181,7 @@ export class TranspilationContext {
/**
* @todo implement
*/
public async nextTuple(): Promise<PropertyDefinition["tuple"]> {
public nextTuple(): PropertyDefinition["tuple"]{
return [];
}
}
Expand Down

1 comment on commit 85beff3

@deno-deploy
Copy link

@deno-deploy deno-deploy bot commented on 85beff3 Dec 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

failed to fetch 'https://raw.githubusercontent.com/EthanThatOneKid/fart/85beff34d0aabf71402a199de2c44297a71dee71/fart_server/handle_request.ts': HTTP status client error (404 Not Found) for url (https://raw.githubusercontent.com/EthanThatOneKid/fart/85beff34d0aabf71402a199de2c44297a71dee71/fart_server/handle_request.ts)

Please sign in to comment.