dashboardjavacloudcoapiotiot-analyticsiot-platformiot-solutionskafkalwm2mmicroservicesmiddlewaremqttnettyplatformsnmpthingsboardvisualizationwebsocketswidgets
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.0 KiB
52 lines
1.0 KiB
"use strict";
|
|
const Literal = require("./literal");
|
|
const isLiteral = token => token[0] === "word" && /^\$\{[\s\S]*\}$/.test(token[1]);
|
|
function literal (start) {
|
|
if (!isLiteral(start)) {
|
|
return;
|
|
}
|
|
const tokens = [];
|
|
let hasWord;
|
|
let type;
|
|
let token;
|
|
while ((token = this.tokenizer.nextToken())) {
|
|
tokens.push(token);
|
|
type = token[0];
|
|
if (type.length === 1) {
|
|
break;
|
|
} else if (type === "word") {
|
|
hasWord = true;
|
|
}
|
|
}
|
|
|
|
while (tokens.length) {
|
|
this.tokenizer.back(tokens.pop());
|
|
}
|
|
|
|
if (type === "{" || (type === ":" && !hasWord)) {
|
|
return;
|
|
}
|
|
|
|
const node = new Literal({
|
|
text: start[1],
|
|
});
|
|
|
|
this.init(node, start[2], start[3]);
|
|
|
|
return node;
|
|
}
|
|
|
|
function freeSemicolon (token) {
|
|
this.spaces += token[1];
|
|
const nodes = this.current.nodes;
|
|
const prev = nodes && nodes[nodes.length - 1];
|
|
if (prev && /^(rule|literal)$/.test(prev.type) && !prev.raws.ownSemicolon) {
|
|
prev.raws.ownSemicolon = this.spaces;
|
|
this.spaces = "";
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
freeSemicolon: freeSemicolon,
|
|
literal: literal,
|
|
};
|
|
|