Skip to content
This repository has been archived by the owner on Sep 13, 2019. It is now read-only.

Commit

Permalink
Merge pull request #70 from danbev/qasm-make-parser-member
Browse files Browse the repository at this point in the history
Make parser a member of class Parser
  • Loading branch information
jesusprubio authored May 17, 2019
2 parents df12fa0 + 32177c2 commit 5babc21
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `@qiskit/qiskit-qasm`: Make QasmError a class
- `@qiskit/qiskit-qasm`: Use QasmError for jison error handling
- `@qiskit/qiskit-qasm`: Make parser a member of class Parser
- `@qiskit/qiskit-qasm`: Use TypeError as error for incorrect type

## [0.9.0] - 2019-05-13
Expand Down
7 changes: 3 additions & 4 deletions packages/qiskit-qasm/lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,19 @@ const QasmError = require('./QasmError');

// TODO: Do async?
const bnf = fs.readFileSync(path.resolve(__dirname, 'grammar.jison'), 'utf8');
let parser;

class Parser {
constructor(opts = {}) {
dbg('Starting', opts);
parser = new jison.Parser(bnf);
this.parser = new jison.Parser(bnf);

if (opts.core !== false) {
// TODO: Parse all core libraries (when we have more)
const qelib1 = fs.readFileSync(
path.resolve(__dirname, '../core/qelib1.inc'),
'utf8',
);
this.qelibParsed = parser.parse(qelib1);
this.qelibParsed = this.parser.parse(qelib1);
}
}

Expand All @@ -47,7 +46,7 @@ class Parser {
let res;

try {
res = parser.parse(circuit, this.qelibParsed);
res = this.parser.parse(circuit, this.qelibParsed);
} catch (err) {
if (err instanceof QasmError) {
throw err;
Expand Down

0 comments on commit 5babc21

Please sign in to comment.