Skip to content

Commit 14a4276

Browse files
committed
(-) bug: parsing native blocks with "end" inside
1 parent 0e26561 commit 14a4276

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
lines changed

src/lua/parser.lua

+9-8
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,9 @@ GG = { [1] = x * V'_Stmts' * V'Y' * (P(-1) + E('end of file'))
509509

510510
, Nat_End = K'native' * KK'/' * K'end'
511511
, Nat_Block = K'native' * (CK'/pre'+CK'/pos') * (#K'do')*'do' *
512-
( C(V'_C') + C((P(1)-(S'\t\n\r '*'end'*P';'^0*'\n'))^0) ) *
513-
x* K'end'
512+
( S'\t\n\r '^0*C(V'_C')*x +
513+
C(('#endif'+(P(1)-'end'))^0) ) *
514+
K'end'
514515

515516
, Nat_Stmt = KK('{',nil,true) * V'__nat1' * KK'}'
516517
, _Nat_Exp = KK('{',nil,true) * V'__nat1' * KK'}'
@@ -849,12 +850,12 @@ GG = { [1] = x * V'_Stmts' * V'Y' * (P(-1) + E('end of file'))
849850
+ V'_Var_set_fin'
850851

851852
--, _C = '/******/' * (P(1)-'/******/')^0 * '/******/'
852-
, _C = m.Cg(V'_CSEP','mark') *
853-
(P(1)-V'_CEND')^0 *
854-
V'_CEND'
855-
, _CSEP = '/***' * (1-P'***/')^0 * '***/'
856-
, _CEND = m.Cmt(C(V'_CSEP') * m.Cb'mark',
857-
function (s,i,a,b) return a == b end)
853+
, _C = m.Cg(V'__CSEP','mark') *
854+
(P(1)-V'__CEND')^0 *
855+
V'__CEND'
856+
, __CSEP = '/***' * (1-P'***/')^0 * '***/'
857+
, __CEND = m.Cmt(C(V'__CSEP') * m.Cb'mark',
858+
function (s,i,a,b) return a==b end)
858859

859860
, __SPACE = ('\n' * (V'__comm'+S'\t\n\r ')^0 *
860861
'#' * (P(1)-'\n')^0)

tst/tests.lua

+31-14
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ escape 1;
395395
}
396396
]==]
397397

398-
--do return end -- OK
398+
do return end -- OK
399399
--]=====]
400400

401401
----------------------------------------------------------------------------
@@ -24713,18 +24713,6 @@ end
2471324713

2471424714
--<<< OUTPUT
2471524715

24716-
Test { [[
24717-
native/pos do
24718-
/******/
24719-
int end = 1;
24720-
/******/
24721-
end
24722-
native _end;
24723-
escape _end;
24724-
]],
24725-
run = 1
24726-
}
24727-
2472824716
Test { [[
2472924717
native/pre do
2473024718
typedef struct {
@@ -26639,13 +26627,42 @@ escape 1;
2663926627
run = 1,
2664026628
}
2664126629

26630+
Test { [[
26631+
native/pre do
26632+
end
26633+
native/end;
26634+
escape 1;
26635+
]],
26636+
run = 1,
26637+
}
26638+
26639+
Test { [[
26640+
native/pre do
26641+
end native/end;
26642+
escape 1;
26643+
]],
26644+
run = 1,
26645+
}
26646+
26647+
Test { [[
26648+
native/pos do
26649+
/******/
26650+
int end = 1;
26651+
/******/
26652+
end
26653+
native _end;
26654+
escape _end;
26655+
]],
26656+
run = 1
26657+
}
26658+
2664226659
Test { [[
2664326660
native/pos do
2664426661
byte* a = (byte*)"end";
2664526662
end
2664626663
escape 1;
2664726664
]],
26648-
run = 1,
26665+
parser = 'line 2 : after `"` : expected `"`',
2664926666
}
2665026667

2665126668
Test { [[

0 commit comments

Comments
 (0)