diff --git a/Source/SimpleParser/SimpleParser.pas b/Source/SimpleParser/SimpleParser.pas index 06caf50..f632596 100644 --- a/Source/SimpleParser/SimpleParser.pas +++ b/Source/SimpleParser/SimpleParser.pas @@ -3648,6 +3648,16 @@ procedure TmwSimplePasPar.OrdinalType; begin ConstantExpression; end; + { An operator after the identifier means the bound is a constant + expression, not a type name: array[mlab + 1..mlog]. Reading it as a + type name consumes the identifier alone and leaves the caller at the + operator, where it can only report an error. These are the operators + SimpleExpression and Term accept. } + ptAnd, ptDiv, ptMinus, ptMod, ptOr, ptPlus, ptShl, ptShr, ptSlash, + ptStar, ptXor: + begin + ConstantExpression; + end; else begin TypeID; diff --git a/Test/Snippets/arrayboundexpression.pas b/Test/Snippets/arrayboundexpression.pas new file mode 100644 index 0000000..1d695d1 --- /dev/null +++ b/Test/Snippets/arrayboundexpression.pas @@ -0,0 +1,22 @@ +unit arrayboundexpression; + +interface + +const + mlab = 4; + mlog = 12; + +type + { An array bound is a constant EXPRESSION, not just a constant or a type name. + OrdinalType decided on one token of lookahead and read `mlab` as a type name, + so the whole unit failed to parse at the `+`. } + TRanges = record + iu: array[mlab + 1..mlog] of Integer; + du: array[mlab * 2..mlog - 1, 0..mlab shl 1] of Byte; + end; + + TSetOfExpression = set of mlab + 1..mlog; + +implementation + +end.