Skip to content

Commit 92d3b9f

Browse files
committed
Генерация предупреждений для не поддерживаемых возможностей.
1 parent ffa4534 commit 92d3b9f

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

src/passes/generate.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
var arrays = require("pegjs/lib/utils/arrays"),
22
objects = require("pegjs/lib/utils/objects"),
33
asts = require("pegjs/lib/compiler/asts"),
4-
visitor = require("pegjs/lib/compiler/visitor");
4+
visitor = require("pegjs/lib/compiler/visitor"),
5+
GrammarError = require("pegjs/lib/grammar-error");
6+
7+
function generateCCode(ast, options) {
8+
function emitWarning(message, value, region) {
9+
// В оригинальном pegjs нет ни region-а у узлов (#225), ни коллектора ошибок (#243),
10+
// поэтому проверяем их наличие, прежде, чем воспользоваться.
11+
if (region) {
12+
message = 'Line ' + region.begin.line + ', column ' + region.begin.column + ': ' + message;
13+
}
14+
if (options.collector) {
15+
options.collector.emitWarning(message);
16+
} else {
17+
throw new GrammarError(message + ' (' + JSON.stringify(value) + ')');
18+
}
19+
}
520

6-
function generateCCode(ast) {
721
function CodeBuilder(code) {
822
var _indent = [];
923
var _indentCache = '';
@@ -552,6 +566,12 @@ function generateCCode(ast) {
552566
},
553567

554568
literal: function(node, context) {
569+
if (node.ignoreCase) {
570+
emitWarning("Case insensitive matching not supported", node.value, node.region);
571+
}
572+
if (/[^\x00-\xFF]/g.test(node.value)) {
573+
emitWarning("Unicode symbols not supported", node.value, node.region);
574+
}
555575
var v = literals.add(node.value);
556576
var e = expected.add(
557577
'LITERAL',
@@ -563,6 +583,9 @@ function generateCCode(ast) {
563583
},
564584

565585
"class": function(node, context) {
586+
if (node.ignoreCase) {
587+
emitWarning("Case insensitive matching not supported", node.rawText, node.region);
588+
}
566589
var v = charClasses.add(node.parts);
567590
var e = expected.add('CLASS', node.rawText, node.rawText);
568591
// Помещаем результат разбора класса символов на вершину стека результатов.

0 commit comments

Comments
 (0)