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

Multiple independent parsers / reentrancy #62

Open
fstirlitz opened this issue Aug 2, 2019 · 1 comment
Open

Multiple independent parsers / reentrancy #62

fstirlitz opened this issue Aug 2, 2019 · 1 comment
Labels
compat hazard Resolving this issue may create backwards compatibility problems enhancement Request for functionality covering an entirely new use case
Milestone

Comments

@fstirlitz
Copy link
Owner

Currently, this code works:

luaparse.parse({ wait: true }).write('foo = "');
console.info(luaparse.parse('bar"'));

It prints out:

{
	"type": "Chunk",
	"body": [
		{
			"type": "AssignmentStatement",
			"variables": [
				{
					"type": "Identifier",
					"name": "foo"
				}
			],
			"init": [
				{
					"type": "StringLiteral",
					"value": "bar",
					"raw": "\"bar\""
				}
			]
		}
	],
	"comments": []
}

This is because the library maintains a single lexer and parser state shared between invocations of the parse function; there is no way to concurrently parse multiple Lua scripts. Code that expects each .parse({ wait: true }) to create a new parser independent of any previously created one is in for a nasty surprise.

There should be a way to create multiple isolated parser states. This will probably necessitate a quite invasive re-write, and may break some backwards compatibility unless this is done through separate API calls. Then though, the sort of code that relies on non-reentrancy is not one I wish to personally support.

@fstirlitz fstirlitz added compat hazard Resolving this issue may create backwards compatibility problems enhancement Request for functionality covering an entirely new use case labels Aug 2, 2019
@fstirlitz fstirlitz added this to the 0.3 milestone Aug 17, 2019
@fstirlitz fstirlitz modified the milestones: 0.3, 0.4 Oct 5, 2019
@fstirlitz
Copy link
Owner Author

I’ll think I’ll add a re-entrant API in 0.3.2, while leaving the current one in place, with semantics preserved. Not sure what I’ll do in 0.4. I may remove the stand-alone parse call entirely, or I may change it to construct a temporary parser state, so that each parse call is independent from the next. Either will be technically a breaking change.

@fstirlitz fstirlitz modified the milestones: 0.4, 0.5 Nov 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat hazard Resolving this issue may create backwards compatibility problems enhancement Request for functionality covering an entirely new use case
Projects
None yet
Development

No branches or pull requests

1 participant