Skip to content

Commit

Permalink
Merge bdb5efa into 4ee92c8
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Wilaby committed Jan 30, 2019
2 parents 4ee92c8 + bdb5efa commit 34ccc4b
Show file tree
Hide file tree
Showing 25 changed files with 2,340 additions and 5,407 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

/coverage
/.nyc_output
/target
**/*.rs.bk
/node_modules
Expand Down
20 changes: 20 additions & 0 deletions .nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extension": [
".js"
],
"include": [
"lib/**/*.js"
],
"exclude": [
"**/node_modules/**",
"**/__test__/**",
"**/src/**",
"**/coverage/**",
"**/*.d.ts"
],
"reporter": [
"html"
],
"all": true,
"cache": true
}
14 changes: 6 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
language: node_js
language: rust

node_js:
- "lts/*"
Expand All @@ -7,9 +7,11 @@ notifications:
email: false

before_install:
- rustup install nightly
- rustup target add wasm32-unknown-unknown --toolchain nightly
- rustup default nightly
- nvm install node
- node --version
- npm prune
- rustup target add wasm32-unknown-unknown --toolchain stable
- rustup default stable
- cwd=$(pwd -P)
- cd /
- cargo install wasm-gc
Expand All @@ -24,7 +26,3 @@ script:
cache:
directories:
- "node_modules"

matrix:
include:
- language: rust
45 changes: 22 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The first streamable, low memory XML, HTML, and JSX parser for [WebAssembly](htt

Sax Wasm is a sax style parser for XML, HTML and JSX written in [Rust](https://www.rust-lang.org/en-US/), compiled for
Web Assembly with the sole motivation to bring **near native speeds** to XML and JSX parsing for node and the web.
Inspired by [sax js](https://github.com/isaacs/sax-js) and rebuilt with Rust for Web Assembly sax-wasm brings optimizations
Inspired by [sax js](https://github.com/isaacs/sax-js) and rebuilt with Rust for Web Assembly, sax-wasm brings optimizations
for speed and support for JSX syntax.

Suitable for [LSP](https://langserver.org/) implementations, sax-wasm provides line numbers and character positions within the
Expand Down Expand Up @@ -105,20 +105,20 @@ parser.events = SaxEventType.Text | SaxEventType.OpenTag | SaxEventType.Attribut
```
Complete list of event/argument pairs:

|Event |Mask |Argument |
|----------------------------------|--------------|--------------------|
|SaxEventType.Text |0b1 |text: Text |
|SaxEventType.ProcessingInstruction|0b10 |procInst: string |
|SaxEventType.SGMLDeclaration |0b100 |sgmlDecl: string |
|SaxEventType.Doctype |0b1000 |doctype: string |
|SaxEventType.Comment |0b10000 |comment: string |
|SaxEventType.OpenTagStart |0b100000 |tag: Tag |
|SaxEventType.Attribute |0b1000000 |attribute: Attribute|
|SaxEventType.OpenTag |0b10000000 |tag: Tag |
|SaxEventType.CloseTag |0b100000000 |tag: Tag |
|SaxEventType.OpenCDATA |0b1000000000 |start: Position |
|SaxEventType.CDATA |0b10000000000 |cdata: string |
|SaxEventType.CloseCDATA |0b100000000000|end: Position |
|Event |Mask |Argument passed to handler |
|----------------------------------|--------------|---------------------------------------------|
|SaxEventType.Text |0b000000000001|text: [Text](src/js/saxWasm.ts#L46) |
|SaxEventType.ProcessingInstruction|0b000000000010|procInst: string |
|SaxEventType.SGMLDeclaration |0b000000000100|sgmlDecl: string |
|SaxEventType.Doctype |0b000000001000|doctype: string |
|SaxEventType.Comment |0b000000010000|comment: string |
|SaxEventType.OpenTagStart |0b000000100000|tag: [Tag](src/js/saxWasm.ts#L52) |
|SaxEventType.Attribute |0b000001000000|attribute: [Attribute](src/js/saxWasm.ts#L37)|
|SaxEventType.OpenTag |0b000010000000|tag: [Tag](src/js/saxWasm.ts#L52) |
|SaxEventType.CloseTag |0b000100000000|tag: [Tag](src/js/saxWasm.ts#L52) |
|SaxEventType.OpenCDATA |0b001000000000|start: [Position](src/js/saxWasm.ts#L32) |
|SaxEventType.CDATA |0b010000000000|cdata: string |
|SaxEventType.CloseCDATA |0b100000000000|end: [Position](src/js/saxWasm.ts#L32) |

## SAXParser.js
### Methods
Expand All @@ -134,7 +134,7 @@ readied for the next document.

- `events` - A bitmask containing the events to subscribe to. See the examples for creating the bitmask

- `eventHanlder` - A function reference used for event handling. The supplied function must have a signature that accepts
- `eventHandlder` - A function reference used for event handling. The supplied function must have a signature that accepts
2 arguments: 1. The `event` which is one of the `SaxEventTypes` and the `body` (listed in the table above)

## sax-wasm.wasm
Expand All @@ -143,28 +143,27 @@ readied for the next document.
the events bitmask can be done at anytime during processing using this method.

- `write(ptr: *mut u8, length: usize)` - Supplies the parser with the location and length of the newly written bytes in the
stream and kicks off processing. The parser assumes that the bytes are valid utf-8. Writing non utf-8 bytes will may cause
stream and kicks off processing. The parser assumes that the bytes are valid utf-8. Writing non utf-8 bytes may cause
unpredictable behavior.

- `end()` - resets the character and line counts but does not halt processing of the current buffer.

## Building from source
### Prerequisites
This project requires rust v1.29+ since it contains the `wasm32-unknown-unknown` target out of the box. This is
currently only available in the nightly build.
This project requires rust v1.30+ since it contains the `wasm32-unknown-unknown` target out of the box.

Install rust:
```bash
curl https://sh.rustup.rs -sSf | sh
```
Install the nightly compiler and switch to it.
Install the stable compiler and switch to it.
```bash
rustup install nightly
rustup default nightly
rustup install stable
rustup default stable
```
Install the wasm32-unknown-unknown target.
```bash
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup target add wasm32-unknown-unknown --toolchain stable
```
Install [node with npm](https://nodejs.org/en/) then run the following command from the project root.
```bash
Expand Down

0 comments on commit 34ccc4b

Please sign in to comment.