mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-19 09:49:33 -06:00
Add language selectors to JavaScript translator.
This commit is contained in:
@@ -7,17 +7,27 @@ function GFGrammar(abstract, concretes) {
|
||||
/* Translates a string from any concrete syntax to all concrete syntaxes.
|
||||
Uses the start category of the grammar.
|
||||
*/
|
||||
GFGrammar.prototype.translate = function (input) {
|
||||
var outputs = new Array();
|
||||
for (var c1 in this.concretes) {
|
||||
GFGrammar.prototype.translate = function (input, fromLang, toLang) {
|
||||
var outputs = new Object();
|
||||
var fromConcs = this.concretes;
|
||||
if (fromLang) {
|
||||
fromConcs = new Object();
|
||||
fromConcs[fromLang] = this.concretes[fromLang];
|
||||
}
|
||||
var toConcs = this.concretes;
|
||||
if (toLang) {
|
||||
toConcs = new Object();
|
||||
toConcs[toLang] = this.concretes[toLang];
|
||||
}
|
||||
for (var c1 in fromConcs) {
|
||||
var p = this.concretes[c1].parser;
|
||||
if (p) {
|
||||
var trees = p.parseString(input, this.abstract.startcat);
|
||||
if (trees.length > 0) {
|
||||
outputs[c1] = new Array();
|
||||
for (var i in trees) {
|
||||
outputs[c1][i] = new Array();
|
||||
for (var c2 in this.concretes) {
|
||||
outputs[c1][i] = new Object();
|
||||
for (var c2 in toConcs) {
|
||||
outputs[c1][i][c2] = this.concretes[c2].linearize(trees[i]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user