Skip to content

Commit 583f96e

Browse files
Integrations for ASTExplorer
1 parent bdb948c commit 583f96e

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

README.md

+45-1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,48 @@ $ npm run build
2828

2929
```
3030
$ npm test
31-
```
31+
```
32+
33+
## Viewing with ASTExplorer
34+
35+
ASTExplorer is a web app for visualizing ASTs. You type source. It shows you the resulting syntax tree based on the parser you've selected. I've included the integrations for this parser. To get that up and running you'll need to clone ASTExplorer.
36+
37+
```
38+
$ git clone https://github.com/fkling/astexplorer.git
39+
$ cd astexplorer
40+
$ git submodule update --init
41+
$ cd website/
42+
```
43+
44+
In another terminal window, (until we publish this parser) you'll need to npm link to get things to work.
45+
46+
From the root directory of this parser, where the package.json is...
47+
48+
```
49+
$ npm link
50+
```
51+
52+
Then back in your terminal for ASTExplorer (from astexplorer/website)...
53+
54+
```
55+
$ npm link @creditkarma/thrift-parser
56+
```
57+
58+
Cool, now we need to copy some stuff into the ASTExplorer project.
59+
60+
If the ASTExplorer project and the @creditkarma/thrift-parser project are siblings you can type this into the temrinal (from astexplorer/website)...
61+
62+
```
63+
$ cp -r ../../thrift-parser/astexplorer/thrift ./src/parsers/thrift
64+
```
65+
66+
You'll now need to build ASTExplorer and start the server
67+
68+
```
69+
$ npm run build
70+
$ npm start
71+
```
72+
73+
By default this will start ASTExplorer on localhost:8080
74+
75+
There is a dropdown to select the language you want to use, choose 'Thrift IDL'

astexplorer/thrift/codeExample.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace js test
2+
3+
const string test = 'test'
4+
5+
struct MyStruct {
6+
1: optional string test
7+
}
8+
9+
service MyService {
10+
void ping()
11+
}

astexplorer/thrift/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const id = 'thrift-idl';
2+
export const displayName = 'Thrift IDL';
3+
export const mimeTypes = ['text/x-thrift-idl'];
4+
export const fileExtension = 'thrift';
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import defaultParserInterface from '../utils/defaultParserInterface';
2+
import { parse } from '@creditkarma/thrift-parser';
3+
4+
const ID = 'ck-thrift-parser';
5+
6+
export default {
7+
...defaultParserInterface,
8+
9+
id: ID,
10+
displayName: ID,
11+
version: '0.0.0',
12+
homepage: 'home',
13+
locationProps: new Set(['location']),
14+
15+
loadParser(callback) {
16+
callback((content) => {
17+
return parse(content);
18+
});
19+
},
20+
21+
parse(parser, code) {
22+
return parser(code);
23+
},
24+
25+
getNodeName(node) {
26+
return node.type;
27+
},
28+
29+
nodeToRange({ loc }) {
30+
if (loc !== null && loc !== undefined) {
31+
return [ loc.start.index, loc.end.index ];
32+
}
33+
},
34+
35+
opensByDefault(node, key) {
36+
return node === 'ThriftDocument' || key === 'body';
37+
},
38+
};

0 commit comments

Comments
 (0)