bondage.js icon indicating copy to clipboard operation
bondage.js copied to clipboard

"->" leads to parsing error and text fails toload

Open blurymind opened this issue 6 years ago • 5 comments

I was using the attached example from yarn's website and found out that the 'Start' card will fail to load, because it contains '->' I get Error: Parse error on line 4: Unexpected 'Text'

You can experience this if you test it with http://hayley.zone/bondage.js/

Yarn example:

[
	{
		"title": "Start",
		"tags": "",
		"body": "A: Hey, I'm a character in a script!\nB: And I am too! You are talking to me!\n-> What's going on\n    A: Why this is a demo of the script system!\n    B: And you're in it!\n-> Um ok\nA: How delightful!\nB: What would you prefer to do next?\n[[Leave|Leave]]\n[[Learn more|LearnMore]]",
		"position": {
			"x": 592,
			"y": 181
		},
		"colorID": 0
	},
	{
		"title": "Leave",
		"tags": "",
		"body": "A: Oh, goodbye!\nB: You'll be back soon!",
		"position": {
			"x": 387,
			"y": 487
		},
		"colorID": 0
	},
	{
		"title": "LearnMore",
		"tags": "rawText",
		"body": "A: HAHAHA",
		"position": {
			"x": 763,
			"y": 472
		},
		"colorID": 0
	}
]

blurymind avatar Jun 03 '18 13:06 blurymind

Ah, good catch. This is an error with the following syntax:

-> What's going on
    A: Why this is a demo of the script system!
    B: And you're in it!
-> Um ok

The parser breaks when it tries to handle an -> with no tabbed-in text following it.

I'll try to find some time to look into this, I'm worried it may require a significant change to the parser to handle the potential of having or not having text after an option

hylyh avatar Jun 16 '18 00:06 hylyh

Interesting, the indent/dedent tokens are both nulls, so that seems to be handled elsewhere - the parser/states? There is a token for -> https://github.com/jhayley/bondage.js/blob/master/src/lexer/tokens.js#L32 ShortcutOption: /->/, But it's regex doesnt incorporate optional tab-in. It would be simple if we could handle that in the token like /(?: |\t|)->/

blurymind avatar Sep 26 '18 07:09 blurymind

Indents are handled specially within the lexer (see lexer.js) because they're used to mark block scope and can be nested arbitrarily, so using actual regex tokens to process them isn't sufficient. The lexer state for shortcut expressions is set to track a following indentation to mark its scope (https://github.com/jhayley/bondage.js/blob/master/src/lexer/states.js#L15).

The solution here might be to add a parameter to setTrackNextIndentation to make it be optional, but I'm not sure how implementing the "optional" part of that would work. Probably somewhere around here: https://github.com/jhayley/bondage.js/blob/master/src/lexer/lexer.js#L96

hylyh avatar Sep 28 '18 17:09 hylyh

not sure how this can be fixed, but your explanation is a very helpful start :)

How did yarnspinner solve this?

blurymind avatar Sep 28 '18 18:09 blurymind

I might fix that at some point, now that I better understand the lexer

blurymind avatar Mar 06 '20 23:03 blurymind