From dd7ebd40750c547df0dce9c9831053c94bb4f19b Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 30 Apr 2023 01:15:04 -0700 Subject: [PATCH] Entered "->" into parser, but does not have a data-structure. --- Makefile | 6 +++--- src/scan.h | 5 +++++ src/scan.re.c | 25 +++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 97e5b9b..aa42a2c 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ - optimize := -ffast-math +optimize := -ffast-math warnbasic := -Wall -pedantic #-ansi # -std=c99 warnclang := -Wextra -Weverything \ -Wno-comma \ @@ -30,7 +30,7 @@ else CF += -g endif -projects := bin/test-text bin/test-journal bin/test-source bin/test-kjv bin/kjv bin/flight bin/score bin/scan +projects := bin/test-text bin/test-journal bin/test-source bin/test-kjv bin/scan #docs := $(patsubst test/test_%.c, doc/%.md, $(wildcard test/test_*.c)) default: $(projects) @@ -70,7 +70,7 @@ build/%.c: src/%.re.c # # https://github.com/neil-edelman/cdoc documentation # -cdoc -o $@ $< -.SECONDARY: build/kjv.c build/journal.c build/source.c build/scan_kjv.c build/flights.c build/kjvcite.c build/scores.c build/scan.c +.SECONDARY: build/kjv.c build/journal.c build/scan.c .PHONY: clean release test test: $(projects) diff --git a/src/scan.h b/src/scan.h index f2b64f9..47d1061 100644 --- a/src/scan.h +++ b/src/scan.h @@ -26,6 +26,11 @@ struct score { #define ARRAY_HEAD #include "../src/array.h" + +//////// fixme: place + + + /* Glider array. */ #define LAUNCH_TYPE \ X(MotorCarTow),\ diff --git a/src/scan.re.c b/src/scan.re.c index 115403d..07ff422 100644 --- a/src/scan.re.c +++ b/src/scan.re.c @@ -122,9 +122,11 @@ static int scan_day(struct scan *const scan, union date32 date, glyph = [^\x00-\x20\x7f]; // [^\x00\n\t ] + all weird semitext = glyph \ ";"; natural = [1-9][0-9]*; - zero_natural = natural | "0"; + zero_natural = [0-9]+; + decimal = "-"? zero_natural ("." zero_natural?)?; uint = [0-9]+; keyword = [A-Za-z0-9][A-Za-z0-9_-]*; + label = semitext+ (" " semitext+)*; // perhaps??? do we want to include ;? date = natural "-" [0-1][0-9] "-" [0-3][0-9]; minutes = [0-5][0-9]; airport = [A-Z0-9]{4,4}; @@ -140,12 +142,28 @@ static int scan_day(struct scan *const scan, union date32 date, "\x00" { return 1; } /* End of day. */ "\n" => line { line++; continue; } * :=> skip + "->" :=> place "--" / [^-] :=> source "::" / [^:] :=> score "[glider]" :=> glider_type "[flight]" :=> flight_type + * { fail = "place unrecognized"; goto catch; } + @t0 "(" decimal "," decimal ")" @t1 ws+ @s0 label @s1 / "\n" + => skip { + const struct pair keyword = pair(s0, s1); + const struct pair coords = pair(t0, t1); + fprintf(stderr, "place: %.*s <<%.*s>>\n", + (int)(t1-t0), t0, (int)(s1-s0), s0); + continue; + } + @s0 label @s1 / "\n" => skip { + const struct pair keyword = pair(s0, s1); + fprintf(stderr, "place: <<%.*s>>\n", (int)(s1-s0), s0); + continue; + } + * { fail = "source unrecognized"; goto catch; } @s0 keyword @s1 / "\n" => skip { also_source: { const struct pair keyword = pair(s0, s1); @@ -235,11 +253,13 @@ static int scan_day(struct scan *const scan, union date32 date, => score_date { assert(new_score); new_score->name.a = s0, new_score->name.b = s1; + continue; } * { fail = "date unrecognized"; goto catch; } ws* "~"? @s0 date ws* ";" => score_edges { assert(new_score); if(!pair_to_date(s0, &new_score->date)) goto catch; + continue; } * { fail = "edges unrecognized"; goto catch; } ws* "~"? @s0 uint @s1 ws* / "\n" => skip { @@ -530,7 +550,8 @@ static int scan_day(struct scan *const scan, union date32 date, catch: if(!errno) errno = EILSEQ; date32_to_string(date, &datestr); - fprintf(stderr, "%s line %zu: %s condition %d.\n", datestr, line, fail, condition); + fprintf(stderr, "%s line %zu: %s" /*" condition %d"*/ ".\n", + datestr, line, fail/*, condition*/); return 0; }