Respec: Single letter variables don't get converted to var

Created on 28 Mar 2019  路  8Comments  路  Source: w3c/respec

What happened (e.g., it crashed)?:

If you have: Let |p| be new Promise...

But what I was expecting?:

It should convert |p| to <var>p</var>.

Similarly, if you have: Let |p:Promise| be newly created Promise.

bug

All 8 comments

The issue is with the regex for inline variables:
https://github.com/w3c/respec/blob/1121be0cdb5244b12a6462993b64cc6f59ba77b8/src/core/inlines.js#L140

Changing it to "\\B\\|\\w[\\s\\w]*(?:\\s*\\:\\s*\\w+)?\\|\\B" fixed the issue for me (i.e remove word character matching \\w in the middle), and also passes the tests in inlines-spec.js.
But I don't really know RegEx, so @sidvishnoi what was the reason to match another word character?

New regex by @Swapnilr1 looks good to me. But I'll see if there are some other use cases and if we can simplify it.

Played with the regex a bit. Found these cases:

and this regex to solve both #2208 and #2184

/\B\|\w[\w\s]*(?:\s*\:.+)?\|\B/

A slightly faster regex would be if we specify allowed characters (and not just .)

/\B\|\w[\w\s]*(?:\s*\:[\w\s&;<>]+)?\|\B/

@sidvishnoi There is an issue with

/\B\|\w[\w\s]*(?:\s*\:.+)?\|\B/

regex1

means that var1 becomes the name and long| and |p becomes the type.

The alternative

/\B\|\w[\w\s]*(?:\s*\:[\w\s&;<>]+)?\|\B/

does not cause this error - but I think I am better off seeing a regular expressions reference rather than just trying out strings. Don't want to introduce another bug while fixing this - so need some time.

Yes, I was concerned about over-matching (See https://github.com/w3c/respec/issues/2184#issuecomment-476075781)
We need to stop the regex search at first |, and not go any further.
The second one works because neither of [\w\s&;<>] includes |, but .+ will match |, causing over-matching.

Yes, l understood why the first one overmatches, but that was only after I found a case where it overmatches. Specifying allowed characters is a safe approach.
Does [\w\s&;<>] cover all allowed characters? I have encountered &;<> for the first time as valid characters in variable types :open_mouth: so I don't have much of an idea on what is allowed and what is not.

@Swapnilr1 here is a comprehensive list of types:
https://heycam.github.io/webidl/#idl-types

See the more complex ones, like union, annotated, etc...

(note we don't need to process the types yet... we will do that eventually).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

deniak picture deniak  路  5Comments

saschanaz picture saschanaz  路  6Comments

marcoscaceres picture marcoscaceres  路  5Comments

sidvishnoi picture sidvishnoi  路  4Comments

saschanaz picture saschanaz  路  3Comments