Skip to content

Regex for detecting composite names breaks in certain scenarios #32

Open
@queeniema

Description

@queeniema

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions