summaryrefslogtreecommitdiffstats
path: root/parser.h
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-10-14 21:24:31 -0700
committerKaz Kylheku <kaz@kylheku.com>2014-10-14 21:24:31 -0700
commit8807a16fe3115e19ce4d65f1c8beb476494ccaec (patch)
treef61b0adc3c66f76415553c4d114fe784f97c5e70 /parser.h
parent68e4d78cf9f153871d9a3c07c8ce3e43eb517c3b (diff)
downloadtxr-8807a16fe3115e19ce4d65f1c8beb476494ccaec.tar.gz
txr-8807a16fe3115e19ce4d65f1c8beb476494ccaec.tar.bz2
txr-8807a16fe3115e19ce4d65f1c8beb476494ccaec.zip
More type safety, with help from C++ compiler.
* parser.h (scanner_t): New typedef. Cleverly, we use yyguts_t as the basis for this, which pays off in a few places, getting rid of conversions. (parser_t): scanner member redeclared to scanner_t *. (yyerror, yyerr, yyerrof, end_of_regex, end_of_char): Declarations updated. * parser.l (yyerror, yyerrorf, num_esc): scanner argument becomes scanner_t * instead of void *. (yyscanner): Occurrences replaced by yyg: why should we refer to the type-unsafe void *yyscanner, when we know that in the middle of the yylex function we have the properly typed yyguts_t *yyg. (end_of_regex, end_of_char): Argument changes to scanner_t * and name strategically changes to yyg, eliminating the local variable and cast. * parser.y (sym_helper): scanner argument becomes scanner_t * instead of void *. (%parse-param}: void *scnr becomes scanner_t *scnr. (define-transform, yybadtoken): Use scanner_t * instead of void *. (parse): Since yylex_init takes a void **, we use it to initialize a local void *, and then assign it to the structure member.
Diffstat (limited to 'parser.h')
-rw-r--r--parser.h14
1 files changed, 8 insertions, 6 deletions
diff --git a/parser.h b/parser.h
index bb85d01c..532fbfb1 100644
--- a/parser.h
+++ b/parser.h
@@ -24,6 +24,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+typedef struct yyguts_t scanner_t;
+
typedef struct {
cnum lineno;
int errors;
@@ -31,17 +33,17 @@ typedef struct {
val name;
val prepared_msg;
val syntax_tree;
- void *scanner;
+ scanner_t *scanner;
} parser_t;
extern const wchar_t *spec_file;
extern val form_to_ln_hash;
-void yyerror(void *scanner, parser_t *, const char *s);
-void yyerr(void *scanner, const char *s);
-void yyerrorf(void *scanner, val s, ...);
+void yyerror(scanner_t *scanner, parser_t *, const char *s);
+void yyerr(scanner_t *scanner, const char *s);
+void yyerrorf(scanner_t *scanner, val s, ...);
void yybadtoken(parser_t *, int tok, val context);
-void end_of_regex(void *scanner);
-void end_of_char(void *scanner);
+void end_of_regex(scanner_t *scanner);
+void end_of_char(scanner_t *scanner);
int yylex_init(void **pscanner);
int yylex_destroy(void *scanner);
parser_t *yyget_extra(void *scanner);