/Users/andy/dev/ohcount/src/parser_macros.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include "languages.h"
Go to the source code of this file.
Define Documentation
#define CHECK_BLANK_ENTRY -3 |
Check blank entry entity. Used for embedded language transitions. If a newline follows immediately after such a transition, the line should be counted as parent code, not child code.
- Note:
- This is only used for line counting parsers.
#define check_blank_entry |
( |
lang |
|
) |
|
Value:
If there is a transition into an embedded language and there is only parent language code on the line (the rest of the line is blank with no child code), count the line as a line of parent code. Moves p and te to the end of the newline and calls the std_newline macro. (p is inclusive, te is not.) This is typically used in the main action for the CHECK_BLANK_ENTRY entity.
- Parameters:
-
| lang | The language name string. |
- Note:
- Applies only to line counting parsers.
Returns the absolute location in memory for a position relative to the start of the buffer being parsed.
- Parameters:
-
| c | Position relative to the start of the buffer. |
- Note:
- This is only used for line counting parsers.
Value:
The C equivalent of the Ragel 'code' action. This is tyically used in the main action for entities where Ragel actions cannot, for one reason or another, be used.
- Note:
- Applies only to line counting parsers.
Value:
The C equivalent of the Ragel 'comment' action. This is typically unused, but here for consistency.
- Note:
- Applies only to line counting parsers.
Value:
Restores settings for a failed enqueued entity. This is typically used in the ls, code, and comment macros.
- Note:
- Applies only to line counting parsers.
#define emb_internal_newline |
( |
lang |
|
) |
|
Value:
Executes emebedded language line counting actions for INTERNAL_NL entities based on whether or not the embedded language's code has been seen in a parent line. This is typically used in the main action for the INTERNAL_NL entity.
- Parameters:
-
| lang | The language name string. |
- Note:
- Applies only to line counting parsers.
#define emb_newline |
( |
lang |
|
) |
|
Value:
Executes embedded language line counting actions for NEWLINE entities based on whether or not the embedded language's code has been seen in a parent line. This is typically used in the main action for the NEWLINE entity.
- Parameters:
-
| lang | The language name string. |
- Note:
- Applies only to line counting parsers.
Value:
Initializes variables for parsing a buffer. Required at the beginning of every parser function.
Internal newline entity. Used for newlines inside patterns like strings and comments that can have newlines in them.
- Note:
- This is only used for line counting parsers.
Value:
Sets the line_start variable to ts. This is typically used for the SPACE entity in the main action.
- Note:
- Applies only to line counting parsers.
Newline entity.
- Note:
- This is only used for line counting parsers.
#define process_last_line |
( |
lang |
|
) |
|
Value:
Processes the last line for buffers that don't have a newline at EOF. This is typically used at the end of the parse_lang function after the Ragel parser has been executed.
- Parameters:
-
| lang | The language name string. |
- Note:
- Applies only to line counting parsers.
Value:
Sets up for having seen an embedded language. This is typically used when entering an embedded language which usually does not span multiple lines (e.g. php for <?php echo 'blah' ?> on single lines) so the line is counted as embedded code or comment, not parent code.
- Parameters:
-
| lang | The language name string. |
- Note:
- Applies only to line counting parsers.
#define std_internal_newline |
( |
lang |
|
) |
|
Value:
{ \
if (callback && p > line_start) { \
if (line_contains_code) { \
if (inqueue) \
enqueue(lang, "lcode", cint(line_start), cint(p), userdata); \
else \
callback(lang, "lcode", cint(line_start), cint(p), userdata); \
} else if (whole_line_comment) { \
if (inqueue) \
enqueue(lang, "lcomment", cint(line_start), cint(p), userdata); \
else \
callback(lang, "lcomment", cint(line_start), cint(p), userdata); \
} else { \
if (inqueue) \
enqueue(lang, "lblank", cint(line_start), cint(p), userdata); \
else \
callback(lang, "lblank", cint(line_start), cint(p), userdata); \
} \
} \
whole_line_comment = 0; \
line_contains_code = 0; \
line_start = p; \
}
Executes standard line counting actions for INTERNAL_NL entities. This is typically used in the main action for the INTERNAL_NL entity.
- Parameters:
-
| lang | The language name string. |
- Note:
- Applies only to line counting parsers.
#define std_newline |
( |
lang |
|
) |
|
Value:
{\
if (inqueue) { dequeue; } \
if (callback && te > line_start) { \
if (line_contains_code) \
callback(lang, "lcode", cint(line_start), cint(te), userdata); \
else if (whole_line_comment) \
callback(lang, "lcomment", cint(line_start), cint(te), userdata); \
else \
callback(lang, "lblank", cint(ts), cint(te), userdata); \
} \
whole_line_comment = 0; \
line_contains_code = 0; \
line_start = 0; \
}
Executes standard line counting actions for NEWLINE entities. This is typically used in the main action for the NEWLINE entity.
- Parameters:
-
| lang | The language name string. |
- Note:
- Applies only to line counting parsers.
Typedef Documentation
Function Documentation
void enqueue |
( |
const char * |
lang, |
|
|
const char * |
entity, |
|
|
int |
s, |
|
|
int |
e, |
|
|
void * |
udata | |
|
) |
| | |
Enqueues a callback for calling upon commit. This is only necessary for line counting machines. Ragel will execute actions in real-time rather than after a complete match. This is a problem for entities that contain internal newlines, since there is a callback for each internal newline whether or not the end of the entity matches. This means that if, for example, the beginning of a string entity is matched, the text following is treated as code until the ending delimiter. If there is no ending delimiter (it was not actually a string entity), Ragel will jump back to the beginning of the string and reparse the text again. This means all the callbacks called were probably not accurate. To remedy this, any entity which needs an ending delimiter that may not appear will have its callbacks enqueued and then committed when the ending delimitter is reached. If that delimitter is not reached, the callbacks are never called.
- Parameters:
-
| lang | The language name. |
| entity | The entity (lcode, lcomment, lblank). |
| s | The start position of the entity in the buffer. |
| e | The end position of the entity in the buffer. |
| udata | Userdata. |
Frees the memory used by a queue.
int is_blank_entry |
( |
char ** |
p |
) |
|
Determines whether or not the rest of the line is blank. This is typically used when entering an embedded language.
- Parameters:
-
| p | The position of entry into the emebedded language. |
- Returns:
- 0 if the rest of the line is not blank, the position at the end of the newline otherwise (inclusive).
- Note:
- Applies only to line counting parsers.
Variable Documentation
The buffer currently being parsed.
The head of the Callback queue.
The tail of the Callback queue.
State variable for the current entity being matched.
Flag indicating whether or not to enqueue callbacks instead of calling them in real time.
- Note:
- This is only used for line counting parsers.
Backup variable for 'inqueue'ing.
- Note:
- This is only used for line counting parsers.
Backup variable for 'inqueue'ing.
- Note:
- This is only used for line counting parsers.
Backup variable for 'inqueue'ing.
- Note:
- This is only used for line counting parsers.
Flag indicating whether or not the current line contains any code.
- Note:
- This is only used for line counting parsers.
The beginning of the current line in the buffer being parsed.
- Note:
- This is only used for line counting parsers.
Keeps track of an embedded language.
- Note:
- This is only used for line counting parsers.
Flag indicating whether or not the current line contains only a comment.
- Note:
- This is only used for line counting parsers.