Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Use more explicit names than Access and Lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
g. nicholas d'andrea committed Apr 23, 2021
1 parent 6f5f7e6 commit c44a70d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
24 changes: 13 additions & 11 deletions packages/parse-mapping-lookup/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export interface Pointer {
path: Step[];
}

export type Step = Access | Lookup;
export type Step = IndexAccess | MemberLookup;

export const pointer = (options: { path: Step[] }): Pointer => {
const { path } = options;
Expand All @@ -60,35 +60,37 @@ export const pointer = (options: { path: Step[] }): Pointer => {
};

/*
* Lookup
* MemberLookup
*/

export interface Lookup {
kind: "lookup";
export interface MemberLookup {
kind: "member-lookup";
property: Identifier;
}

export const lookup = (options: { property: Identifier }): Lookup => {
export const memberLookup = (options: {
property: Identifier;
}): MemberLookup => {
const { property } = options;
return {
kind: "lookup",
kind: "member-lookup",
property
};
};

/*
* Access
* IndexAccess
*/

export interface Access {
kind: "access";
export interface IndexAccess {
kind: "index-access";
index: Literal;
}

export const access = (options: { index: Literal }): Access => {
export const indexAccess = (options: { index: Literal }): IndexAccess => {
const { index } = options;
return {
kind: "access",
kind: "index-access",
index
};
};
Expand Down
24 changes: 12 additions & 12 deletions packages/parse-mapping-lookup/src/parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { parse } from "@truffle/parse-mapping-lookup/parser";

import {
expression,
access,
lookup,
indexAccess,
memberLookup,
identifier,
pointer,
literal
Expand All @@ -15,7 +15,7 @@ const testCases = [
result: expression({
root: identifier({ name: "m" }),
pointer: pointer({
path: [access({ index: literal({ value: "0" }) })]
path: [indexAccess({ index: literal({ value: "0" }) })]
})
})
},
Expand All @@ -25,8 +25,8 @@ const testCases = [
root: identifier({ name: "m" }),
pointer: pointer({
path: [
access({ index: literal({ value: "0" }) }),
access({ index: literal({ value: "1" }) })
indexAccess({ index: literal({ value: "0" }) }),
indexAccess({ index: literal({ value: "1" }) })
]
})
})
Expand All @@ -36,7 +36,7 @@ const testCases = [
result: expression({
root: identifier({ name: "m" }),
pointer: pointer({
path: [access({ index: literal({ value: "hello" }) })]
path: [indexAccess({ index: literal({ value: "hello" }) })]
})
})
},
Expand All @@ -45,7 +45,7 @@ const testCases = [
result: expression({
root: identifier({ name: "m" }),
pointer: pointer({
path: [access({ index: literal({ value: '"' }) })]
path: [indexAccess({ index: literal({ value: '"' }) })]
})
})
},
Expand All @@ -55,8 +55,8 @@ const testCases = [
root: identifier({ name: "s" }),
pointer: pointer({
path: [
lookup({ property: identifier({ name: "m" }) }),
access({ index: literal({ value: "0" }) })
memberLookup({ property: identifier({ name: "m" }) }),
indexAccess({ index: literal({ value: "0" }) })
]
})
})
Expand All @@ -67,9 +67,9 @@ const testCases = [
root: identifier({ name: "m$" }),
pointer: pointer({
path: [
access({ index: literal({ value: "0" }) }),
lookup({ property: identifier({ name: "_k" }) }),
access({ index: literal({ value: "1" }) })
indexAccess({ index: literal({ value: "0" }) }),
memberLookup({ property: identifier({ name: "_k" }) }),
indexAccess({ index: literal({ value: "1" }) })
]
})
})
Expand Down
18 changes: 9 additions & 9 deletions packages/parse-mapping-lookup/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {
} from "parjs/combinators";

import {
access,
indexAccess,
expression,
identifier,
literal,
lookup,
memberLookup,
pointer
} from "./ast";

Expand Down Expand Up @@ -91,28 +91,28 @@ const literalP = numberP.pipe(
);

/*
* Lookup
* MemberLookup
*/

const lookupP = string(".").pipe(
const memberLookupP = string(".").pipe(
then(identifierP),
map(([_, property]) => lookup({ property }))
map(([_, property]) => memberLookup({ property }))
);

/*
* Access
* IndexAccess
*/

const accessP = literalP.pipe(
const indexAccessP = literalP.pipe(
between(string("["), string("]")),
map(index => access({ index }))
map(index => indexAccess({ index }))
);

/*
* Pointer
*/

const stepP = lookupP.pipe(or(accessP));
const stepP = memberLookupP.pipe(or(indexAccessP));

const pointerP = stepP.pipe(
then(stepP.pipe(many())),
Expand Down

0 comments on commit c44a70d

Please sign in to comment.