Skip to content

Commit

Permalink
S5 support (#259)
Browse files Browse the repository at this point in the history
* Handle error reporting and use of ignore-errors in node module properly

* Prepare for alpha.9 release of node and web modules for \s5 support with ignore errors

* Make API changes and do error handling in web, similar to python and node packages

* Change documentations corresponding to web module usage and development

* Update dev notes regarding node and web modules
  • Loading branch information
kavitharaju authored Oct 4, 2024
1 parent 31208dd commit 79a705d
Show file tree
Hide file tree
Showing 9 changed files with 675 additions and 76 deletions.
7 changes: 5 additions & 2 deletions docs/Dev_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ pytest -k "not compare_usx_with_testsuite_samples and not testsuite_usx_with_rnc

```

## How to build and publish JS module for local Development
## How to build and publish JS web module for local Development

First compile the grammar and get the wasm file
```bash
cd tree-sitter-usfm3
export PATH=$PATH:./node_modules/.bin
tree-sitter generate
tree-sitter build --wasm
cp tree-sitter-usfm.wasm ../js-usfm-parser/
cd ..
```
Expand All @@ -69,7 +70,9 @@ cp node_modules/web-tree-sitter/tree-sitter.wasm ./

```

Build the code base generating both cjs and esm versions of the same code base. This used parcel and its configs are in package.json(main, module, source, etc). Upon running the commands two folders `dist/cjs/` and `dist/esm` would be created.
### To publish the node and web modules

Build the code base generating both cjs and esm versions of the same code base. This used parcel and its configs are in package.json(main, module, source, etc). These steps can be followed in both the node module directory and web module directory.

```bash
rm -fr ./dist
Expand Down
2 changes: 1 addition & 1 deletion node-usfm-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "usfm-grammar",
"version": "3.0.0-alpha.8",
"version": "3.0.0-alpha.9",
"description": "Parser using tree-sitter-usfm3, to convert usfm to usj format.",
"main": "./dist/cjs/index.cjs",
"module": "./dist/es/index.mjs",
Expand Down
19 changes: 12 additions & 7 deletions node-usfm-parser/src/usfmParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ Only one of USFM, USJ or USX is supported in one object.`)
return this.syntaxTree.toString();
}

toUSJ() {
this.usj = this.convertUSFMToUSJ();
toUSJ(excludeMarkers = null,
includeMarkers = null,
ignoreErrors = false,
combineTexts = true,) {
this.usj = this.convertUSFMToUSJ(excludeMarkers = excludeMarkers,
includeMarkers = includeMarkers,
ignoreErrors = ignoreErrors,
combineTexts = combineTexts,);
return this.usj;
}

Expand Down Expand Up @@ -128,14 +134,13 @@ Only one of USFM, USJ or USX is supported in one object.`)
return outputUSFM;
}

convertUSFMToUSJ({
convertUSFMToUSJ(
excludeMarkers = null,
includeMarkers = null,
ignoreErrors = false,
combineTexts = true,
} = {}) {
combineTexts = true,) {
if (!ignoreErrors && this.errors.length > 0) {
let errorString = this.errors.map((err) => err.join(":")).join("\n\t");
let errorString = this.errors.join("\n\t");
throw new Error(
`Errors present:\n\t${errorString}\nUse ignoreErrors = true to generate output despite errors.`,
);
Expand All @@ -153,7 +158,7 @@ Only one of USFM, USJ or USX is supported in one object.`)
} catch (err) {
let message = "Unable to do the conversion. ";
if (this.errors) {
let errorString = this.errors.map((err) => err.join(":")).join("\n\t");
let errorString = this.errors.join("\n\t");
message += `Could be due to an error in the USFM\n\t${errorString}`;
}
else {
Expand Down
Loading

0 comments on commit 79a705d

Please sign in to comment.