Skip to content

Commit dcac970

Browse files
committed
main: adjust the end fields of tags that scopes are cleared with "set" action
'/regex/\n/x/{scope=set}' clears the scope stack, then pushes the newly created tag on the stack. The original code set the start line of the newly created tag to the end fields of the tags pushed on the scope stack when clearing. The new code sets (the start line of the newly created tag) minus one to the field. Let's think about the following input (input.x) for an imaginary language X: 1: namespace NS1: 2: def x = 1 3: 4: namespace NS2: 5: def y = 1 6: and think about the optlib file for the X: --langdef=X --map-X=.x --kinddef-X=n,namespace,namespaces --kinddef-X=v,variable,variables --regex-X=/namespace +([A-Z][A-Z0-9]*)/\1/n/{scope=set} --regex-X=/ *def +([a-z])/\1/v/{scope=ref} The original code emitted: NS1 input.x /^namespace NS1:$/;" n end:4 x input.x /^ def x = 1$/;" v namespace:NS1 NS2 input.x /^namespace NS2:$/;" n end:6 y input.x /^ def y = 1$/;" v namespace:NS2 The code with this change emits: NS1 input.x /^namespace NS1:$/;" n end:3 x input.x /^ def x = 1$/;" v namespace:NS1 NS2 input.x /^namespace NS2:$/;" n end:6 y input.x /^ def y = 1$/;" v namespace:NS2 The end field for `NS1` is adjusted as expected. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 80fd3f7 commit dcac970

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Units/regex-with-scope-autoFQTag.d/expected.tags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NS1 input.foo /^ns NS1$/;" n end:16
1+
NS1 input.foo /^ns NS1$/;" n end:15
22
x input.foo /^define x {$/;" d namespace:NS1 end:14
33
NS1.x input.foo /^define x {$/;" d namespace:NS1 end:14
44
y input.foo /^ define y {$/;" d definition:NS1.x end:7

Units/regex-with-scope-nested.d/expected.tags

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
X input.foo /^# open:X$/;" s end:47
2-
NS1 input.foo /^ns NS1$/;" n end:16
2+
NS1 input.foo /^ns NS1$/;" n end:15
33
x input.foo /^define x {$/;" d namespace:NS1 end:14
44
y input.foo /^ define y {$/;" d definition:NS1.x end:7
55
v_y_0 input.foo /^ var v_y_0$/;" v definition:NS1.x.y

main/lregex.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,16 @@ static void matchTagPattern (struct lregexControlBlock *lcb,
15961596
if (patbuf->scopeActions & SCOPE_CLEAR)
15971597
{
15981598
unsigned long endline = getInputLineNumberInRegPType(patbuf->regptype, offset);
1599+
1600+
/*
1601+
* SCOPE_CLEAR|SCOPE_PUSH implies that "set" was specified as the scope action.
1602+
* If the specified action is "set", getInputLineNumberInRegPType()
1603+
* returns the start line of the NEW scope. The cleared scopes are ended BEFORE
1604+
* the new scope. There is a gap. We must adjust the "end:" field here.
1605+
*/
1606+
if (patbuf->scopeActions & SCOPE_PUSH && endline > 0)
1607+
endline--;
1608+
15991609
fillEndLineFieldOfUpperScopes (lcb, endline);
16001610
lcb->currentScope = CORK_NIL;
16011611
}

0 commit comments

Comments
 (0)