Skip to content

Commit 4ffc9d0

Browse files
committed
Add more checking of variable identifiers
1 parent 4ef6e58 commit 4ffc9d0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ The element stands for the entire pattern in the rule with the name given by _ru
116116
term <- l:term _ '+' _ r:factor { $$ = l + r; }
117117
```
118118

119+
A variable identifier must consist of alphabets (both uppercase and lowercase letters), digits, and underscores. The first letter must be an alphabet. The reserved keywords in C cannot be used.
120+
119121
**_sequence1_ `/` _sequence2_ `/` ... `/` _sequenceN_**
120122

121123
Each _sequence_ is tried in turn until one of them matches, at which time matching for the overall pattern succeeds. If no _sequence_ matches then the matching for the overall pattern fails. The operator slash (`/`) has the least priority. The example is shown below.

src/packcc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,6 +1830,11 @@ static node_t *parse_primary(context_t *ctx, node_t *rule) {
18301830
assert(s != VOID_VALUE); /* s should have a valid value when r has a valid value */
18311831
assert(q >= p);
18321832
n_p->data.reference.var = strndup_e(ctx->buffer.buf + p, q - p);
1833+
if (n_p->data.reference.var[0] == '_') {
1834+
print_error("%s:%llu:%llu: Leading underscore in variable name '%s'\n",
1835+
ctx->iname, (ullong_t)(l + 1), (ullong_t)(m + 1), n_p->data.reference.var);
1836+
ctx->errnum++;
1837+
}
18331838
{
18341839
size_t i;
18351840
for (i = 0; i < rule->data.rule.vars.len; i++) {

0 commit comments

Comments
 (0)