I have this piece of language grammar to match a struct in D :
begin = '(?x)^\s* ((?:\b(public|private|protected|static|final|synchronized|abstract|export|shared)\b\s*)*) # modifier (struct)\s+ (\w+)\s* # identifier (?:(\s*([^)]+)\s*)|)\s* # Template type (if\s*(\s*([^)]+)\s*)|)?\s* # Template constraint '; end = '(?={|;)';
It will match this code, as an example:
struct Foo(A) if (true) { }
The problem is if I put the "if" on a new line it won't match. How can I make the rule match across several lines?
On 10 Mar 2015, at 2:30, Jacob Carlborg wrote:
I have this piece of language grammar to match a struct in D : […] It will match this code, as an example:
struct Foo(A) if (true) { }
The problem is if I put the "if" on a new line it won't match. How can I make the rule match across several lines?
This will require breaking up the rule into nested begin/end rules.
I.e. outer rule matches ‘struct Foo(A)’ then its child matches ‘if’ etc.
On 2015-03-13 07:55, Allan Odgaard wrote:
This will require breaking up the rule into nested begin/end rules.
I.e. outer rule matches ‘struct Foo(A)’ then its child matches ‘if’ etc.
Hmm, is that really necessary when there's only whitespace between the "if" and the struct declaration?
On 19 Mar 2015, at 2:15, Jacob Carlborg wrote:
Hmm, is that really necessary when there's only whitespace between the "if" and the struct declaration?
If there are linefeeds between the tokens, they cannot be matched by a single ‘match’ regexp, regerdless of what other characters are used.