Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run coq commands in isolation #84

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions src/coq/serapi/processors/SerapiSearchProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import SerapiProcessor from '../util/SerapiProcessor';
import {Mutex} from 'async-mutex';
import {
createCheckCommand, createQueryVernacCommand,
createSearchCommand,
createIndexedQueryVernacCommand, createSearchCommand,
} from '../util/SerapiCommandFactory';
import {COQ_EXCEPTION, parseErrorResponse} from '../SerapiParser';

Expand Down Expand Up @@ -217,20 +217,41 @@ class SerapiSearchProcessor extends SerapiProcessor {
* @private
*/
async _queryCommand(command) {
return this.sendCommand(createQueryVernacCommand(command), 'raw',
(feedback) => {
return {
result: feedback.string,
};
})
.then((result) => {
if (result.hasOwnProperty('result')) {
this.editor.message(result.result);
}
if (result.error) {
this.editor.message(result.errorMessage);
}
});
try {
return this.sendCommand(
createIndexedQueryVernacCommand(
command, this.state.idOfSentence(this.state.lastExecuted)), 'raw',
(feedback) => {
return {
result: feedback.string,
};
})
.then((result) => {
if (result.hasOwnProperty('result')) {
this.editor.message(result.result);
}
if (result.error) {
this.editor.message(result.errorMessage);
}
});
} catch (e) {
return this.sendCommand(
createQueryVernacCommand(
command), 'raw',
(feedback) => {
return {
result: feedback.string,
};
})
.then((result) => {
if (result.hasOwnProperty('result')) {
this.editor.message(result.result);
}
if (result.error) {
this.editor.message(result.errorMessage);
}
});
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/coq/serapi/util/SerapiCommandFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ export function createQueryVernacCommand(command) {
return `(Query () (Vernac "${sanitise(command)}"))`;
}

/**
* Partial method for vernac commands to execute the command
* after a specific sentece
* @param {String} command the vernac commmand to execute
* @param {number} sentenceId the sentence id after which
* the command should execute
* @return {string} the command
*/
export function createIndexedQueryVernacCommand(command, sentenceId) {
return `(Query ((sid ${sentenceId})) (Vernac "${sanitise(command)}"))`;
}

/**
* Create a serapi check command
* @param {String} query the term to check for
Expand Down