From f22378937db114256bc787c942c1f189b009dfbe Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 23 May 2012 17:26:35 -0300 Subject: [PATCH] b2/: add parsing of supplemental symbol information (option -X) --- b2/bom.c | 15 ++++++++++++++- b2/bom.h | 1 + b2/boom.c | 3 +++ b2/lang.h | 1 + b2/lang.l | 6 ++++++ b2/lang.y | 18 ++++++++++++++++++ 6 files changed, 43 insertions(+), 1 deletion(-) diff --git a/b2/bom.c b/b2/bom.c index 4fe7820..144025b 100644 --- a/b2/bom.c +++ b/b2/bom.c @@ -46,7 +46,7 @@ struct bom *bom_parse_line(const char *s) s++; for (t = s+1; *t && !isspace(*t); t++); if (!*t) - yyerror("invalid BOM record (1)\n"); + yyerror("invalid BOM record"); ref = unique_n(s, t-s); if (bom_find(ref)) @@ -86,3 +86,16 @@ struct bom *bom_parse_line(const char *s) } return b; } + + +void bom_set_sym(const char *ref, const char *sym) +{ + struct bom *b; + + b = bom_find(ref); + if (!b) + yyerrorf("cannot find component reference \"%s\"", ref); + if (b->sym) + yyerrorf("symbol is already set in \"%s\"", ref); + b->sym = sym; +} diff --git a/b2/bom.h b/b2/bom.h index c8de71c..1315339 100644 --- a/b2/bom.h +++ b/b2/bom.h @@ -30,5 +30,6 @@ extern int n_bom; struct bom *bom_parse_line(const char *s); +void bom_set_sym(const char *ref, const char *sym); #endif /* !BOM_H */ diff --git a/b2/boom.c b/b2/boom.c index 02153f0..5b9257b 100644 --- a/b2/boom.c +++ b/b2/boom.c @@ -83,6 +83,7 @@ static void usage(const char *name) " -p providers\n" " -s substitutions\n" " -b KiCad eeschema BOM\n" +" -X symbols (BOM supplement)\n" " -q var=value ... run substitutions with the specified inputs\n" " -Q var=value ... run substitutions and then do parametric search\n" , name); @@ -110,6 +111,8 @@ int main(int argc, char **argv) process = parse_substitutions; else if (!strcmp(argv[i], "-b")) process = parse_kicad_bom; + else if (!strcmp(argv[i], "-X")) + process = parse_symbols; else if (!strcmp(argv[i], "-q")) process = add_var; else if (!strcmp(argv[i], "-Q")) { diff --git a/b2/lang.h b/b2/lang.h index 78f0f04..fa1256e 100644 --- a/b2/lang.h +++ b/b2/lang.h @@ -29,6 +29,7 @@ void parse_currencies(const char *name); void parse_providers(const char *name); void parse_substitutions(const char *name); void parse_kicad_bom(const char *name); +void parse_symbols(const char *name); void yywarnf(const char *fmt, ...); void __attribute__((noreturn)) yyerrorf(const char *fmt, ...); diff --git a/b2/lang.l b/b2/lang.l index 7941d54..97ae698 100644 --- a/b2/lang.l +++ b/b2/lang.l @@ -97,6 +97,12 @@ void parse_substitutions(const char *name) do_parse(name, START_SUBST, 0, 1); } + +void parse_symbols(const char *name) +{ + do_parse(name, START_SYMBOLS, 1, 0); +} + %} diff --git a/b2/lang.y b/b2/lang.y index 1055726..0a0b7f7 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -102,6 +102,7 @@ static struct subst *parse_jump(const char *keyword, const char *target) %token START_HIERARCHY START_CHAR START_INVENTORY %token START_EXCHANGE START_PROVIDERS START_SUBST START_BOM +%token START_SYMBOLS %token BOM_EESCHEMA %token TOK_LE TOK_GE TOK_NL %token WORD PATTERN @@ -140,6 +141,7 @@ all: substitutions = $2; } | START_BOM bom + | START_SYMBOLS symbols ; @@ -669,3 +671,19 @@ bom: * bom.c */ ; + + +/* ----- Symbols (BOM supplement) ------------------------------------------ */ + + +symbols: + | TOK_NL + | symbol symbols + ; + +symbol: + WORD WORD TOK_NL + { + bom_set_sym($1, $2); + } + ;