Skip to content

Commit

Permalink
Merge pull request #67 from stanford-oval/wip/genie-templates
Browse files Browse the repository at this point in the history
Make it possible to bundle Genie templates
  • Loading branch information
gcampax authored Jul 29, 2019
2 parents 370a27c + 07e3234 commit bc9b4f2
Show file tree
Hide file tree
Showing 20 changed files with 67 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*~
node_modules/
coverage/
bundle/
.nyc_output/
.idea/

Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
bundle/%: languages/%/*.genie languages/*.genie languages/*.js
mkdir -p $@
cp -r languages/$* languages/*.genie languages/*.js $@
echo "import '$*/thingtalk.genie';" > $@/index.genie
touch $@

bundle/%.zip: bundle/%
cd $< ; zip -r ../$*.zip *

all: bundle/en.zip bundle/zh-tw.zip
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Type = ThingTalk.Type;
const { isUnaryTableToTableOp,
isUnaryStreamToTableOp,
isUnaryStreamToStreamOp,
isUnaryTableToStreamOp } = require('../utils');
isUnaryTableToStreamOp } = require('./utils');
const { notifyAction } = ThingTalk.Generate;

function typeToStringSafe(type) {
Expand Down
2 changes: 1 addition & 1 deletion languages/common-parameters.genie
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{
// import the combinator library
const C = require('../lib/sentence-generator/ast_manip');
const C = require('./ast_manip');
}

out_param_Numeric = {
Expand Down
3 changes: 1 addition & 2 deletions languages/en/aggregation.genie
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const Generate = ThingTalk.Generate;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');
}

projection_Number = {
Expand Down
2 changes: 1 addition & 1 deletion languages/en/bookkeeping.genie
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');

function special(specialType) {
return new Ast.Input.Bookkeeping(new Ast.BookkeepingIntent.Special(specialType));
Expand Down
3 changes: 1 addition & 2 deletions languages/en/constants.genie
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');
}

constant_Number = {
Expand Down
3 changes: 1 addition & 2 deletions languages/en/contextual.genie
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');

function addParamToAction(command, pname, joinArg) {
let actiontype = command.action.schema.inReq[pname];
Expand Down
3 changes: 1 addition & 2 deletions languages/en/filters.genie
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');
}

// generic filters (npp)
Expand Down
3 changes: 1 addition & 2 deletions languages/en/parameters.genie
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');
}

import '../common-parameters';
Expand Down
2 changes: 1 addition & 1 deletion languages/en/stream_tables.genie
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');

}

Expand Down
2 changes: 1 addition & 1 deletion languages/en/thingtalk.genie
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');

}

Expand Down
2 changes: 1 addition & 1 deletion languages/en/who_questions.genie
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');

}

Expand Down
39 changes: 39 additions & 0 deletions languages/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Genie
//
// Copyright 2015-2019 The Board of Trustees of the Leland Stanford Junior University
// 2019 National Taiwan University
//
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>
// Elvis Yu-Jing Lin <r06922068@ntu.edu.tw> <elvisyjlin@gmail.com>
//
// See COPYING for details
"use strict";

module.exports = {
isUnaryTableToTableOp(table) {
return table.isFilter ||
table.isProjection ||
table.isCompute ||
table.isAlias ||
table.isAggregation ||
table.isArgMinMax ||
table.isSequence ||
table.isHistory;
},
isUnaryStreamToTableOp(table) {
return table.isWindow || table.isTimeSeries;
},
isUnaryStreamToStreamOp(stream) {
return stream.isEdgeNew ||
stream.isEdgeFilter ||
stream.isFilter ||
stream.isProjection ||
stream.isCompute ||
stream.isAlias;
},
isUnaryTableToStreamOp(stream) {
return stream.isMonitor;
}
};
3 changes: 1 addition & 2 deletions languages/zh-tw/aggregation.genie
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const Generate = ThingTalk.Generate;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');
}

projection_Number = {
Expand Down
3 changes: 1 addition & 2 deletions languages/zh-tw/constants.genie
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');
}

constant_Number = {
Expand Down
3 changes: 1 addition & 2 deletions languages/zh-tw/filters.genie
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');
}

atom_filter = {
Expand Down
3 changes: 1 addition & 2 deletions languages/zh-tw/parameters.genie
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const { clean } = require('../../lib/utils');

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');
}

import '../common-parameters';
Expand Down
2 changes: 1 addition & 1 deletion languages/zh-tw/thingtalk.genie
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;

// import the combinator library
const C = require('../../lib/sentence-generator/ast_manip');
const C = require('../ast_manip');

}

Expand Down
2 changes: 1 addition & 1 deletion lib/sentence-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const { clean, makeDummyEntities } = require('../utils');

const $runtime = require('./runtime');
const importGenie = require('../genie-compiler');
const { typeToStringSafe } = require('./ast_manip');
const { typeToStringSafe } = require('../../languages/ast_manip');
const i18n = require('../i18n');

function identity(x) {
Expand Down

0 comments on commit bc9b4f2

Please sign in to comment.