Skip to content

Commit 62ec637

Browse files
committed
Merge pull request #1 from minicast/addGetLatex
Add parser build
2 parents c552df0 + 6ce7217 commit 62ec637

File tree

5 files changed

+2085
-30
lines changed

5 files changed

+2085
-30
lines changed

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
},
99
"main": "dist/index.js",
1010
"scripts": {
11-
"prebuild": "rm -rf dist && mkdir dist",
12-
"build": "babel src/index.js -o dist/index.js",
13-
"postbuild": "cp src/qmlStructureGrammar.pegjs dist/qmlStructureGrammar.pegjs",
11+
"prebuild": "rm -rf dist && mkdir dist && rm src/qmlStructureParser.js",
12+
"build": "babel src/index.js -o dist/index.js && pegjs src/qmlStructureGrammar.pegjs src/qmlStructureParser.js",
13+
"postbuild": "cp src/qmlStructureParser.js dist/qmlStructureParser.js",
1414
"commit": "git-cz",
1515
"test": "istanbul cover -x *.test.js _mocha -- -R spec src/index.test.js --compilers js:babel/register",
1616
"test:watch": "mocha src/index.test.js -w --compilers js:babel/register",
17-
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
17+
"check-coverage": "istanbul check-coverage --statements 50 --branches 50 --functions 50 --lines 50",
1818
"report-coverage": "cat ./coverage/lcov.info | codecov",
19-
"semantic-release": "semantic-release pre && npm publish && semantic-release post"
19+
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
20+
"pegjs": "rm src/qmlStructureParser.js && pegjs src/qmlStructureGrammar.pegjs src/qmlStructureParser.js"
2021
},
2122
"repository": {
2223
"type": "git",

src/index.js

+9-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
// const fs = require("fs");
55
import fs from "fs";
6-
const PEG = require("pegjs");
7-
const _ = require("lodash");
8-
9-
const qmlStructureGrammar = fs.readFileSync(
10-
"./src/qmlStructureGrammar.pegjs",
11-
"utf8"
12-
);
13-
const qmlStructureParser = PEG.buildParser(qmlStructureGrammar);
6+
import _ from "lodash";
7+
// const PEG = require("pegjs");
8+
const qmlStructureParser = require("./qmlStructureParser.js");
9+
10+
// const qmlStructureGrammar = fs.readFileSync(
11+
// "./src/qmlStructureGrammar.pegjs",
12+
// "utf8"
13+
// );
14+
// const qmlStructureParser = PEG.buildParser(qmlStructureGrammar);
1415

1516
const getMetadomain = (structure) => {
1617
return structure.map((x) => {

src/index.test.js

+83
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,89 @@ describe("qmlStructureParser", function () {
5656
)
5757
);
5858
});
59+
60+
it("should throw on badly formed input", function () {
61+
const illFormedInput = function() {
62+
qmlStructure.parser.parse(`badInput`);
63+
};
64+
expect(illFormedInput).to.throw();
65+
});
66+
67+
it("should (not yet) parse input with 3 and 4 tuples", function () {
68+
const input3and4 = function() {
69+
qmlStructure.parser.parse(`{
70+
w1(
71+
{a,b,c,d},
72+
{P,R0},
73+
{
74+
P{a},
75+
R1{a,b}
76+
},
77+
{
78+
R2{(a,b)},
79+
S{(a,b),(b,a)}
80+
},
81+
{
82+
R3{(a,b,c),(b,c,a)}
83+
},
84+
{
85+
R2{(a,b,c,d),(a,d,b,c)}
86+
},
87+
{w1,w2}
88+
)
89+
}`);
90+
};
91+
// expect(input3and4).to.not.throw();
92+
expect(input3and4).to.throw();
93+
});
94+
95+
it("should fail on malformed inputs", function () {
96+
const malformedInput1 = function() {
97+
qmlStructure.parser.parse(`{
98+
w1(
99+
{a,b,c,d},
100+
{P,R0},
101+
{
102+
R1{a,b}
103+
},
104+
{
105+
S{(a,b),(b,a)}
106+
},
107+
{w1,w2}
108+
),X
109+
}`);
110+
};
111+
expect(malformedInput1).to.throw();
112+
});
113+
it("should not fail on well formed inputs", function () {
114+
const wellFormedInput1 = function() {
115+
qmlStructure.parser.parse(`{
116+
w1(
117+
{a,b,c,d},
118+
{P,R0},
119+
{
120+
R1{a,b}
121+
},
122+
{
123+
S{(a,b),(b,a)}
124+
},
125+
{w1,w2}
126+
),
127+
w2(
128+
{a},
129+
{P},
130+
{
131+
R1{a,b}
132+
},
133+
{
134+
S{(a,b),(b,a)}
135+
},
136+
{w1,w2}
137+
)
138+
}`);
139+
};
140+
expect(wellFormedInput1).to.not.throw();
141+
});
59142
});
60143
describe("getD3", function () {
61144
it("should return a D3 force layout graph", function () {

src/qmlStructureGrammar.pegjs

+16-17
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,24 @@ possibleWorld "possibleWorld"
5252
}
5353
}
5454

55-
metanominalsSet "metanominalsSet"
56-
= "{" metanominalsList:metanominalsList "}" {
57-
return metanominalsList
58-
}
55+
// metanominalsSet "metanominalsSet"
56+
// = "{" metanominalsList:metanominalsList "}" {
57+
// return metanominalsList
58+
// }
5959

6060
metanominalsList "metanominalsList"
6161
= head:(metanominal)* tail:("," metanominal)* {
6262
return head.concat(tail.map((x) => x[1]))
6363
}
6464

65-
tuple4 "tuple4"
66-
= "(" constant "," constant "," constant "," constant ")" {
67-
return "(" + c1 + "," + c2 + ")"
68-
}
69-
tuple3 "tuple3"
70-
= "(" constant "," constant "," constant ")" {
71-
return "(" + c1 + "," + c2 + ")"
72-
}
65+
// tuple4 "tuple4"
66+
// = "(" constant "," constant "," constant "," constant ")" {
67+
// return "(" + c1 + "," + c2 + ")"
68+
// }
69+
// tuple3 "tuple3"
70+
// = "(" constant "," constant "," constant ")" {
71+
// return "(" + c1 + "," + c2 + ")"
72+
// }
7373

7474
binaryExtensionsList "binaryExtensionsList"
7575
= _ head:(binaryExtension)* _ tail:("," binaryExtension)* _ {
@@ -100,10 +100,10 @@ tuple2 "tuple2"
100100
return "(" + c1 + "," + c2 + ")"
101101
}
102102

103-
unaryExtensionsSet "unaryExtensionsSet"
104-
= _ "{" _ unaryExtensionsList:unaryExtensionsList _ "}" _ {
105-
return { unaryExtensions: unaryExtensionsList }
106-
}
103+
// unaryExtensionsSet "unaryExtensionsSet"
104+
// = _ "{" _ unaryExtensionsList:unaryExtensionsList _ "}" _ {
105+
// return { unaryExtensions: unaryExtensionsList }
106+
// }
107107

108108
unaryExtensionsList "unaryExtensionsList"
109109
= _ head:(unaryExtension)* _ tail:("," unaryExtension)* _ {
@@ -141,7 +141,6 @@ constantsList "constantsList"
141141
return head.concat(tail.map((x) => x[1]))
142142
}
143143

144-
145144
metanominal "metanominal"
146145
= metanominalString:[wvtl]+ index:index {
147146
return metanominalString.join("") + index

0 commit comments

Comments
 (0)