Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
189 changed files
with
1,219 additions
and
8,168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"useTabs": true, | ||
"tabWidth": 4, | ||
"printWidth": 100 | ||
"printWidth": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,47 @@ | ||
/* tslint:disable:no-console */ | ||
import * as Benchmark from "benchmark"; | ||
import { makeParser } from "../src/parser/parse"; | ||
import { getTestSchema } from "../test/schemas"; | ||
import { parse } from "../src/parser/parse"; | ||
import { formatBytes, generateBenchmarkInput } from "./utils"; | ||
|
||
const parse = makeParser(getTestSchema(), console.error); | ||
const input = generateBenchmarkInput(); | ||
console.log("Size of test input: " + formatBytes(input.length)); | ||
const jsonAst = JSON.stringify(parse(input)); | ||
const jsonStr = JSON.stringify(parse(input, true)); | ||
new Benchmark.Suite("compare") | ||
.add("Parse Hashml", () => { | ||
parse(input); | ||
return parse(input); | ||
}) | ||
.add("Parse JSON", () => { | ||
JSON.parse(jsonAst); | ||
return JSON.parse(jsonStr); | ||
}) | ||
.add("String.matchAll", () => { | ||
for (const _ of input.matchAll( | ||
/(?:((?:\r\n|\n|\r|^)(\t*)[\t ]*(?:#([^ \[\r\n]+)(?: |$))?)|(#([^ \[]+)(\[)?)|(]\[)|(\[)|(\\(.)))/g | ||
)); | ||
return [ | ||
...input.matchAll( | ||
/(?:((?:\r\n|\n|\r|^)(\t*)[\t ]*(?:#([^ \[\r\n]+)(?: |$))?)|(#([^ \[]+)(\[)?)|(]\[)|(\[)|(\\(.)))/g | ||
) | ||
]; | ||
}) | ||
.add("Iterate through chars", () => { | ||
const SHARP = "#"; | ||
const OPENING_BRACKET = "["; | ||
let n = 0; | ||
const end = input.length; | ||
for (let i = 0; i < end; ++i) { | ||
switch (input.charAt(i)) { | ||
case SHARP: | ||
break; | ||
case OPENING_BRACKET: | ||
++n; | ||
break; | ||
} | ||
} | ||
return n; | ||
}) | ||
// add listeners | ||
.on("cycle", (event: Event) => { | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", function (this: Benchmark[]) { | ||
console.log("JSON/Hashml ratio: " + (this[1].stats.mean / this[0].stats.mean).toFixed(2)); | ||
console.log("Hashml throughput: " + formatBytes(input.length / this[0].stats.mean) + "/s"); | ||
}) | ||
// run async | ||
.run({ async: true }); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { InlineContent } from "./InlineContent"; | ||
import { parseInline } from "../parser/parseInline"; | ||
|
||
export class BlockElement { | ||
public tagError?: string; | ||
public labelError?: string; | ||
private _parsedLabel?: InlineContent; | ||
|
||
constructor( | ||
readonly tag?: string, | ||
readonly label?: string, | ||
readonly lineDelta: number = 0, | ||
readonly children: BlockElement[] = [] | ||
) {} | ||
|
||
toJSON() { | ||
return { tag: this.tag, label: this.label, lineDelta: this.lineDelta, children: this.children }; | ||
} | ||
|
||
get(tag: string | undefined) { | ||
return this.children.find(el => el.tag === tag); | ||
} | ||
|
||
getAll(tag: string | undefined) { | ||
return this.children.filter(el => el.tag === tag); | ||
} | ||
|
||
get parsedLabel(): InlineContent { | ||
if (!this._parsedLabel) this._parsedLabel = parseInline(this.label || ""); | ||
return this._parsedLabel; | ||
} | ||
|
||
get source(): string { | ||
return this.tagSource + this.labelSource; | ||
} | ||
|
||
get tagSource(): string { | ||
return this.tag ? "#" + this.tag + " " : ""; | ||
} | ||
|
||
get labelSource(): string { | ||
return this.label || ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { SpanElement } from "./SpanElement"; | ||
|
||
export class InlineContent { | ||
public error?: string; | ||
|
||
constructor(readonly content: Array<string | SpanElement> = []) {} | ||
|
||
get(tag: string | undefined) { | ||
return this.content.find(el => typeof el === "object" && el.tag === tag) as SpanElement | undefined; | ||
} | ||
|
||
getAll(tag: string | undefined) { | ||
return this.content.filter(el => typeof el === "object" && el.tag === tag) as SpanElement[]; | ||
} | ||
|
||
get source() { | ||
return this.content.map(el => (typeof el === "string" ? el : el.source)).join(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { InlineContent } from "./InlineContent"; | ||
|
||
export class SpanElement { | ||
public error?: string; | ||
|
||
constructor(readonly tag: string, readonly sugar: string | null = null, readonly args: InlineContent[] = []) {} | ||
|
||
addArg(): InlineContent { | ||
const arg = new InlineContent(); | ||
this.args.push(arg); | ||
return arg; | ||
} | ||
|
||
get source(): string { | ||
if (this.sugar) return this.sugar + this.args[0].source + this.sugar; | ||
return "#" + this.tag + this.args.map(arg => "[" + arg.source + "]").join(""); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.