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
5 changes: 2 additions & 3 deletions gherkin/c/gherkin-c-parser.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#include "token_scanner.h"
#include "token_matcher.h"
#include "token_queue.h"
#include "builder.h"
#include "error_list.h"
#include <stdlib.h>
#include <setjmp.h>
Expand All @@ -46,11 +45,11 @@ typedef struct ParserContext {
ErrorList* errors;
} ParserContext;

typedef struct @Model.ParserClassName {
struct @Model.ParserClassName {
ParserContext* parser_context;
Builder* builder;
ErrorList* errors;
} @Model.ParserClassName;
};

static Token* read_token(ParserContext* context);

Expand Down
9 changes: 3 additions & 6 deletions gherkin/c/include/builder.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#ifndef GHERKIN_BUILDER_H_
#define GHERKIN_BUILDER_H_

#include "error_list.h"
#include "rule_type.h"
#include "token.h"

typedef struct ErrorList ErrorList;

typedef struct Builder Builder;

typedef void (*builder_reset_function) (Builder*);
Expand All @@ -16,14 +15,12 @@ typedef void (*build_function) (Builder*, Token*);

typedef void (*rule_function) (Builder*, RuleType);

typedef void (*rule_function) (Builder*, RuleType);

typedef struct Builder {
struct Builder {
builder_reset_function reset;
builder_error_context_function set_error_context;
build_function build;
rule_function start_rule;
rule_function end_rule;
} Builder;
};

#endif /* GHERKIN_BUILDER_H_ */
6 changes: 2 additions & 4 deletions gherkin/c/include/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@

#include <stdbool.h>
#include <wchar.h>
#include "gherkin_document.h"
#include "pickle.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct Compiler Compiler;

typedef struct GherkinDocument GherkinDocument;

typedef struct Pickle Pickle;

Compiler* Compiler_new();

void Compiler_delete(Compiler* compiler);
Expand Down
4 changes: 2 additions & 2 deletions gherkin/c/include/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ typedef enum EventType {
Gherkin_PickleEvent
} EventType;

typedef struct Event {
struct Event {
event_delete_function event_delete;
event_print_function event_print;
EventType event_type;
} Event;
};

void Event_delete(const Event* event);

Expand Down
4 changes: 2 additions & 2 deletions gherkin/c/include/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ typedef struct Item Item;

typedef void (*item_delete_function) (Item*);

typedef struct Item {
struct Item {
item_delete_function item_delete;
} Item;
};

#endif /* GHERKIN_ITEM_H_ */
11 changes: 3 additions & 8 deletions gherkin/c/include/parser.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#ifndef GHERKIN_PARSER_H_
#define GHERKIN_PARSER_H_

#include "builder.h"
#include "error.h"
#include "token_matcher.h"
#include "token_scanner.h"
#include <stdbool.h>
#include <wchar.h>

