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

Regex for detecting composite names breaks in certain scenarios #32

Open
queeniema opened this issue Jan 8, 2019 · 0 comments
Open
Labels
bug Something isn't working

Comments

@queeniema
Copy link

Base scenario: Use HelloWorld.spl as a starting point. Then, duplicate the HelloWorld composite and give it a unique name (e.g. HelloWorld2). The application looks like this:

composite HelloWorld {
	...
} // End of HelloWorld composite.

composite HelloWorld2 {
	...
} // End of HelloWorld2 composite.
  • If you comment out the HelloWorld2 composite with // and then try to build, the available composite options are HelloWorld and .. The . comes from the // End of HelloWorld composite. comment.
composite HelloWorld {
	...
} // End of HelloWorld composite.

// composite HelloWorld2 {
// 	...
// } // End of HelloWorld2 composite.

screen shot 2019-01-08 at 9 32 32 am

  • If you comment out the HelloWorld2 composite with /* ... */ and then try to build, the available composite options are HelloWorld and HelloWorld2.
composite HelloWorld {
	...
} // End of HelloWorld composite.

/* composite HelloWorld2 {
 	...
} // End of HelloWorld2 composite. */

screen shot 2019-01-08 at 9 36 26 am


For both scenarios, I would expect that there is only one composite available to build (HelloWorld), and thus the composite selector should not show up.

The current regex is this:
/.*?(?:\bcomposite\b)(?:\s*|\/\/.*?|\/\*.*?\*\/)+([a-z|A-Z|0-9|\.|\_]+)(?:\s*|\/\/.*?|\/\*.*?\*\/)*\{/gm

I think we should be detecting the start of the line using ^, and only match whitespace characters at the beginning of lines using /s rather than matching all characters .. Something like this:
/^\s*(?:\bcomposite\b)(?:\s*|\/\/.*?|\/\*.*?\*\/)+([a-z|A-Z|0-9|\.|\_]+)(?:\s*|\/\/.*?|\/\*.*?\*\/)*\{/gm

@guychris guychris added the bug Something isn't working label Jan 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants