hdl-js
Version:
Hardware definition language (HDL) and Hardware simulator
759 lines (649 loc) • 23.7 kB
JavaScript
/**
* LR parser generated by the Syntax tool.
*
* https://www.npmjs.com/package/syntax-cli
*
* npm install -g syntax-cli
*
* syntax-cli --help
*
* To regenerate run:
*
* syntax-cli \
* --grammar ~/path-to-grammar-file \
* --mode <parsing-mode> \
* --output ~/path-to-output-parser-file.js
*/
;
/**
* Matched token text.
*/
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var yytext = void 0;
/**
* Length of the matched token text.
*/
var yyleng = void 0;
/**
* Storage object.
*/
var yy = {};
/**
* Result of semantic action.
*/
var __ = void 0;
/**
* Result location object.
*/
var __loc = void 0;
function yyloc(start, end) {
if (!yy.options.captureLocations) {
return null;
}
// Epsilon doesn't produce location.
if (!start || !end) {
return start || end;
}
return {
startOffset: start.startOffset,
endOffset: end.endOffset,
startLine: start.startLine,
endLine: end.endLine,
startColumn: start.startColumn,
endColumn: end.endColumn
};
}
var EOF = '$';
/**
* List of productions (generated by Syntax tool).
*/
var productions = [[-1, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [0, 5, function (_1, _2, _3, _4, _5, _1loc, _2loc, _3loc, _4loc, _5loc) {
__loc = yyloc(_1loc, _5loc);
__ = {
type: 'Chip',
name: _2,
inputs: inputs,
outputs: outputs,
parts: parts,
builtins: builtins,
clocked: clocked
};
}], [1, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [1, 2], [2, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [2, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [2, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [2, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [2, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [3, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
var _inputs;
__loc = yyloc(_1loc, _3loc);
(_inputs = inputs).push.apply(_inputs, _toConsumableArray(subscriptListToProp(_2, 'size')));
}], [4, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
var _outputs;
__loc = yyloc(_1loc, _3loc);
(_outputs = outputs).push.apply(_outputs, _toConsumableArray(subscriptListToProp(_2, 'size')));
}], [5, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
var _parts;
__loc = yyloc(_1loc, _3loc);
(_parts = parts).push.apply(_parts, _toConsumableArray(_3));
}], [6, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
var _builtins;
__loc = yyloc(_1loc, _3loc);
(_builtins = builtins).push.apply(_builtins, _toConsumableArray(_2));
}], [7, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
var _clocked;
__loc = yyloc(_1loc, _3loc);
(_clocked = clocked).push.apply(_clocked, _toConsumableArray(_2));
}], [8, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = [_1];
}], [8, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
__loc = yyloc(_1loc, _3loc);_1.push(_3);__ = _1;
}], [9, 2, function (_1, _2, _1loc, _2loc) {
__loc = yyloc(_1loc, _2loc);
__ = {
type: 'Name',
value: _1
};
if (_2) {
__.subscript = _2;
}
}], [10, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [10, 0], [11, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
__loc = yyloc(_1loc, _3loc);
__ = _2;
}], [12, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);
__ = {
kind: 'number',
value: Number(_1)
};
}], [12, 4, function (_1, _2, _3, _4, _1loc, _2loc, _3loc, _4loc) {
__loc = yyloc(_1loc, _4loc);
__ = {
kind: 'range',
from: Number(_1),
to: Number(_4)
};
}], [13, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [13, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [14, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [15, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [15, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [15, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [15, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [15, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [15, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [16, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = [_1];
}], [16, 2, function (_1, _2, _1loc, _2loc) {
__loc = yyloc(_1loc, _2loc);_1.push(_2);__ = _1;
}], [17, 5, function (_1, _2, _3, _4, _5, _1loc, _2loc, _3loc, _4loc, _5loc) {
__loc = yyloc(_1loc, _5loc);
__ = {
type: 'ChipCall',
name: _1,
arguments: _3
};
}], [18, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = [_1];
}], [18, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
__loc = yyloc(_1loc, _3loc);_1.push(_3);__ = _1;
}], [19, 3, function (_1, _2, _3, _1loc, _2loc, _3loc) {
__loc = yyloc(_1loc, _3loc);
__ = {
type: 'Argument',
name: subscriptToProp(_1, 'index'),
value: subscriptToProp(_3, 'index')
};
}], [20, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);__ = _1;
}], [20, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);
var constName = null;
if (_1.value === 'true') {
constName = 1;
} else if (_1.value === 'false') {
constName = 0;
}
if (constName !== null) {
__ = {
type: 'Constant',
value: constName,
raw: _1.value
};
} else {
// Other name:
__ = _1;
}
}], [21, 1, function (_1, _1loc) {
__loc = yyloc(_1loc, _1loc);
__ = {
type: 'Constant',
value: Number(_1),
raw: _1
};
}]];
/**
* Encoded tokens map.
*/
var tokens = { "CHIP": "22", "IN": "23", "OUT": "24", "PARTS": "25", "BUILTIN": "26", "CLOCKED": "27", "NUMBER": "28", "ID": "29", "'{'": "30", "'}'": "31", "';'": "32", "':'": "33", "','": "34", "'['": "35", "']'": "36", "'.'": "37", "'('": "38", "')'": "39", "'='": "40", "$": "41" };
/**
* Parsing table (generated by Syntax tool).
*/
var table = [{ "0": 1, "22": "s2" }, { "41": "acc" }, { "14": 3, "29": "s4" }, { "30": "s5" }, { "30": "r24", "38": "r24" }, { "1": 6, "2": 7, "3": 8, "4": 9, "5": 10, "6": 11, "7": 12, "23": "s13", "24": "s14", "25": "s15", "26": "s16", "27": "s17" }, { "2": 19, "3": 8, "4": 9, "5": 10, "6": 11, "7": 12, "23": "s13", "24": "s14", "25": "s15", "26": "s16", "27": "s17", "31": "s18" }, { "23": "r2", "24": "r2", "25": "r2", "26": "r2", "27": "r2", "31": "r2" }, { "23": "r4", "24": "r4", "25": "r4", "26": "r4", "27": "r4", "31": "r4" }, { "23": "r5", "24": "r5", "25": "r5", "26": "r5", "27": "r5", "31": "r5" }, { "23": "r6", "24": "r6", "25": "r6", "26": "r6", "27": "r6", "31": "r6" }, { "23": "r7", "24": "r7", "25": "r7", "26": "r7", "27": "r7", "31": "r7" }, { "23": "r8", "24": "r8", "25": "r8", "26": "r8", "27": "r8", "31": "r8" }, { "8": 20, "9": 21, "13": 22, "15": 24, "22": "s25", "23": "s26", "24": "s27", "25": "s28", "26": "s29", "27": "s30", "29": "s23" }, { "8": 43, "9": 21, "13": 22, "15": 24, "22": "s25", "23": "s26", "24": "s27", "25": "s28", "26": "s29", "27": "s30", "29": "s23" }, { "33": "s45" }, { "8": 63, "9": 21, "13": 22, "15": 24, "22": "s25", "23": "s26", "24": "s27", "25": "s28", "26": "s29", "27": "s30", "29": "s23" }, { "8": 65, "9": 21, "13": 22, "15": 24, "22": "s25", "23": "s26", "24": "s27", "25": "s28", "26": "s29", "27": "s30", "29": "s23" }, { "41": "r1" }, { "23": "r3", "24": "r3", "25": "r3", "26": "r3", "27": "r3", "31": "r3" }, { "32": "s31", "34": "s32" }, { "32": "r14", "34": "r14" }, { "10": 34, "11": 35, "32": "r18", "34": "r18", "35": "s36", "39": "r18", "40": "r18" }, { "32": "r22", "34": "r22", "35": "r22", "39": "r22", "40": "r22" }, { "32": "r23", "34": "r23", "35": "r23", "39": "r23", "40": "r23" }, { "32": "r25", "34": "r25", "35": "r25", "39": "r25", "40": "r25" }, { "32": "r26", "34": "r26", "35": "r26", "39": "r26", "40": "r26" }, { "32": "r27", "34": "r27", "35": "r27", "39": "r27", "40": "r27" }, { "32": "r28", "34": "r28", "35": "r28", "39": "r28", "40": "r28" }, { "32": "r29", "34": "r29", "35": "r29", "39": "r29", "40": "r29" }, { "32": "r30", "34": "r30", "35": "r30", "39": "r30", "40": "r30" }, { "23": "r9", "24": "r9", "25": "r9", "26": "r9", "27": "r9", "31": "r9" }, { "9": 33, "13": 22, "15": 24, "22": "s25", "23": "s26", "24": "s27", "25": "s28", "26": "s29", "27": "s30", "29": "s23" }, { "32": "r15", "34": "r15" }, { "32": "r16", "34": "r16", "39": "r16", "40": "r16" }, { "32": "r17", "34": "r17", "39": "r17", "40": "r17" }, { "12": 37, "28": "s38" }, { "36": "s39" }, { "36": "r20", "37": "s40" }, { "32": "r19", "34": "r19", "39": "r19", "40": "r19" }, { "37": "s41" }, { "28": "s42" }, { "36": "r21" }, { "32": "s44", "34": "s32" }, { "23": "r10", "24": "r10", "25": "r10", "26": "r10", "27": "r10", "31": "r10" }, { "14": 48, "16": 46, "17": 47, "29": "s4" }, { "14": 48, "17": 49, "23": "r11", "24": "r11", "25": "r11", "26": "r11", "27": "r11", "29": "s4", "31": "r11" }, { "23": "r31", "24": "r31", "25": "r31", "26": "r31", "27": "r31", "29": "r31", "31": "r31" }, { "38": "s50" }, { "23": "r32", "24": "r32", "25": "r32", "26": "r32", "27": "r32", "29": "r32", "31": "r32" }, { "9": 53, "13": 22, "15": 24, "18": 51, "19": 52, "22": "s25", "23": "s26", "24": "s27", "25": "s28", "26": "s29", "27": "s30", "29": "s23" }, { "34": "s55", "39": "s54" }, { "34": "r34", "39": "r34" }, { "40": "s58" }, { "32": "s56" }, { "9": 53, "13": 22, "15": 24, "19": 57, "22": "s25", "23": "s26", "24": "s27", "25": "s28", "26": "s29", "27": "s30", "29": "s23" }, { "23": "r33", "24": "r33", "25": "r33", "26": "r33", "27": "r33", "29": "r33", "31": "r33" }, { "34": "r35", "39": "r35" }, { "9": 61, "13": 22, "15": 24, "20": 59, "21": 60, "22": "s25", "23": "s26", "24": "s27", "25": "s28", "26": "s29", "27": "s30", "28": "s62", "29": "s23" }, { "34": "r36", "39": "r36" }, { "34": "r37", "39": "r37" }, { "34": "r38", "39": "r38" }, { "34": "r39", "39": "r39" }, { "32": "s64", "34": "s32" }, { "23": "r12", "24": "r12", "25": "r12", "26": "r12", "27": "r12", "31": "r12" }, { "32": "s66", "34": "s32" }, { "23": "r13", "24": "r13", "25": "r13", "26": "r13", "27": "r13", "31": "r13" }];
/**
* Parsing stack.
*/
var stack = [];
/**
* Tokenizer instance.
*/
var tokenizer = void 0;
/**
* Generic tokenizer used by the parser in the Syntax tool.
*
* https://www.npmjs.com/package/syntax-cli
*
* See `--custom-tokinzer` to skip this generation, and use a custom one.
*/
var lexRules = [[/^\/\/.*/, function () {/* skip comments */}], [/^\/\*(.|\s)*?\*\//, function () {/* skip comments */}], [/^\s+/, function () {/* skip whitespace */}], [/^\b(?:CHIP|chip)\b/, function () {
return 'CHIP';
}], [/^\b(?:IN|in)\b/, function () {
return 'IN';
}], [/^\b(?:OUT|out)\b/, function () {
return 'OUT';
}], [/^\b(?:PARTS|parts)\b/, function () {
return 'PARTS';
}], [/^\b(?:BUILTIN|builtin)\b/, function () {
return 'BUILTIN';
}], [/^\b(?:CLOCKED|clocked)\b/, function () {
return 'CLOCKED';
}], [/^\d+/, function () {
return 'NUMBER';
}], [/^[a-zA-Z_$]\w*/, function () {
return 'ID';
}], [/^\{/, function () {
return "'{'";
}], [/^\}/, function () {
return "'}'";
}], [/^;/, function () {
return "';'";
}], [/^:/, function () {
return "':'";
}], [/^,/, function () {
return "','";
}], [/^\[/, function () {
return "'['";
}], [/^\]/, function () {
return "']'";
}], [/^\./, function () {
return "'.'";
}], [/^\(/, function () {
return "'('";
}], [/^\)/, function () {
return "')'";
}], [/^=/, function () {
return "'='";
}]];
var lexRulesByConditions = { "INITIAL": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21] };
var EOF_TOKEN = {
type: EOF,
value: ''
};
tokenizer = {
initString: function initString(string) {
this._string = string;
this._cursor = 0;
this._states = ['INITIAL'];
this._tokensQueue = [];
this._currentLine = 1;
this._currentColumn = 0;
this._currentLineBeginOffset = 0;
/**
* Matched token location data.
*/
this._tokenStartOffset = 0;
this._tokenEndOffset = 0;
this._tokenStartLine = 1;
this._tokenEndLine = 1;
this._tokenStartColumn = 0;
this._tokenEndColumn = 0;
return this;
},
/**
* Returns tokenizer states.
*/
getStates: function getStates() {
return this._states;
},
getCurrentState: function getCurrentState() {
return this._states[this._states.length - 1];
},
pushState: function pushState(state) {
this._states.push(state);
},
begin: function begin(state) {
this.pushState(state);
},
popState: function popState() {
if (this._states.length > 1) {
return this._states.pop();
}
return this._states[0];
},
getNextToken: function getNextToken() {
// Something was queued, return it.
if (this._tokensQueue.length > 0) {
return this._toToken(this._tokensQueue.shift());
}
if (!this.hasMoreTokens()) {
return EOF_TOKEN;
}
var string = this._string.slice(this._cursor);
var lexRulesForState = lexRulesByConditions[this.getCurrentState()];
for (var i = 0; i < lexRulesForState.length; i++) {
var lexRuleIndex = lexRulesForState[i];
var lexRule = lexRules[lexRuleIndex];
var matched = this._match(string, lexRule[0]);
// Manual handling of EOF token (the end of string). Return it
// as `EOF` symbol.
if (string === '' && matched === '') {
this._cursor++;
}
if (matched !== null) {
yytext = matched;
yyleng = yytext.length;
var token = lexRule[1].call(this);
if (!token) {
return this.getNextToken();
}
// If multiple tokens are returned, save them to return
// on next `getNextToken` call.
if (Array.isArray(token)) {
var tokensToQueue = token.slice(1);
token = token[0];
if (tokensToQueue.length > 0) {
var _tokensQueue;
(_tokensQueue = this._tokensQueue).unshift.apply(_tokensQueue, _toConsumableArray(tokensToQueue));
}
}
return this._toToken(token, yytext);
}
}
if (this.isEOF()) {
this._cursor++;
return EOF_TOKEN;
}
this.throwUnexpectedToken(string[0], this._currentLine, this._currentColumn);
},
/**
* Throws default "Unexpected token" exception, showing the actual
* line from the source, pointing with the ^ marker to the bad token.
* In addition, shows `line:column` location.
*/
throwUnexpectedToken: function throwUnexpectedToken(symbol, line, column) {
var lineSource = this._string.split('\n')[line - 1];
var lineData = '';
if (lineSource) {
var pad = ' '.repeat(column);
lineData = '\n\n' + lineSource + '\n' + pad + '^\n';
}
throw new SyntaxError(lineData + 'Unexpected token: "' + symbol + '" ' + ('at ' + line + ':' + column + '.'));
},
getCursor: function getCursor() {
return this._cursor;
},
getCurrentLine: function getCurrentLine() {
return this._currentLine;
},
getCurrentColumn: function getCurrentColumn() {
return this._currentColumn;
},
_captureLocation: function _captureLocation(matched) {
var nlRe = /\n/g;
// Absolute offsets.
this._tokenStartOffset = this._cursor;
// Line-based locations, start.
this._tokenStartLine = this._currentLine;
this._tokenStartColumn = this._tokenStartOffset - this._currentLineBeginOffset;
// Extract `\n` in the matched token.
var nlMatch = void 0;
while ((nlMatch = nlRe.exec(matched)) !== null) {
this._currentLine++;
this._currentLineBeginOffset = this._tokenStartOffset + nlMatch.index + 1;
}
this._tokenEndOffset = this._cursor + matched.length;
// Line-based locations, end.
this._tokenEndLine = this._currentLine;
this._tokenEndColumn = this._currentColumn = this._tokenEndOffset - this._currentLineBeginOffset;
},
_toToken: function _toToken(tokenType) {
var yytext = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
return {
// Basic data.
type: tokenType,
value: yytext,
// Location data.
startOffset: this._tokenStartOffset,
endOffset: this._tokenEndOffset,
startLine: this._tokenStartLine,
endLine: this._tokenEndLine,
startColumn: this._tokenStartColumn,
endColumn: this._tokenEndColumn
};
},
isEOF: function isEOF() {
return this._cursor === this._string.length;
},
hasMoreTokens: function hasMoreTokens() {
return this._cursor <= this._string.length;
},
_match: function _match(string, regexp) {
var matched = string.match(regexp);
if (matched) {
// Handle `\n` in the matched token to track line numbers.
this._captureLocation(matched[0]);
this._cursor += matched[0].length;
return matched[0];
}
return null;
}
};
/**
* Expose tokenizer so it can be accessed in semantic actions.
*/
yy.lexer = tokenizer;
yy.tokenizer = tokenizer;
/**
* Global parsing options. Some options can be shadowed per
* each `parse` call, if the optations are passed.
*
* Initalized to the `captureLocations` which is passed
* from the generator. Other options can be added at runtime.
*/
yy.options = {
captureLocations: true
};
/**
* Parsing module.
*/
var yyparse = {
/**
* Sets global parsing options.
*/
setOptions: function setOptions(options) {
yy.options = options;
return this;
},
/**
* Returns parsing options.
*/
getOptions: function getOptions() {
return yy.options;
},
/**
* Parses a string.
*/
parse: function parse(string, parseOptions) {
if (!tokenizer) {
throw new Error('Tokenizer instance wasn\'t specified.');
}
tokenizer.initString(string);
/**
* If parse options are passed, override global parse options for
* this call, and later restore global options.
*/
var globalOptions = yy.options;
if (parseOptions) {
yy.options = Object.assign({}, yy.options, parseOptions);
}
/**
* Allow callers to do setup work based on the
* parsing string, and passed options.
*/
yyparse.onParseBegin(string, tokenizer, yy.options);
stack.length = 0;
stack.push(0);
var token = tokenizer.getNextToken();
var shiftedToken = null;
do {
if (!token) {
// Restore options.
yy.options = globalOptions;
unexpectedEndOfInput();
}
var state = stack[stack.length - 1];
var column = tokens[token.type];
if (!table[state].hasOwnProperty(column)) {
yy.options = globalOptions;
unexpectedToken(token);
}
var entry = table[state][column];
// Shift action.
if (entry[0] === 's') {
var loc = null;
if (yy.options.captureLocations) {
loc = {
startOffset: token.startOffset,
endOffset: token.endOffset,
startLine: token.startLine,
endLine: token.endLine,
startColumn: token.startColumn,
endColumn: token.endColumn
};
}
stack.push({ symbol: tokens[token.type], semanticValue: token.value, loc: loc }, Number(entry.slice(1)));
shiftedToken = token;
token = tokenizer.getNextToken();
}
// Reduce action.
else if (entry[0] === 'r') {
var productionNumber = entry.slice(1);
var production = productions[productionNumber];
var hasSemanticAction = typeof production[2] === 'function';
var semanticValueArgs = hasSemanticAction ? [] : null;
var locationArgs = hasSemanticAction && yy.options.captureLocations ? [] : null;
if (production[1] !== 0) {
var rhsLength = production[1];
while (rhsLength-- > 0) {
stack.pop();
var stackEntry = stack.pop();
if (hasSemanticAction) {
semanticValueArgs.unshift(stackEntry.semanticValue);
if (locationArgs) {
locationArgs.unshift(stackEntry.loc);
}
}
}
}
var reduceStackEntry = { symbol: production[0] };
if (hasSemanticAction) {
yytext = shiftedToken ? shiftedToken.value : null;
yyleng = shiftedToken ? shiftedToken.value.length : null;
var semanticActionArgs = locationArgs !== null ? semanticValueArgs.concat(locationArgs) : semanticValueArgs;
production[2].apply(production, _toConsumableArray(semanticActionArgs));
reduceStackEntry.semanticValue = __;
if (locationArgs) {
reduceStackEntry.loc = __loc;
}
}
var nextState = stack[stack.length - 1];
var symbolToReduceWith = production[0];
stack.push(reduceStackEntry, table[nextState][symbolToReduceWith]);
}
// Accept.
else if (entry === 'acc') {
stack.pop();
var parsed = stack.pop();
if (stack.length !== 1 || stack[0] !== 0 || tokenizer.hasMoreTokens()) {
// Restore options.
yy.options = globalOptions;
unexpectedToken(token);
}
if (parsed.hasOwnProperty('semanticValue')) {
yy.options = globalOptions;
yyparse.onParseEnd(parsed.semanticValue);
return parsed.semanticValue;
}
yyparse.onParseEnd();
// Restore options.
yy.options = globalOptions;
return true;
}
} while (tokenizer.hasMoreTokens() || stack.length > 1);
},
setTokenizer: function setTokenizer(customTokenizer) {
tokenizer = customTokenizer;
return yyparse;
},
getTokenizer: function getTokenizer() {
return tokenizer;
},
onParseBegin: function onParseBegin(string, tokenizer, options) {},
onParseEnd: function onParseEnd(parsed) {}
};
/**
* List of inputs for this chip.
*/
var inputs = null;
/**
* List of outputs for this chip.
*/
var outputs = null;
/**
* Actual definitions.
*/
var parts = null;
/**
* Builtin parts.
*/
var builtins = null;
/**
* Clocked parts.
*/
var clocked = null;
yyparse.onParseBegin = function (_string) {
inputs = [];
outputs = [];
parts = [];
builtins = [];
clocked = [];
};
/**
* Converts subscript to `size` for input/ouput:
* `a[16]`: {value: 'a', size: 16}
*
* And to `index` or `range` for references:
* `a[15]`: {value: 'a', index: 15}
* `a[0..7]`: {value: 'a', range: {from: 0, to: 7}}
*/
function subscriptToProp(value, prop) {
var subscript = value.subscript;
if (subscript) {
if (subscript.kind === 'number') {
value[prop] = subscript.value;
} else if (subscript.kind === 'range') {
delete subscript.kind;
value.range = subscript;
}
delete value.subscript;
}
return value;
}
function subscriptListToProp(values, prop) {
values.forEach(function (value) {
return subscriptToProp(value, prop);
});
return values;
}
function unexpectedToken(token) {
if (token.type === EOF) {
unexpectedEndOfInput();
}
tokenizer.throwUnexpectedToken(token.value, token.startLine, token.startColumn);
}
function unexpectedEndOfInput() {
parseError('Unexpected end of input.');
}
function parseError(message) {
throw new SyntaxError(message);
}
module.exports = yyparse;