2012-03-18 18:24:12 +02:00
|
|
|
%{
|
2012-05-22 03:25:29 +03:00
|
|
|
/*
|
2012-03-18 18:24:12 +02:00
|
|
|
* lang.y - BOOM grammar
|
|
|
|
*
|
|
|
|
* Copyright 2012 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2012-04-25 23:14:39 +03:00
|
|
|
#include <assert.h>
|
2012-03-18 18:24:12 +02:00
|
|
|
|
|
|
|
#include "util.h"
|
2012-05-21 20:35:51 +03:00
|
|
|
#include "relop.h"
|
2012-03-18 18:24:12 +02:00
|
|
|
#include "param.h"
|
|
|
|
#include "chr.h"
|
2012-04-28 17:46:42 +03:00
|
|
|
#include "db.h"
|
2012-05-20 17:18:18 +03:00
|
|
|
#include "subst.h"
|
2012-04-29 04:12:33 +03:00
|
|
|
#include "lang.h"
|
2012-03-18 18:24:12 +02:00
|
|
|
|
|
|
|
#include "y.tab.h"
|
|
|
|
|
2012-04-25 23:14:39 +03:00
|
|
|
|
2012-05-22 19:01:39 +03:00
|
|
|
const char *dollar;
|
|
|
|
|
2012-05-21 01:00:04 +03:00
|
|
|
struct action hierarchy;
|
|
|
|
struct subst *substitutions = NULL;
|
|
|
|
|
2012-05-01 04:49:33 +03:00
|
|
|
static struct currency *curr;
|
|
|
|
|
2012-04-29 04:50:15 +03:00
|
|
|
|
2012-04-25 23:14:39 +03:00
|
|
|
static struct field_stack {
|
|
|
|
const struct field *field;
|
|
|
|
struct field_stack *next;
|
|
|
|
} *field_stack = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
static void push_field(const struct field *field)
|
|
|
|
{
|
|
|
|
struct field_stack *entry;
|
|
|
|
|
|
|
|
entry = alloc_type(struct field_stack);
|
|
|
|
entry->field = field;
|
|
|
|
entry->next = field_stack;
|
|
|
|
field_stack = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void pop_field(void)
|
|
|
|
{
|
|
|
|
struct field_stack *entry;
|
|
|
|
|
|
|
|
assert(field_stack);
|
|
|
|
entry = field_stack;
|
|
|
|
field_stack = entry->next;
|
|
|
|
free(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const struct field *top_field(void)
|
|
|
|
{
|
|
|
|
return field_stack ? field_stack->field : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-22 21:57:55 +03:00
|
|
|
static struct subst *parse_jump(const char *keyword, const char *target)
|
|
|
|
{
|
|
|
|
if (!strcmp(keyword, "break"))
|
|
|
|
return subst_break(target);
|
|
|
|
if (!strcmp(keyword, "continue"))
|
|
|
|
return subst_continue(target);
|
|
|
|
yyerrorf("unknown keyword \"%s\"", keyword);
|
|
|
|
}
|
|
|
|
|
2012-03-18 18:24:12 +02:00
|
|
|
%}
|
|
|
|
|
|
|
|
|
|
|
|
%union {
|
|
|
|
const char *s;
|
2012-05-01 02:03:10 +03:00
|
|
|
int num;
|
|
|
|
double fnum;
|
2012-03-18 18:24:12 +02:00
|
|
|
struct equiv *equiv;
|
|
|
|
struct names *names;
|
|
|
|
struct format *format;
|
|
|
|
enum relop relop;
|
2012-04-25 23:14:39 +03:00
|
|
|
struct field *field;
|
|
|
|
struct selector *sel;
|
|
|
|
struct condition *cond;
|
|
|
|
struct action act;
|
2012-04-28 17:46:42 +03:00
|
|
|
struct part *part;
|
|
|
|
struct param *param;
|
2012-05-01 02:03:10 +03:00
|
|
|
struct price *price;
|
|
|
|
struct stock *stock;
|
2012-05-01 20:57:12 +03:00
|
|
|
struct provider *prov;
|
2012-05-20 17:18:18 +03:00
|
|
|
struct subst *subst;
|
2012-03-18 18:24:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-05-01 02:03:10 +03:00
|
|
|
%token START_HIERARCHY START_CHAR START_INVENTORY
|
2012-05-23 22:05:24 +03:00
|
|
|
%token START_EXCHANGE START_PROVIDERS START_SUBST START_BOM
|
2012-05-23 23:26:35 +03:00
|
|
|
%token START_SYMBOLS
|
2012-05-23 22:05:24 +03:00
|
|
|
%token BOM_EESCHEMA
|
2012-04-28 17:46:42 +03:00
|
|
|
%token TOK_LE TOK_GE TOK_NL
|
2012-05-20 17:18:18 +03:00
|
|
|
%token <s> WORD PATTERN
|
2012-03-18 18:24:12 +02:00
|
|
|
|
2012-05-01 02:03:10 +03:00
|
|
|
%type <num> int
|
|
|
|
%type <fnum> float
|
2012-03-18 18:24:12 +02:00
|
|
|
%type <equiv> nameqs
|
|
|
|
%type <names> names nameq
|
|
|
|
%type <format> format
|
|
|
|
%type <relop> relop opt_relop
|
2012-04-25 23:14:39 +03:00
|
|
|
%type <field> /*rules*/ opt_rule rule opt_fields fields field
|
|
|
|
%type <sel> selectors
|
|
|
|
%type <cond> conditions condition
|
2012-05-21 01:00:04 +03:00
|
|
|
%type <act> hierarchy opt_wildcard action
|
2012-05-01 02:03:10 +03:00
|
|
|
%type <part> part inventory_item
|
2012-04-28 17:46:42 +03:00
|
|
|
%type <param> param params
|
2012-05-01 02:03:10 +03:00
|
|
|
%type <price> prices price
|
|
|
|
%type <stock> stock
|
2012-05-01 20:57:12 +03:00
|
|
|
%type <prov> providers provider
|
2012-05-21 01:00:04 +03:00
|
|
|
%type <subst> substitutions block opt_block
|
2012-05-22 19:01:39 +03:00
|
|
|
%type <s> word_or_dollar
|
2012-03-18 18:24:12 +02:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
all:
|
2012-04-26 09:02:48 +03:00
|
|
|
START_HIERARCHY hierarchy
|
2012-05-21 01:00:04 +03:00
|
|
|
{
|
|
|
|
hierarchy = $2;
|
|
|
|
}
|
2012-04-28 17:46:42 +03:00
|
|
|
| START_CHAR characteristics
|
2012-05-01 02:03:10 +03:00
|
|
|
| START_INVENTORY inventory
|
2012-05-01 04:49:33 +03:00
|
|
|
| START_EXCHANGE exchange
|
2012-05-01 20:57:12 +03:00
|
|
|
| START_PROVIDERS providers
|
2012-05-20 17:18:18 +03:00
|
|
|
| START_SUBST substitutions
|
2012-05-21 01:00:04 +03:00
|
|
|
{
|
|
|
|
substitutions = $2;
|
|
|
|
}
|
2012-05-23 22:05:24 +03:00
|
|
|
| START_BOM bom
|
2012-05-23 23:26:35 +03:00
|
|
|
| START_SYMBOLS symbols
|
2012-04-26 09:02:48 +03:00
|
|
|
;
|
|
|
|
|
2012-05-01 02:03:10 +03:00
|
|
|
|
|
|
|
/* ----- Characteristics hierarchy ----------------------------------------- */
|
|
|
|
|
|
|
|
|
2012-04-26 09:02:48 +03:00
|
|
|
hierarchy:
|
|
|
|
nameset hierarchy
|
2012-05-21 01:00:04 +03:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2012-04-29 05:30:50 +03:00
|
|
|
| action
|
2012-04-25 23:14:39 +03:00
|
|
|
{
|
2012-05-21 01:00:04 +03:00
|
|
|
$$ = $1;
|
2012-05-30 17:53:58 +03:00
|
|
|
fields_dump(stderr, $1.fields);
|
|
|
|
if ($1.fields)
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
rules_dump(stderr, $1.rules);
|
2012-04-25 23:14:39 +03:00
|
|
|
}
|
2012-03-18 18:24:12 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
nameset:
|
|
|
|
'<' WORD '>' '=' names ';'
|
|
|
|
{
|
|
|
|
register_nameset($2, $5);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
names:
|
|
|
|
nameq
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| nameq '<' names
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->next = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
nameq:
|
|
|
|
nameqs
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct names);
|
|
|
|
$$->equiv = $1;
|
|
|
|
$$->next = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
nameqs:
|
|
|
|
WORD
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct equiv);
|
|
|
|
$$->name = $1;
|
|
|
|
$$->next = NULL;
|
|
|
|
}
|
|
|
|
| WORD '=' nameqs
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct equiv);
|
|
|
|
$$->name = $1;
|
|
|
|
$$->next = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-04-25 23:14:39 +03:00
|
|
|
/*
|
|
|
|
* @@@ for now, we can't select on a collective of fields. maybe later, with
|
|
|
|
* a syntax change.
|
|
|
|
*
|
2012-03-18 18:24:12 +02:00
|
|
|
rules:
|
|
|
|
{
|
2012-04-25 23:14:39 +03:00
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| rule rules
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->next = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
*/
|
|
|
|
|
|
|
|
opt_rule:
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
2012-03-18 18:24:12 +02:00
|
|
|
}
|
2012-04-25 23:14:39 +03:00
|
|
|
| rule
|
2012-03-18 18:24:12 +02:00
|
|
|
{
|
2012-04-25 23:14:39 +03:00
|
|
|
$$ = $1;
|
2012-03-18 18:24:12 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-04-25 23:14:39 +03:00
|
|
|
rule:
|
|
|
|
field
|
|
|
|
{
|
|
|
|
$1->prev = top_field();
|
|
|
|
push_field($1);
|
|
|
|
}
|
|
|
|
'{' selectors opt_wildcard '}'
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->sel = $4;
|
|
|
|
$$->any = $5;
|
|
|
|
$$->next = NULL;
|
|
|
|
field_finalize($$);
|
|
|
|
pop_field();
|
|
|
|
}
|
2012-03-18 18:24:12 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
selectors:
|
|
|
|
{
|
2012-04-25 23:14:39 +03:00
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| conditions ':' action selectors
|
|
|
|
{
|
2012-04-26 08:48:08 +03:00
|
|
|
$$ = new_selector();
|
2012-04-25 23:14:39 +03:00
|
|
|
$$->cond = $1;
|
|
|
|
$$->act = $3;
|
|
|
|
$$->next = $4;
|
2012-03-18 18:24:12 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-04-25 23:14:39 +03:00
|
|
|
conditions:
|
|
|
|
condition
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| condition '|' conditions
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->next = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
condition:
|
2012-03-18 18:24:12 +02:00
|
|
|
opt_relop WORD
|
|
|
|
{
|
2012-04-26 08:48:08 +03:00
|
|
|
$$ = new_condition($1, $2);
|
2012-03-18 18:24:12 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_wildcard:
|
|
|
|
{
|
2012-04-25 23:14:39 +03:00
|
|
|
$$.fields = NULL;
|
|
|
|
$$.rules = NULL;
|
|
|
|
}
|
|
|
|
| '*' ':' action
|
|
|
|
{
|
|
|
|
$$ = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
action:
|
|
|
|
{
|
|
|
|
push_field(top_field());
|
|
|
|
}
|
|
|
|
opt_fields opt_rule ';'
|
|
|
|
{
|
|
|
|
$$.fields = $2;
|
|
|
|
$$.rules = $3;
|
|
|
|
pop_field();
|
2012-03-18 18:24:12 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_relop:
|
|
|
|
{
|
|
|
|
$$ = rel_eq;
|
|
|
|
}
|
|
|
|
| relop
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
relop:
|
|
|
|
'='
|
|
|
|
{
|
|
|
|
$$ = rel_eq;
|
|
|
|
}
|
|
|
|
| '<'
|
|
|
|
{
|
|
|
|
$$ = rel_le;
|
|
|
|
}
|
|
|
|
| '>'
|
|
|
|
{
|
|
|
|
$$ = rel_gt;
|
|
|
|
}
|
|
|
|
| TOK_LE
|
|
|
|
{
|
|
|
|
$$ = rel_le;
|
|
|
|
}
|
|
|
|
| TOK_GE
|
|
|
|
{
|
|
|
|
$$ = rel_ge;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
opt_fields:
|
2012-04-25 23:14:39 +03:00
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
2012-03-18 18:24:12 +02:00
|
|
|
| '{' fields '}'
|
2012-04-25 23:14:39 +03:00
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
2012-03-18 18:24:12 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
fields:
|
2012-04-25 23:14:39 +03:00
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| field
|
|
|
|
{
|
|
|
|
push_field($1);
|
|
|
|
}
|
|
|
|
fields
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->next = $3;
|
|
|
|
pop_field();
|
|
|
|
$$->prev = top_field();
|
|
|
|
if ($3)
|
|
|
|
$3->prev = $1;
|
|
|
|
}
|
2012-03-18 18:24:12 +02:00
|
|
|
;
|
|
|
|
|
|
|
|
field:
|
2012-04-26 00:25:35 +03:00
|
|
|
WORD '=' format
|
2012-03-18 18:24:12 +02:00
|
|
|
{
|
2012-04-26 08:48:08 +03:00
|
|
|
$$ = new_field($1, $3, top_field());
|
2012-03-18 18:24:12 +02:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
format:
|
|
|
|
'*'
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct format);
|
|
|
|
$$->ops = ¶m_ops_name;
|
|
|
|
}
|
|
|
|
| '<' WORD '>'
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct format);
|
|
|
|
$$->ops = ¶m_ops_set;
|
|
|
|
$$->u.set = find_nameset($2);
|
|
|
|
if (!$$->u.set)
|
|
|
|
yyerrorf("unknown name set \"%s\"", $2);
|
|
|
|
}
|
|
|
|
| '#' WORD
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct format);
|
|
|
|
$$->ops = ¶m_ops_abs;
|
|
|
|
$$->u.abs = $2;
|
|
|
|
}
|
|
|
|
| '%' WORD
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct format);
|
|
|
|
$$->ops = ¶m_ops_rel;
|
2012-04-25 23:14:39 +03:00
|
|
|
$$->u.rel = field_find($2, top_field());
|
2012-03-18 18:24:12 +02:00
|
|
|
if (!$$->u.rel)
|
|
|
|
yyerrorf("unknown field \"%s\"", $2);
|
|
|
|
}
|
|
|
|
;
|
2012-04-28 17:46:42 +03:00
|
|
|
|
2012-05-01 02:03:10 +03:00
|
|
|
|
|
|
|
/* ----- Part characteristics --------------------------------------------- */
|
|
|
|
|
|
|
|
|
2012-04-28 17:46:42 +03:00
|
|
|
characteristics:
|
|
|
|
| TOK_NL
|
|
|
|
| part characteristics
|
2012-04-29 04:50:15 +03:00
|
|
|
{
|
2012-04-29 05:30:50 +03:00
|
|
|
part_finalize($1, &hierarchy);
|
2012-04-29 05:26:22 +03:00
|
|
|
part_dump(stderr, $1);
|
2012-04-29 04:50:15 +03:00
|
|
|
}
|
2012-04-28 17:46:42 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
part:
|
|
|
|
WORD WORD params TOK_NL
|
|
|
|
{
|
2012-05-01 02:40:11 +03:00
|
|
|
$$ = part_add($1, $2);
|
2012-04-28 17:46:42 +03:00
|
|
|
if ($$->param)
|
|
|
|
yyerror("parameters already defined");
|
|
|
|
$$->param = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
params:
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| param params
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->next = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
param:
|
|
|
|
WORD '=' WORD
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct param);
|
|
|
|
$$->u.name = $1;
|
2012-05-21 20:35:51 +03:00
|
|
|
$$->op = rel_eq;
|
2012-05-21 20:44:33 +03:00
|
|
|
$$->value.u.s = $3;
|
2012-04-28 17:46:42 +03:00
|
|
|
}
|
|
|
|
;
|
2012-05-01 02:03:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* ----- Part inventory ---------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
inventory:
|
|
|
|
| TOK_NL
|
|
|
|
| inventory_item inventory
|
2012-05-01 02:40:11 +03:00
|
|
|
{
|
|
|
|
part_dump(stderr, $1);
|
|
|
|
}
|
2012-05-01 02:03:10 +03:00
|
|
|
;
|
|
|
|
|
|
|
|
inventory_item:
|
|
|
|
WORD WORD stock TOK_NL
|
|
|
|
{
|
2012-05-01 02:40:11 +03:00
|
|
|
$$ = part_add($1, $2);
|
2012-05-01 21:21:32 +03:00
|
|
|
$3->provider = provider_add($1);
|
2012-05-01 02:03:10 +03:00
|
|
|
part_add_stock($$, $3);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
stock:
|
|
|
|
WORD int int WORD float prices
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct stock);
|
2012-05-01 21:21:32 +03:00
|
|
|
$$->provider = NULL;
|
2012-05-01 02:03:10 +03:00
|
|
|
$$->cat = $1;
|
|
|
|
$$->avail = $2;
|
|
|
|
$$->package = $3;
|
2012-05-01 04:49:33 +03:00
|
|
|
$$->curr = currency_lookup($4);
|
|
|
|
if (!$$->curr)
|
|
|
|
yyerrorf("unknown currency %s", $4);
|
2012-05-01 02:03:10 +03:00
|
|
|
$$->add = $5;
|
|
|
|
$$->price = $6;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
prices:
|
|
|
|
price
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
| price prices
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->next = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
price:
|
|
|
|
int float
|
|
|
|
{
|
|
|
|
$$ = alloc_type(struct price);
|
|
|
|
$$->qty = $1;
|
|
|
|
$$->value = $2;
|
|
|
|
$$->next = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
int:
|
|
|
|
WORD
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
$$ = strtol($1, &end, 10);
|
|
|
|
if (*end)
|
|
|
|
yyerrorf("\"%s\" is not an integer", $1);
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
float:
|
|
|
|
WORD
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
$$ = strtod($1, &end);
|
|
|
|
if (*end)
|
|
|
|
yyerrorf("\"%s\" is not a number", $1);
|
|
|
|
}
|
|
|
|
;
|
2012-05-01 04:49:33 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* ----- Currency exchange ------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
exchange:
|
|
|
|
| TOK_NL
|
|
|
|
| currency exchange
|
|
|
|
;
|
|
|
|
|
|
|
|
currency:
|
|
|
|
WORD
|
|
|
|
{
|
|
|
|
curr = currency_add($1);
|
|
|
|
}
|
|
|
|
rates TOK_NL
|
|
|
|
;
|
|
|
|
|
|
|
|
rates:
|
|
|
|
| rate rates
|
|
|
|
;
|
|
|
|
|
|
|
|
rate:
|
|
|
|
WORD float
|
|
|
|
{
|
|
|
|
const struct currency *to;
|
|
|
|
|
|
|
|
/* add and not lookup, since we just introduce the
|
|
|
|
currency here */
|
|
|
|
to = currency_add($1);
|
|
|
|
currency_exchange(curr, to, $2);
|
|
|
|
}
|
|
|
|
;
|
2012-05-01 20:57:12 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* ----- Providers --------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
providers:
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| TOK_NL
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| provider providers
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
$$->next = $2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
provider:
|
|
|
|
WORD WORD float float TOK_NL
|
|
|
|
{
|
|
|
|
$$ = provider_add($1);
|
|
|
|
$$->curr = currency_add($2);
|
|
|
|
$$->shipping = $3;
|
|
|
|
$$->minimum = $4;
|
|
|
|
}
|
|
|
|
;
|
2012-05-20 17:18:18 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* ----- Substitutions ----------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
substitutions:
|
|
|
|
block
|
|
|
|
{
|
2012-05-21 01:00:04 +03:00
|
|
|
$$ = $1;
|
|
|
|
subst_finalize($$);
|
|
|
|
subst_dump(stderr, $$);
|
2012-05-20 17:18:18 +03:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
block:
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
2012-05-22 19:01:39 +03:00
|
|
|
| word_or_dollar relop PATTERN opt_block block
|
2012-05-20 17:18:18 +03:00
|
|
|
{
|
|
|
|
if ($4) {
|
2012-05-21 05:16:51 +03:00
|
|
|
if ($2 != rel_eq)
|
|
|
|
yyerror("only = allow for matching");
|
2012-05-20 17:18:18 +03:00
|
|
|
$$ = subst_match($1, $3);
|
|
|
|
$$->u.match.block = $4;
|
|
|
|
} else {
|
2012-05-21 05:16:51 +03:00
|
|
|
$$ = subst_assign($1, $2, $3);
|
2012-05-20 17:18:18 +03:00
|
|
|
}
|
|
|
|
free((void *) $3);
|
|
|
|
$$->next = $5;
|
|
|
|
}
|
|
|
|
| WORD WORD
|
|
|
|
{
|
2012-05-22 21:57:55 +03:00
|
|
|
$$ = parse_jump($1, $2);
|
|
|
|
}
|
|
|
|
| WORD '$'
|
|
|
|
{
|
|
|
|
$$ = parse_jump($1, NULL);
|
2012-05-20 17:18:18 +03:00
|
|
|
}
|
|
|
|
| WORD
|
|
|
|
{
|
2012-05-22 05:17:33 +03:00
|
|
|
if (!strcmp($1, "end"))
|
|
|
|
$$ = subst_end();
|
|
|
|
else if (!strcmp($1, "ignore"))
|
|
|
|
$$ = subst_ignore();
|
|
|
|
else
|
2012-05-22 21:57:55 +03:00
|
|
|
$$ = parse_jump($1, NULL);
|
2012-05-20 17:18:18 +03:00
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-05-22 19:01:39 +03:00
|
|
|
word_or_dollar:
|
|
|
|
'$'
|
|
|
|
{
|
|
|
|
$$ = dollar;
|
|
|
|
}
|
|
|
|
| WORD
|
|
|
|
{
|
|
|
|
$$ = $1;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
2012-05-20 17:18:18 +03:00
|
|
|
opt_block:
|
|
|
|
{
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
|
|
|
| '{' block '}'
|
|
|
|
{
|
|
|
|
$$ = $2;
|
|
|
|
}
|
|
|
|
;
|
2012-05-23 22:05:24 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* ----- KiCad BOM (from eeschema) ----------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
bom:
|
|
|
|
BOM_EESCHEMA
|
|
|
|
/*
|
|
|
|
* The KiCad BOM syntax is quite alien, so we just check the
|
|
|
|
* overall structure here, leave extracting the lines with
|
|
|
|
* actual content to the lexer, and do all the detail work in
|
|
|
|
* bom.c
|
|
|
|
*/
|
|
|
|
;
|
2012-05-23 23:26:35 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* ----- Symbols (BOM supplement) ------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
symbols:
|
|
|
|
| TOK_NL
|
|
|
|
| symbol symbols
|
|
|
|
;
|
|
|
|
|
|
|
|
symbol:
|
|
|
|
WORD WORD TOK_NL
|
|
|
|
{
|
|
|
|
bom_set_sym($1, $2);
|
|
|
|
}
|
|
|
|
;
|