Skip to content

Commit

Permalink
fix: upgrade to @hikerpig/moo to solve parser state corruption when…
Browse files Browse the repository at this point in the history
… parse multiple times
  • Loading branch information
hikerpig committed Jan 5, 2022
1 parent 3e80969 commit dbe9f97
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 48 deletions.
70 changes: 41 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,28 @@
"npmClient": "npm",
"pipeline": {
"compile": {
"dependsOn": ["^compile"],
"outputs": ["lib/**", "dist/*"]
"dependsOn": [
"^compile"
],
"outputs": [
"lib/**",
"dist/*"
]
},
"build": {
"outputs": ["dist/*", "build/*"]
"outputs": [
"dist/*",
"build/*"
]
},
"watch": {
"dependsOn": ["^watch"],
"outputs": ["lib/**", "dist/*"],
"dependsOn": [
"^watch"
],
"outputs": [
"lib/**",
"dist/*"
],
"cache": false
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/pintora-diagrams/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"coverage": "npx jest --collect-coverage"
},
"dependencies": {
"@hikerpig/moo": "^0.5.2-beta.2",
"@pintora/core": "^0.1.0-alpha.14",
"@pintora/dagre": "^0.10.0-alpha.0",
"@pintora/graphlib": "2.2.2",
Expand Down
5 changes: 1 addition & 4 deletions packages/pintora-diagrams/src/activity/parser.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { db } from './db'
import grammar, { setYY, reset } from './parser/activityDiagram'
import grammar, { setYY } from './parser/activityDiagram'
import { genParserWithRules } from '../util/parser-util'

setYY(db)

export const parse = genParserWithRules(grammar, {
prepare() {
reset()
},
postProcess(results) {
db.apply(results as any)
return results
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{%
import * as moo from 'moo'
import * as moo from '@hikerpig/moo'
import { tv, textToCaseInsensitiveRegex, VALID_TEXT_REGEXP, COLOR_REGEXP } from '../../util/parser-shared'

let lexer = moo.compile({
Expand All @@ -24,12 +24,6 @@ let yy
export function setYY(v) {
yy = v
}

export function reset() {
if (lexer.queuedText) {
lexer.queuedText = ''; // this is a tweak for moo.js bug
}
}
%}

@preprocessor typescript
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{%
import * as moo from 'moo'
import * as moo from '@hikerpig/moo'
import { tv, VALID_TEXT_REGEXP } from '../../util/parser-shared'

const commonTopRules = {
Expand Down
2 changes: 1 addition & 1 deletion packages/pintora-diagrams/src/er/parser/erDiagram.ne
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{%
import * as moo from 'moo'
import * as moo from '@hikerpig/moo'
import { tv, VALID_TEXT_REGEXP } from '../../util/parser-shared'

let lexer = moo.compile({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@{%
import * as moo from 'moo'
import * as moo from '@hikerpig/moo'
import { tv, textToCaseInsensitiveRegex, VALID_TEXT_REGEXP, COLOR_REGEXP } from '../../util/parser-shared'

let lexer = moo.states({
Expand Down

0 comments on commit dbe9f97

Please sign in to comment.