pacc logo
pacc v0.3: References to the input

Next: , Previous: , Up: User manual   [Contents][Index]


21.5 References to the input

Expressions in a pacc grammar frequently need to refer to the input string. The type ‘ref_t’ and a number of functions facilitate this.

‘ref_t’

An opaque type which can hold a reference to a substring of the input string. Whenever a name is bound to an expression that is not a simple rule call, it has the type ‘ref_t’. For example, in ‘c:.’, the type of ‘c’ is ‘ref_t’.

‘ref_t ref()’

Returns a reference to everything that is matched by the current rule.

‘char *ref_ptr(ref_t r)’

Returns a pointer to the start of the substring referenced by ‘r’.

‘char ref_0(ref_t r)’

Returns the first byte of the substring referenced by ‘r’.

‘size_t ref_len(ref_t r)’

Returns the length of the substring referenced by ‘r’.

‘char *ref_dup(ref_t r)’

Returns a newly-allocated, NUL-terminated copy of the substring. Almost equivalent to ‘strndup(ref_ptr(r), ref_len(r))’, except that it is more portable, and it calls ‘nomem()’ if memory cannot be allocated.

‘char *ref_str()’

Equivalent to ‘ref_dup(ref())’.

‘int ref_streq(ref_t r, char *s)’

Tests if the substring referenced by ‘r’ is equal to the NUL-terminatd string ‘s’. Has the same value as ‘!strcmp(ref_dup(r), s)’, but allocates no memory.

Last updated: 2016-08-03 21:39:50 UTC

News

Porting and packaging

One thing pacc needs is more users. And, perhaps, one way to get more users is to reduce the friction in getting started with pacc. An obvious lubricant is packaging. Read More...

Release relief

Looking at _pacc_coords(), I noticed that it seemed to have the same realloc() bug that I'd just fixed in _pacc_result(). However, the "list of arrays" trick really wasn't going to work here. Read More...

See more news articles

feed