Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bin/template
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,6 @@ template("../ext/yarp/extension.c", nodes, cmark)
template("../ext/yarp/yarp.c", nodes, cmark)
template("../lib/yarp.rb", nodes, rbmark)

pure_template(template: 'bin/templates/token_type.h.erb', write_to: 'ext/yarp/token_type.h', locals: { tokens: tokens })
pure_template(template: 'bin/templates/token_type.c.erb', write_to: 'ext/yarp/token_type.c', locals: { tokens: tokens })
pure_template(template: 'bin/templates/node.h.erb', write_to: 'ext/yarp/node.h', locals: { nodes: nodes })
pure_template(template: 'bin/templates/gen_token_type.h.erb', write_to: 'ext/yarp/gen_token_type.h', locals: { tokens: tokens })
pure_template(template: 'bin/templates/gen_token_type.c.erb', write_to: 'ext/yarp/gen_token_type.c', locals: { tokens: tokens })
pure_template(template: 'bin/templates/gen_node.h.erb', write_to: 'ext/yarp/gen_node.h', locals: { nodes: nodes })
7 changes: 6 additions & 1 deletion bin/templates/node.h.erb → bin/templates/gen_node.h.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/******************************************************************************/
/* This file is generated by the bin/template script and should not be */
/* modified manually. */
/******************************************************************************/

#ifndef YARP_NODE_H
#define YARP_NODE_H

Expand All @@ -12,7 +17,7 @@ typedef enum {
} yp_node_type_t;

struct yp_node;
struct yp_node;

typedef struct yp_node_list {
struct yp_node **nodes;
size_t size;
Expand Down
30 changes: 30 additions & 0 deletions bin/templates/gen_token_type.c.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/******************************************************************************/
/* This file is generated by the bin/template script and should not be */
/* modified manually. */
/******************************************************************************/

#include "gen_token_type.h"
#include <string.h>

const char *
token_type_to_str(yp_token_type_t token_type)
{
switch (token_type) {
<%- tokens.each do |token| -%>
case YP_TOKEN_<%= token.name %>:
return "<%= token.name %>";
<%- end -%>
case YP_TOKEN_MAXIMUM:
return "MAXIMUM";
}
}

yp_token_type_t
token_type_from_str(const char *str)
{
<%- tokens.sort_by { |token| [*token.name.split("_"), *5.times.map { "ZZZ" }] }.each do |token| -%>
if (strncmp(str, "<%= token.name %>", <%= token.name.length %>) == 0) return YP_TOKEN_<%= token.name %>;
<%- end -%>
// Fallback
return YP_TOKEN_INVALID;
}
19 changes: 19 additions & 0 deletions bin/templates/gen_token_type.h.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/******************************************************************************/
/* This file is generated by the bin/template script and should not be */
/* modified manually. */
/******************************************************************************/

#ifndef YARP_TOKEN_TYPE_H
#define YARP_TOKEN_TYPE_H

typedef enum yp_token_type {
<%- tokens.each do |token| -%>
<%= token.declaration %>
<%- end -%>
YP_TOKEN_MAXIMUM, // the maximum token value
} yp_token_type_t;

const char *token_type_to_str(yp_token_type_t token_type);
yp_token_type_t token_type_from_str(const char *str);

#endif // YARP_TOKEN_TYPE_H
28 changes: 0 additions & 28 deletions bin/templates/token_type.c.erb

This file was deleted.

14 changes: 0 additions & 14 deletions bin/templates/token_type.h.erb

This file was deleted.

2 changes: 1 addition & 1 deletion ext/yarp/extension.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "token_type.h"
#include "gen_token_type.h"
#include "yarp.h"
#include <ruby.h>

Expand Down
7 changes: 6 additions & 1 deletion ext/yarp/node.h → ext/yarp/gen_node.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/******************************************************************************/
/* This file is generated by the bin/template script and should not be */
/* modified manually. */
/******************************************************************************/

#ifndef YARP_NODE_H
#define YARP_NODE_H

Expand Down Expand Up @@ -28,7 +33,7 @@ typedef enum {
} yp_node_type_t;

struct yp_node;
struct yp_node;

typedef struct yp_node_list {
struct yp_node **nodes;
size_t size;
Expand Down
Loading