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

Commit 4f84db6

Browse files
Adding lexical info to RAML tokens
Signed-off-by: Antonio Garrote <antoniogarrote@gmail.com>
1 parent b563994 commit 4f84db6

File tree

14 files changed

+450
-67
lines changed

14 files changed

+450
-67
lines changed

js/js-support-bundle.js

Lines changed: 115 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ function mergeMappings(state, destination, source, overridableKeys) {
12451245
function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode) {
12461246
var index, quantity;
12471247

1248-
keyNode = String(keyNode);
1248+
keyNode = String(keyNode["amf-lexical-token"]);
12491249

12501250
if (_result === null) {
12511251
_result = {};
@@ -1350,7 +1350,6 @@ function testDocumentSeparator(state) {
13501350
return true;
13511351
}
13521352
}
1353-
13541353
return false;
13551354
}
13561355

@@ -1376,6 +1375,10 @@ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
13761375
_result = state.result,
13771376
ch;
13781377

1378+
var startLine = state.line;
1379+
var startColumn = state.lineStart;
1380+
var startIndex = state.position;
1381+
13791382
ch = state.input.charCodeAt(state.position);
13801383

13811384
if (is_WS_OR_EOL(ch) ||
@@ -1464,18 +1467,46 @@ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
14641467
captureSegment(state, captureStart, captureEnd, false);
14651468

14661469
if (state.result) {
1470+
var endLine = state.line;
1471+
var endColumn = state.position - state.lineStart;
1472+
var endIndex = state.position;
1473+
1474+
var positions = {
1475+
"start-line": startLine,
1476+
"start-column": startColumn,
1477+
"start-index": startIndex,
1478+
"end-line": endLine,
1479+
"end-column": endColumn,
1480+
"end-index": endIndex
1481+
};
1482+
state.kind = _kind;
1483+
if (state.result === 'null') {
1484+
state.result = null;
1485+
}
1486+
if (state.result === 'true') {
1487+
state.result = true;
1488+
}
1489+
if (state.result === 'false') {
1490+
state.result = false;
1491+
}
1492+
state.result = {
1493+
"amf-lexical-token": state.result,
1494+
"__location__": positions
1495+
};
1496+
14671497
return true;
14681498
}
1469-
1470-
state.kind = _kind;
1471-
state.result = _result;
14721499
return false;
14731500
}
14741501

