diff options
author | wlemb <wlemb> | 2002-05-17 12:09:09 +0000 |
---|---|---|
committer | wlemb <wlemb> | 2002-05-17 12:09:09 +0000 |
commit | eb963bd9782c68810421a5254e31051f1b40a00f (patch) | |
tree | 30026b3ace74a720eca02671ebf5a9a7a1e1b3b5 /src | |
parent | 01b79ca1f1c4621a5ddd88c7c3c25723fe2d8ecd (diff) | |
download | groff-eb963bd9782c68810421a5254e31051f1b40a00f.tar.gz |
Pic's `with' attribute now accepts positions.
* src/preproc/pic/pic.y: Make `.', BOX, CIRCLE, ELLIPSE, ARC, LINE,
ARROW, SPLINE, and `[' left-associative tokens to fix shift/reduce
conflicts.
(object_spec): Add rule for `WITH' and `position'.
(relative_path): Give `corner' the precedence of `CHOP'.
* src/preproc/pic/object.h (path): New members `pos' and
`is_position'.
* src/preproc/pic/object.cc: Updated initializers of `path'.
(path::follow): Handle `is_position'.
* doc/pic.ms: Completely updated grammar description.
Many typographical improvements.
Diffstat (limited to 'src')
-rw-r--r-- | src/preproc/pic/object.cc | 34 | ||||
-rw-r--r-- | src/preproc/pic/object.h | 5 | ||||
-rw-r--r-- | src/preproc/pic/pic.man | 4 | ||||
-rw-r--r-- | src/preproc/pic/pic.y | 32 |
4 files changed, 54 insertions, 21 deletions
diff --git a/src/preproc/pic/object.cc b/src/preproc/pic/object.cc index 30d49067..3d32bf53 100644 --- a/src/preproc/pic/object.cc +++ b/src/preproc/pic/object.cc @@ -1782,18 +1782,28 @@ string_list::~string_list() a_delete str; } -/* A path is used to hold the argument to the with attribute. For example, -`.nw' or `.A.s' or `.A'. The major operation on a path is to take a -place and follow the path through the place to place within the place. -Note that `.A.B.C.sw' will work. */ +/* A path is used to hold the argument to the `with' attribute. For + example, `.nw' or `.A.s' or `.A'. The major operation on a path is to + take a place and follow the path through the place to place within the + place. Note that `.A.B.C.sw' will work. + + For compatibility with DWB pic, `with' accepts positions also (this + is incorrectly documented in CSTR 116). */ path::path(corner c) -: crn(c), label_list(0), ypath(0) +: crn(c), label_list(0), ypath(0), is_position(0) { } +path::path(position p) +: crn(0), label_list(0), ypath(0), is_position(1) +{ + pos.x = p.x; + pos.y = p.y; +} + path::path(char *l, corner c) -: crn(c), ypath(0) +: crn(c), ypath(0), is_position(0) { label_list = new string_list(l); } @@ -1831,6 +1841,12 @@ void path::set_ypath(path *p) int path::follow(const place &pl, place *result) const { + if (is_position) { + result->x = pos.x; + result->y = pos.y; + result->obj = 0; + return 1; + } const place *p = &pl; for (string_list *lb = label_list; lb; lb = lb->next) if (p->obj == 0 || (p = p->obj->find_label(lb->str)) == 0) { @@ -1840,9 +1856,9 @@ int path::follow(const place &pl, place *result) const if (crn == 0 || p->obj == 0) *result = *p; else { - position pos = ((p->obj)->*(crn))(); - result->x = pos.x; - result->y = pos.y; + position ps = ((p->obj)->*(crn))(); + result->x = ps.x; + result->y = ps.y; result->obj = 0; } if (ypath) { diff --git a/src/preproc/pic/object.h b/src/preproc/pic/object.h index dc6cf57f..98937f93 100644 --- a/src/preproc/pic/object.h +++ b/src/preproc/pic/object.h @@ -1,5 +1,5 @@ // -*- C++ -*- -/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc. +/* Copyright (C) 1989, 1990, 1991, 1992, 2002 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.com) This file is part of groff. @@ -76,11 +76,14 @@ struct place { struct string_list; class path { + position pos; corner crn; string_list *label_list; path *ypath; + int is_position; public: path(corner = 0); + path(position); path(char *, corner = 0); ~path(); void append(corner); diff --git a/src/preproc/pic/pic.man b/src/preproc/pic/pic.man index 2add8cb5..6054f197 100644 --- a/src/preproc/pic/pic.man +++ b/src/preproc/pic/pic.man @@ -52,7 +52,7 @@ the original English. ] [ .I filename -\&.\|.\|. +\&.\|.\|.\& ] .br .B @g@pic @@ -62,7 +62,7 @@ the original English. ] [ .I filename -\&.\|.\|. +\&.\|.\|.\& ] . . diff --git a/src/preproc/pic/pic.y b/src/preproc/pic/pic.y index b3a35133..4771e763 100644 --- a/src/preproc/pic/pic.y +++ b/src/preproc/pic/pic.y @@ -224,6 +224,8 @@ char *do_sprintf(const char *form, const double *v, int nv); %token DEFINE %token UNDEF +%left '.' + /* this ensures that plot 17 "%g" parses as (plot 17 "%g") */ %left PLOT %left TEXT SPRINTF @@ -244,6 +246,8 @@ parses properly. */ %left VARIABLE NUMBER '(' SIN COS ATAN2 LOG EXP SQRT K_MAX K_MIN INT RAND SRAND LAST %left ORDINAL HERE '`' +%left BOX CIRCLE ELLIPSE ARC LINE ARROW SPLINE '[' + /* these need to be lower than '-' */ %left HEIGHT RADIUS WIDTH DIAMETER FROM TO AT THICKNESS @@ -478,7 +482,7 @@ print_args: ; print_arg: - expr %prec ',' + expr %prec ',' { $$.str = new char[GDIGITS + 1]; sprintf($$.str, "%g", $1); @@ -487,7 +491,7 @@ print_arg: } | text { $$ = $1; } - | position %prec ',' + | position %prec ',' { $$.str = new char[GDIGITS + 2 + GDIGITS + 1]; sprintf($$.str, "%g, %g", $1.x, $1.y); @@ -674,7 +678,7 @@ object_spec: lookup_variable("linewid", & $$->segment_width); $$->dir = current_direction; } - | text %prec TEXT + | text %prec TEXT { $$ = new object_spec(TEXT_OBJECT); $$->text = new text_item($1.str, $1.filename, $1.lineno); @@ -742,7 +746,7 @@ object_spec: $$->radius = $3/2.0; $$->flags |= HAS_RADIUS; } - | object_spec expr %prec HEIGHT + | object_spec expr %prec HEIGHT { $$ = $1; $$->flags |= HAS_SEGMENT; @@ -857,6 +861,15 @@ object_spec: $$->flags |= HAS_WITH; $$->with = $3; } + | object_spec WITH position %prec ',' + { + $$ = $1; + $$->flags |= HAS_WITH; + position pos; + pos.x = $3.x; + pos.y = $3.y; + $$->with = new path(pos); + } | object_spec BY expr_pair { $$ = $1; @@ -1006,7 +1019,7 @@ object_spec: $$ = $1; $$->flags &= ~IS_CLOCKWISE; } - | object_spec text %prec TEXT + | object_spec text %prec TEXT { $$ = $1; text_item **p; @@ -1165,7 +1178,8 @@ expr_pair: ; place: - label %prec CHOP /* line at A left == line (at A) left */ + /* line at A left == line (at A) left */ + label %prec CHOP { $$ = $1; } | label corner { @@ -1296,11 +1310,11 @@ label_path: ; relative_path: - corner + corner %prec CHOP { $$ = new path($1); } /* give this a lower precedence than LEFT and RIGHT so that [A: box] with .A left == [A: box] with (.A left) */ - | label_path %prec TEXT + | label_path %prec TEXT { $$ = $1; } | label_path corner { @@ -1491,7 +1505,7 @@ expr: YYABORT; } } - | '-' expr %prec '!' + | '-' expr %prec '!' { $$ = -$2; } | '(' any_expr ')' { $$ = $2; } |