Expand All @@ -11,14 +14,6 @@ extern "C" {

typedef struct Parser Parser;

typedef struct Builder Builder;

typedef struct TokenMatcher TokenMatcher;

typedef struct TokenScanner TokenScanner;

typedef struct Feature Feature;

Parser* Parser_new(Builder* builder);

void Parser_delete(Parser* parser);
Expand Down
10 changes: 4 additions & 6 deletions gherkin/c/include/token_matcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
#define GHERKIN_TOKEN_MATCHER_H_

#include <stdbool.h>
#include "dialect.h"
#include "error_list.h"
#include "token.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct Dialect Dialect;

typedef struct ErrorList ErrorList;

typedef struct TokenMatcher TokenMatcher;

typedef void (*matcher_reset_function) (TokenMatcher*);

typedef bool (*match_function) (TokenMatcher*, Token*);

typedef struct TokenMatcher {
struct TokenMatcher {
const wchar_t* default_language;
const wchar_t* language;
const Dialect* dialect;
Expand All @@ -40,7 +38,7 @@ typedef struct TokenMatcher {
match_function match_Language;
match_function match_Other;
match_function match_EOF;
} TokenMatcher;
};

TokenMatcher* TokenMatcher_new(const wchar_t* default_language);

Expand Down
4 changes: 2 additions & 2 deletions gherkin/c/include/token_scanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ typedef Token* (*read_function) (TokenScanner*);

typedef void (*delete_function) (TokenScanner*);

typedef struct TokenScanner {
struct TokenScanner {
read_function read;
delete_function delete;
} TokenScanner;
};

void TokenScanner_delete(TokenScanner* token_scanner);

Expand Down
8 changes: 4 additions & 4 deletions gherkin/c/src/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
GCC_FLAGS=-c -Wall -Werror -g
CLANG_FLAGS=-c -Wall -Wno-typedef-redefinition -Werror -g
CLANG_FLAGS=-c -Wall -Werror -g

ifeq ($(CC),i686-w64-mingw32-gcc)
CC=i686-w64-mingw32-gcc
Expand All @@ -21,7 +21,7 @@ endif
GENERATE_DEPS_FLAGS=-MMD -MP -MF $(basename $@).d
AR_FLAGS=cr
LD_FLAGS=
LD_LIBS=
LD_LIBS=-lm
RM_CMD=rm -rf
MKDIR_CMD=mkdir -p

Expand All @@ -42,8 +42,8 @@ UTILITIES_OBJS= \
../objs/file_utf8_source.o \
../objs/print_utilities.o \
../objs/string_utilities.o \
../objs/utf8_source.o \
../objs/utf8_utilities.o
../objs/unicode_utilities.o \
../objs/utf8_source.o
-include $(UTILITIES_OBJS:.o=.d)

PARSER_OBJS= \
Expand Down
1 change: 0 additions & 1 deletion gherkin/c/src/ast_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "scenario_outline.h"
#include "data_table.h"
#include "doc_string.h"
#include "error_list.h"
#include <stdio.h>
#include <stdlib.h>

Expand Down
41 changes: 30 additions & 11 deletions gherkin/c/src/ast_printer.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ static void print_doc_string(FILE* file, const DocString* doc_string) {
fprintf(file, "{\"type\":\"%ls\",", ast_item_type_to_string(doc_string->type));
print_location(file, &doc_string->location);
if (doc_string->content_type) {
fprintf(file, "\"contentType\":\"%ls\",", doc_string->content_type);
fprintf(file, "\"contentType\":\"");
PrintUtilities_print_json_string(file, doc_string->content_type);
fprintf(file, "\",");
}
fprintf(file, "\"content\":\"");
if (doc_string->content) {
Expand All @@ -102,11 +104,23 @@ static void print_doc_string(FILE* file, const DocString* doc_string) {
fprintf(file, "\"}");
}

static void print_keyword(FILE* file, const wchar_t* keyword) {
fprintf(file, "\"keyword\":\"");
PrintUtilities_print_json_string(file, keyword);
fprintf(file, "\",");
}

static void print_text(FILE* file, const wchar_t* text) {
fprintf(file, "\"text\":\"");
PrintUtilities_print_json_string(file, text);
fprintf(file, "\"");
}

static void print_step(FILE* file, const Step* step) {
fprintf(file, "{\"type\":\"%ls\",", ast_item_type_to_string(step->type));
print_location(file, &step->location);
fprintf(file, "\"keyword\":\"%ls\",", step->keyword);
fprintf(file, "\"text\":\"%ls\"", step->text);
print_keyword(file, step->keyword);
print_text(file, step->text);
if (step->argument) {
fprintf(file, ",\"argument\":");
if (step->argument->type == Gherkin_DataTable) {
Expand Down Expand Up @@ -136,7 +150,7 @@ static void print_description(FILE* file, const wchar_t* description) {
static void print_background(FILE* file, const Background* background) {
fprintf(file, "{\"type\":\"%ls\",", ast_item_type_to_string(background->type));
print_location(file, &background->location);
fprintf(file, "\"keyword\":\"%ls\",", background->keyword);
print_keyword(file, background->keyword);
print_name(file, background->name);
print_description(file, background->description);
fprintf(file, "\"steps\":[");
Expand All @@ -153,7 +167,9 @@ static void print_background(FILE* file, const Background* background) {
static void print_tag(FILE* file, const Tag* tag) {
fprintf(file, "{\"type\":\"%ls\",", ast_item_type_to_string(tag->type));
print_location(file, &tag->location);
fprintf(file, "\"name\":\"%ls\"}", tag->name);
fprintf(file, "\"name\":\"");
PrintUtilities_print_json_string(file, tag->name);
fprintf(file, "\"}");
}

static void print_scenario(FILE* file, const Scenario* scenario) {
Expand All @@ -168,7 +184,7 @@ static void print_scenario(FILE* file, const Scenario* scenario) {
}
fprintf(file, "],");
print_location(file, &scenario->location);
fprintf(file, "\"keyword\":\"%ls\",", scenario->keyword);
print_keyword(file, scenario->keyword);
print_name(file, scenario->name);
print_description(file, scenario->description);
fprintf(file, "\"steps\":[");
Expand All @@ -185,7 +201,7 @@ static void print_example_table(FILE* file, const ExampleTable* example_table) {
fprintf(file, "{\"type\":\"%ls\",", ast_item_type_to_string(example_table->type));
print_location(file, &example_table->location);
print_description(file, example_table->description);
fprintf(file, "\"keyword\":\"%ls\",", example_table->keyword);
print_keyword(file, example_table->keyword);
print_name(file, example_table->name);
fprintf(file, "\"tags\":[");
int i;
Expand Down Expand Up @@ -227,7 +243,7 @@ static void print_scenario_outline(FILE* file, const ScenarioOutline* scenario_o
}
fprintf(file, "],");
print_location(file, &scenario_outline->location);
fprintf(file, "\"keyword\":\"%ls\",", scenario_outline->keyword);
print_keyword(file, scenario_outline->keyword);
print_name(file, scenario_outline->name);
print_description(file, scenario_outline->description);
fprintf(file, "\"steps\":[");
Expand All @@ -251,7 +267,8 @@ static void print_scenario_outline(FILE* file, const ScenarioOutline* scenario_o
static void print_comment(FILE* file, const Comment* comment) {
fprintf(file, "{\"type\":\"%ls\",", ast_item_type_to_string(comment->type));
print_location(file, &comment->location);
fprintf(file, "\"text\":\"%ls\"}", comment->text);
print_text(file, comment->text);
fprintf(file, "}");
}

void print_feature(FILE* file, const Feature* feature) {
Expand All @@ -267,8 +284,10 @@ void print_feature(FILE* file, const Feature* feature) {
}
fprintf(file, "],");
print_location(file, &feature->location);
fprintf(file, "\"language\":\"%ls\",", feature->language);
fprintf(file, "\"keyword\":\"%ls\",", feature->keyword);
fprintf(file, "\"language\":\"");
PrintUtilities_print_json_string(file, feature->language);
fprintf(file, "\",");
print_keyword(file, feature->keyword);
print_name(file, feature->name);
print_description(file, feature->description);
fprintf(file, "\"children\":[");
Expand Down
11 changes: 7 additions & 4 deletions gherkin/c/src/attachment_event.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "attachment_event.h"
#include "print_utilities.h"
#include "string_utilities.h"
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -46,12 +47,14 @@ static void AttachmentEvent_print(const Event* event, FILE* file) {
}
const AttachmentEvent* attachment_event = (const AttachmentEvent*)event;
fprintf(file, "{");
fprintf(file, "\"data\":\"%ls\",", attachment_event->data);
fprintf(file, "\"media\":{\"encoding\":\"utf-8\",\"type\":\"text/vnd.cucumber.stacktrace+plain\"},");
fprintf(file, "\"data\":\"");
PrintUtilities_print_json_string(file, attachment_event->data);
fprintf(file, "\",\"media\":{\"encoding\":\"utf-8\",\"type\":\"text/vnd.cucumber.stacktrace+plain\"},");
fprintf(file, "\"source\":{\"start\":");
fprintf(file, "{\"line\":%d,", attachment_event->location.line);
fprintf(file, "\"column\":%d},", attachment_event->location.column);
fprintf(file, "\"uri\":\"%ls\"},", attachment_event->uri);
fprintf(file, "\"type\":\"attachment\"");
fprintf(file, "\"uri\":\"");
PrintUtilities_print_json_string(file, attachment_event->uri);
fprintf(file, "\"},\"type\":\"attachment\"");
fprintf(file, "}\n");
}
9 changes: 5 additions & 4 deletions gherkin/c/src/compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
#include "pickle_table.h"
#include "pickle_tag.h"
#include "pickle_string.h"
#include "string_utilities.h"
#include <stdlib.h>

typedef struct Compiler {
struct Compiler {
ItemQueue* pickle_list;
} Compiler;
};

typedef struct ReplacementItem {
item_delete_function item_delete;
Expand Down Expand Up @@ -103,7 +104,7 @@ int Compiler_compile(Compiler* compiler, const GherkinDocument* gherkin_document
}
int j;
for (j = 0; j < scenario_outline->steps->step_count; ++j) {
int column_offset = scenario_outline->steps->steps[j].keyword ? wcslen(scenario_outline->steps->steps[j].keyword) : 0;
int column_offset = scenario_outline->steps->steps[j].keyword ? StringUtilities_code_point_length(scenario_outline->steps->steps[j].keyword) : 0;
const PickleLocations* step_locations = PickleLocations_new_double(table_row->location.line, table_row->location.column, scenario_outline->steps->steps[j].location.line, scenario_outline->steps->steps[j].location.column + column_offset);
const PickleStep* step = expand_outline_step(&scenario_outline->steps->steps[j], example_table->table_header, table_row, step_locations);
PickleStep_transfer(&steps->steps[background_step_count + j], (PickleStep*)step);
Expand Down Expand Up @@ -225,7 +226,7 @@ static void copy_tags(PickleTag* destination_array, const Tags* source) {
static void copy_steps(PickleStep* destination_array, const Steps* source) {
int i;
for (i = 0; i < source->step_count; ++i) {
int column_offset = source->steps[i].keyword ? wcslen(source->steps[i].keyword) : 0;
int column_offset = source->steps[i].keyword ? StringUtilities_code_point_length(source->steps[i].keyword) : 0;
const PickleLocations* step_locations = PickleLocations_new_single(source->steps[i].location.line, source->steps[i].location.column + column_offset);
const PickleArgument* argument = create_pickle_argument(source->steps[i].argument, 0, 0);
const PickleStep* step = PickleStep_new(step_locations, source->steps[i].text, argument);
Expand Down
Loading