Skip to content

Commit

Permalink
parser: delete code parsing logic
Browse files Browse the repository at this point in the history
Pugneum will be fully static and will have no support for this.
No need to keep this code around.
  • Loading branch information
matheusmoreira committed Aug 27, 2023
1 parent 316ca17 commit 1d9c373
Showing 1 changed file with 0 additions and 285 deletions.
285 changes: 0 additions & 285 deletions packages/pug-parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,255 +440,6 @@ Parser.prototype = {
}
},

/**
* case
*/

parseCase: function() {
var tok = this.expect('case');
var node = {
type: 'Case',
expr: tok.val,
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};

var block = this.emptyBlock(tok.loc.start.line + 1);
this.expect('indent');
while ('outdent' != this.peek().type) {
switch (this.peek().type) {
case 'comment':
case 'newline':
this.advance();
break;
case 'when':
block.nodes.push(this.parseWhen());
break;
case 'default':
block.nodes.push(this.parseDefault());
break;
default:
var pluginResult = this.runPlugin('caseTokens', this.peek(), block);
if (pluginResult) break;
this.error(
'INVALID_TOKEN',
'Unexpected token "' +
this.peek().type +
'", expected "when", "default" or "newline"',
this.peek()
);
}
}
this.expect('outdent');

node.block = block;

return node;
},

/**
* when
*/

parseWhen: function() {
var tok = this.expect('when');
if (this.peek().type !== 'newline') {
return {
type: 'When',
expr: tok.val,
block: this.parseBlockExpansion(),
debug: false,
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};
} else {
return {
type: 'When',
expr: tok.val,
debug: false,
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};
}
},

/**
* default
*/

parseDefault: function() {
var tok = this.expect('default');
return {
type: 'When',
expr: 'default',
block: this.parseBlockExpansion(),
debug: false,
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};
},

/**
* code
*/

parseCode: function(noBlock) {
var tok = this.expect('code');
assert(
typeof tok.mustEscape === 'boolean',
'Please update to the newest version of pugneum-lexer.'
);
var node = {
type: 'Code',
val: tok.val,
buffer: tok.buffer,
mustEscape: tok.mustEscape !== false,
isInline: !!noBlock,
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};
// todo: why is this here? It seems like a hacky workaround
if (node.val.match(/^ *else/)) node.debug = false;

if (noBlock) return node;

var block;

// handle block
block = 'indent' == this.peek().type;
if (block) {
if (tok.buffer) {
this.error(
'BLOCK_IN_BUFFERED_CODE',
'Buffered code cannot have a block attached to it',
this.peek()
);
}
node.block = this.block();
}

return node;
},
parseConditional: function() {
var tok = this.expect('if');
var node = {
type: 'Conditional',
test: tok.val,
consequent: this.emptyBlock(tok.loc.start.line),
alternate: null,
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};

// handle block
if ('indent' == this.peek().type) {
node.consequent = this.block();
}

var currentNode = node;
while (true) {
if (this.peek().type === 'newline') {
this.expect('newline');
} else if (this.peek().type === 'else-if') {
tok = this.expect('else-if');
currentNode = currentNode.alternate = {
type: 'Conditional',
test: tok.val,
consequent: this.emptyBlock(tok.loc.start.line),
alternate: null,
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};
if ('indent' == this.peek().type) {
currentNode.consequent = this.block();
}
} else if (this.peek().type === 'else') {
this.expect('else');
if (this.peek().type === 'indent') {
currentNode.alternate = this.block();
}
break;
} else {
break;
}
}

return node;
},
parseWhile: function() {
var tok = this.expect('while');
var node = {
type: 'While',
test: tok.val,
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};

// handle block
if ('indent' == this.peek().type) {
node.block = this.block();
} else {
node.block = this.emptyBlock(tok.loc.start.line);
}

return node;
},

/**
* block code
*/

parseBlockCode: function() {
var tok = this.expect('blockcode');
var line = tok.loc.start.line;
var column = tok.loc.start.column;
var body = this.peek();
var text = '';
if (body.type === 'start-pipeless-text') {
this.advance();
while (this.peek().type !== 'end-pipeless-text') {
tok = this.advance();
switch (tok.type) {
case 'text':
text += tok.val;
break;
case 'newline':
text += '\n';
break;
default:
var pluginResult = this.runPlugin('blockCodeTokens', tok, tok);
if (pluginResult) {
text += pluginResult;
break;
}
this.error(
'INVALID_TOKEN',
'Unexpected token type: ' + tok.type,
tok
);
}
}
this.advance();
}
return {
type: 'Code',
val: text,
buffer: false,
mustEscape: false,
isInline: false,
line: line,
column: column,
filename: this.filename,
};
},
/**
* comment
*/
Expand Down Expand Up @@ -792,42 +543,6 @@ Parser.prototype = {
};
},

/**
* each block
*/

parseEach: function() {
var tok = this.expect('each');
var node = {
type: 'Each',
obj: tok.code,
val: tok.val,
key: tok.key,
block: this.block(),
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};
if (this.peek().type == 'else') {
this.advance();
node.alternate = this.block();
}
return node;
},

parseEachOf: function() {
var tok = this.expect('eachOf');
var node = {
type: 'EachOf',
obj: tok.code,
val: tok.val,
block: this.block(),
line: tok.loc.start.line,
column: tok.loc.start.column,
filename: this.filename,
};
return node;
},
/**
* 'extends' name
*/
Expand Down

0 comments on commit 1d9c373

Please sign in to comment.