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

Commit c44a70d

Browse files
author
g. nicholas d'andrea
committed
Use more explicit names than Access and Lookup
1 parent 6f5f7e6 commit c44a70d

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

packages/parse-mapping-lookup/src/ast.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface Pointer {
4949
path: Step[];
5050
}
5151

52-
export type Step = Access | Lookup;
52+
export type Step = IndexAccess | MemberLookup;
5353

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

6262
/*
63-
* Lookup
63+
* MemberLookup
6464
*/
6565

66-
export interface Lookup {
67-
kind: "lookup";
66+
export interface MemberLookup {
67+
kind: "member-lookup";
6868
property: Identifier;
6969
}
7070

71-
export const lookup = (options: { property: Identifier }): Lookup => {
71+
export const memberLookup = (options: {
72+
property: Identifier;
73+
}): MemberLookup => {
7274
const { property } = options;
7375
return {
74-
kind: "lookup",
76+
kind: "member-lookup",
7577
property
7678
};
7779
};
7880

7981
/*
80-
* Access
82+
* IndexAccess
8183
*/
8284

83-
export interface Access {
84-
kind: "access";
85+
export interface IndexAccess {
86+
kind: "index-access";
8587
index: Literal;
8688
}
8789

88-
export const access = (options: { index: Literal }): Access => {
90+
export const indexAccess = (options: { index: Literal }): IndexAccess => {
8991
const { index } = options;
9092
return {
91-
kind: "access",
93+
kind: "index-access",
9294
index
9395
};
9496
};

packages/parse-mapping-lookup/src/parser.spec.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { parse } from "@truffle/parse-mapping-lookup/parser";
22

33
import {
44
expression,
5-
access,
6-
lookup,
5+
indexAccess,
6+
memberLookup,
77
identifier,
88
pointer,
99
literal
@@ -15,7 +15,7 @@ const testCases = [
1515
result: expression({
1616
root: identifier({ name: "m" }),
1717
pointer: pointer({
18-
path: [access({ index: literal({ value: "0" }) })]
18+
path: [indexAccess({ index: literal({ value: "0" }) })]
1919
})
2020
})
2121
},
@@ -25,8 +25,8 @@ const testCases = [
2525
root: identifier({ name: "m" }),
2626
pointer: pointer({
2727
path: [
28-
access({ index: literal({ value: "0" }) }),
29-
access({ index: literal({ value: "1" }) })
28+
indexAccess({ index: literal({ value: "0" }) }),
29+
indexAccess({ index: literal({ value: "1" }) })
3030
]
3131
})
3232
})
@@ -36,7 +36,7 @@ const testCases = [
3636
result: expression({
3737
root: identifier({ name: "m" }),
3838
pointer: pointer({
39-
path: [access({ index: literal({ value: "hello" }) })]
39+
path: [indexAccess({ index: literal({ value: "hello" }) })]
4040
})
4141
})
4242
},
@@ -45,7 +45,7 @@ const testCases = [
4545
result: expression({
4646
root: identifier({ name: "m" }),
4747
pointer: pointer({
48-
path: [access({ index: literal({ value: '"' }) })]
48+
path: [indexAccess({ index: literal({ value: '"' }) })]
4949
})
5050
})
5151
},
@@ -55,8 +55,8 @@ const testCases = [
5555
root: identifier({ name: "s" }),
5656
pointer: pointer({
5757
path: [
58-
lookup({ property: identifier({ name: "m" }) }),
59-
access({ index: literal({ value: "0" }) })
58+
memberLookup({ property: identifier({ name: "m" }) }),
59+
indexAccess({ index: literal({ value: "0" }) })
6060
]
6161
})
6262
})
@@ -67,9 +67,9 @@ const testCases = [
6767
root: identifier({ name: "m$" }),
6868
pointer: pointer({
6969
path: [
70-
access({ index: literal({ value: "0" }) }),
71-
lookup({ property: identifier({ name: "_k" }) }),
72-
access({ index: literal({ value: "1" }) })
70+
indexAccess({ index: literal({ value: "0" }) }),
71+
memberLookup({ property: identifier({ name: "_k" }) }),
72+
indexAccess({ index: literal({ value: "1" }) })
7373
]
7474
})
7575
})

packages/parse-mapping-lookup/src/parser.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import {
2121
} from "parjs/combinators";
2222

2323
import {
24-
access,
24+
indexAccess,
2525
expression,
2626
identifier,
2727
literal,
28-
lookup,
28+
memberLookup,
2929
pointer
3030
} from "./ast";
3131

@@ -91,28 +91,28 @@ const literalP = numberP.pipe(
9191
);
9292

9393
/*
94-
* Lookup
94+
* MemberLookup
9595
*/
9696

97-
const lookupP = string(".").pipe(
97+
const memberLookupP = string(".").pipe(
9898
then(identifierP),
99-
map(([_, property]) => lookup({ property }))
99+
map(([_, property]) => memberLookup({ property }))
100100
);
101101

102102
/*
103-
* Access
103+
* IndexAccess
104104
*/
105105

106-
const accessP = literalP.pipe(
106+
const indexAccessP = literalP.pipe(
107107
between(string("["), string("]")),
108-
map(index => access({ index }))
108+
map(index => indexAccess({ index }))
109109
);
110110

111111
/*
112112
* Pointer
113113
*/
114114

115-
const stepP = lookupP.pipe(or(accessP));
115+
const stepP = memberLookupP.pipe(or(indexAccessP));
116116

117117
const pointerP = stepP.pipe(
118118
then(stepP.pipe(many())),

0 commit comments

Comments
 (0)