14751502
function readSingleQuotedScalar(state, nodeIndent) {
14761503
var ch,
14771504
captureStart, captureEnd;
14781505

1506+
var startLine = state.line;
1507+
var startColumn = state.lineStart;
1508+
var startIndex = state.position;
1509+
14791510
ch = state.input.charCodeAt(state.position);
14801511

14811512
if (ch !== 0x27/* ' */) {
@@ -1497,6 +1528,24 @@ function readSingleQuotedScalar(state, nodeIndent) {
14971528
state.position++;
14981529
captureEnd = state.position;
14991530
} else {
1531+
1532+
var endLine = state.line;
1533+
var endColumn = state.position - state.lineStart;
1534+
var endIndex = state.position;
1535+
1536+
var positions = {
1537+
"start-line": startLine,
1538+
"start-column": startColumn,
1539+
"start-index": startIndex,
1540+
"end-line": endLine,
1541+
"end-column": endColumn,
1542+
"end-index": endIndex
1543+
};
1544+
1545+
state.result = {
1546+
"amf-lexical-token": state.result,
1547+
"__location__": positions
1548+
};
15001549
return true;
15011550
}
15021551

@@ -1525,6 +1574,10 @@ function readDoubleQuotedScalar(state, nodeIndent) {
15251574
tmp,
15261575
ch;
15271576

1577+
var startLine = state.line;
1578+
var startColumn = state.lineStart;
1579+
var startIndex = state.position;
1580+
15281581
ch = state.input.charCodeAt(state.position);
15291582

15301583
if (ch !== 0x22/* " */) {
@@ -1540,6 +1593,25 @@ function readDoubleQuotedScalar(state, nodeIndent) {
15401593
if (ch === 0x22/* " */) {
15411594
captureSegment(state, captureStart, state.position, true);
15421595
state.position++;
1596+
1597+
var endLine = state.line;
1598+
var endColumn = state.position - state.lineStart;
1599+
var endIndex = state.position;
1600+
1601+
var positions = {
1602+
"start-line": startLine,
1603+
"start-column": startColumn,
1604+
"start-index": startIndex,
1605+
"end-line": endLine,
1606+
"end-column": endColumn,
1607+
"end-index": endIndex
1608+
};
1609+
1610+
state.result = {
1611+
"amf-lexical-token": state.result,
1612+
"__location__": positions
1613+
};
1614+
15431615
return true;
15441616

15451617
} else if (ch === 0x5C/* \ */) {
@@ -1713,6 +1785,10 @@ function readBlockScalar(state, nodeIndent) {
17131785
tmp,
17141786
ch;
17151787

1788+
var startLine = state.line;
1789+
var startColumn = state.lineStart;
1790+
var startIndex = state.position;
1791+
17161792
ch = state.input.charCodeAt(state.position);
17171793

17181794
if (ch === 0x7C/* | */) {
@@ -1841,6 +1917,24 @@ function readBlockScalar(state, nodeIndent) {
18411917
captureSegment(state, captureStart, state.position, false);
18421918
}
18431919

1920+
var endLine = state.line;
1921+
var endColumn = state.position - state.lineStart;
1922+
var endIndex = state.position;
1923+
1924+
var positions = {
1925+
"start-line": startLine,
1926+
"start-column": startColumn,
1927+
"start-index": startIndex,
1928+
"end-line": endLine,
1929+
"end-column": endColumn,
1930+
"end-index": endIndex
1931+
};
1932+
1933+
state.result = {
1934+
"amf-lexical-token": state.result,
1935+
"__location__": positions
1936+
};
1937+
18441938
return true;
18451939
}
18461940

@@ -2379,16 +2473,26 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
23792473
}
23802474
}
23812475
} else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
2476+
var isLexicaltoken = false;
2477+
var lexicalLocation = null;
2478+
if (state.result && state.result["amf-lexical-token"]) {
2479+
lexicalLocation = state.result["__location__"];
2480+
state.result = state.result["amf-lexical-token"];
2481+
isLexicaltoken = true;
2482+
}
23822483
type = state.typeMap[state.kind || 'fallback'][state.tag];
23832484

2384-
if (state.result !== null && type.kind !== state.kind) {
2485+
if (!isLexicaltoken && state.result !== null && type.kind !== state.kind) {
23852486
throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
23862487
}
23872488

23882489
if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched
23892490
throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
23902491
} else {
23912492
state.result = type.construct(state.result);
2493+
if (lexicalLocation != null) {
2494+
state.result["__location__"] = lexicalLocation;
2495+
}
23922496
if (state.anchor !== null) {
23932497
state.anchorMap[state.anchor] = state.result;
23942498
}
@@ -4115,7 +4219,11 @@ var collectLibraries = function (fragment, location) {
41154219
var libraries = fragment.uses || {};
41164220
for (var p in libraries) {
41174221
if (p !== "__location__") {
4118-
var resolvedLocation = resolvePath(location, libraries[p]);
4222+
var value = libraries[p];
4223+
if (typeof(value) === "object" && value["amf-lexical-token"]) {
4224+
value = value["amf-lexical-token"];
4225+
}
4226+
var resolvedLocation = resolvePath(location, value);
41194227
PENDING_LIBRARIES.push({
41204228
"path": libraries[p],
41214229
"location": resolvedLocation,
@@ -4211,12 +4319,8 @@ global.JS_YAML.parseYamlFile = parseYamlFile;
42114319
global.JS_YAML.parseYamlString = parseYamlString;
42124320
global.JS_YAML.dump = yaml.dump;
42134321
global.JS_REST = function (location) {
4214-
console.log("USING PROXY?");
42154322
if (typeof (global.JS_USE_PROXY) !== "undefined") {
4216-
console.log("YES: " + global.JS_USE_PROXY.replace("$URL", encodeURIComponent(location)));
42174323
location = global.JS_USE_PROXY.replace("$URL", encodeURIComponent(location));
4218-
} else {
4219-
console.log("NOPE!");
42204324
}
42214325
return rest(location);
42224326
};

0 commit comments

Comments
 (0)