source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mandoc: add parentheses to the output where required for disambiguation
@ 2017-07-07 19:07 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2017-07-07 19:07 UTC (permalink / raw)
  To: source

Log Message:
-----------
add parentheses to the output where required for disambiguation

Modified Files:
--------------
    mandoc:
        eqn_term.c
    mandoc/regress/eqn/fromto:
        basic.out_ascii
        noarg.out_ascii
        precedence.out_ascii
    mandoc/regress/eqn/over:
        noarg.out_ascii
        precedence.out_ascii
    mandoc/regress/eqn/subsup:
        combine.out_ascii
        noarg.out_ascii
        precedence.out_ascii
        sub_group.out_ascii

Revision Data
-------------
Index: noarg.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/fromto/noarg.out_ascii,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/eqn/fromto/noarg.out_ascii -Lregress/eqn/fromto/noarg.out_ascii -u -p -r1.3 -r1.4
--- regress/eqn/fromto/noarg.out_ascii
+++ regress/eqn/fromto/noarg.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      f\bfr\bro\bom\bmt\bto\bo-\b-n\bno\boa\bar\brg\bg - vertical stacking lacks final argument
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text _\bx__\ba^^ final text
+     initial text _\bx_(_\ba^)^ final text
 
 OpenBSD                          July 4, 2017                          OpenBSD
Index: basic.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/fromto/basic.out_ascii,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/eqn/fromto/basic.out_ascii -Lregress/eqn/fromto/basic.out_ascii -u -p -r1.3 -r1.4
--- regress/eqn/fromto/basic.out_ascii
+++ regress/eqn/fromto/basic.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      f\bfr\bro\bom\bmt\bto\bo-\b-b\bba\bas\bsi\bic\bc - vertical stacking
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text E_(_\bi = 1)^oo 1/_\bi^2 final text
+     initial text E_(_\bi = 1)^oo 1/(_\bi^2) final text
 
 OpenBSD                          July 4, 2017                          OpenBSD
Index: precedence.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/fromto/precedence.out_ascii,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/eqn/fromto/precedence.out_ascii -Lregress/eqn/fromto/precedence.out_ascii -u -p -r1.1 -r1.2
--- regress/eqn/fromto/precedence.out_ascii
+++ regress/eqn/fromto/precedence.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      s\bsu\bub\bbs\bsu\bup\bp-\b-p\bpr\bre\bec\bce\bed\bde\ben\bnc\bce\be - precedence of subscripts and superscripts
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text _\bX__\ba_^_\bc^ ; X_a\ba^_\bc ; _\bX_1^2__\ba__\bc^_\be^_\bo__\br^_\bs final text
+     initial text _\bX_(_\ba_)^_\bc^ ; X_a\ba^_\bc ; (_\bX_1^2)_(_\ba__\bc^_\be)^(_\bo__\br^_\bs) final text
 
 OpenBSD                          July 6, 2017                          OpenBSD
Index: eqn_term.c
===================================================================
RCS file: /home/cvs/mandoc/mandoc/eqn_term.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -Leqn_term.c -Leqn_term.c -u -p -r1.11 -r1.12
--- eqn_term.c
+++ eqn_term.c
@@ -51,21 +51,40 @@ static void
 eqn_box(struct termp *p, const struct eqn_box *bp)
 {
 	const struct eqn_box *child;
+	int delim;
+
+	/* Delimiters around this box? */
 
 	if ((bp->type == EQN_LIST && bp->expectargs > 1) ||
 	    (bp->type == EQN_PILE && (bp->prev || bp->next)) ||
-	    (bp->parent != NULL && bp->parent->pos == EQNPOS_SQRT)) {
+	    (bp->parent != NULL && (bp->parent->pos == EQNPOS_SQRT ||
+	    /* Diacritic followed by ^ or _. */
+	    ((bp->top != NULL || bp->bottom != NULL) &&
+	     bp->parent->type == EQN_SUBEXPR &&
+	     bp->parent->pos != EQNPOS_OVER && bp->next != NULL) ||
+	    /* Nested over, sub, sup, from, to. */
+	    (bp->type == EQN_SUBEXPR && bp->pos != EQNPOS_SQRT &&
+	     ((bp->parent->type == EQN_LIST && bp->expectargs == 1) ||
+	      (bp->parent->type == EQN_SUBEXPR &&
+	       bp->pos != EQNPOS_SQRT)))))) {
 		if (bp->parent->type == EQN_SUBEXPR && bp->prev != NULL)
 			p->flags |= TERMP_NOSPACE;
 		term_word(p, bp->left != NULL ? bp->left : "(");
 		p->flags |= TERMP_NOSPACE;
-	}
+		delim = 1;
+	} else
+		delim = 0;
+
+	/* Handle Fonts and text. */
+
 	if (bp->font != EQNFONT_NONE)
 		term_fontpush(p, fontmap[(int)bp->font]);
 
 	if (bp->text != NULL)
 		term_word(p, bp->text);
 
+	/* Special box types. */
+
 	if (bp->pos == EQNPOS_SQRT) {
 		term_word(p, "sqrt");
 		if (bp->first != NULL) {
@@ -111,6 +130,8 @@ eqn_box(struct termp *p, const struct eq
 		}
 	}
 
+	/* Handle Fonts and diacritics. */
+
 	if (bp->font != EQNFONT_NONE)
 		term_fontpop(p);
 	if (bp->top != NULL) {
@@ -121,9 +142,10 @@ eqn_box(struct termp *p, const struct eq
 		p->flags |= TERMP_NOSPACE;
 		term_word(p, "_");
 	}
-	if ((bp->type == EQN_LIST && bp->expectargs > 1) ||
-	    (bp->type == EQN_PILE && (bp->prev || bp->next)) ||
-	    (bp->parent != NULL && bp->parent->pos == EQNPOS_SQRT)) {
+
+	/* Right delimiter after this box? */
+
+	if (delim) {
 		p->flags |= TERMP_NOSPACE;
 		term_word(p, bp->right != NULL ? bp->right : ")");
 		if (bp->parent->type == EQN_SUBEXPR && bp->next != NULL)
Index: noarg.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/over/noarg.out_ascii,v
retrieving revision 1.2
retrieving revision 1.3
diff -Lregress/eqn/over/noarg.out_ascii -Lregress/eqn/over/noarg.out_ascii -u -p -r1.2 -r1.3
--- regress/eqn/over/noarg.out_ascii
+++ regress/eqn/over/noarg.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      o\bov\bve\ber\br-\b-n\bno\boa\bar\brg\bg - fraction operator without arguments
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text // final text
+     initial text (/)/ final text
 
 OpenBSD                          July 4, 2017                          OpenBSD
Index: precedence.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/over/precedence.out_ascii,v
retrieving revision 1.4
retrieving revision 1.5
diff -Lregress/eqn/over/precedence.out_ascii -Lregress/eqn/over/precedence.out_ascii -u -p -r1.4 -r1.5
--- regress/eqn/over/precedence.out_ascii
+++ regress/eqn/over/precedence.out_ascii
@@ -4,7 +4,7 @@ N\bNA\bAM\bME\bE
      o\bov\bve\ber\br-\b-p\bpr\bre\bec\bce\bed\bde\ben\bnc\bce\be - precedence of the fraction operator
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text 1 + _\bx + _\bx^2/2 + _\bx^3/(2 * 3) ; _\ba^/_\bc~ ; a\ba/c\bc ; sqrt(_\ba)/sqrt(_\bc)
-     final text
+     initial text 1 + _\bx + (_\bx^2)/2 + (_\bx^3)/(2 * 3) ; _\ba^/_\bc~ ; a\ba/c\bc ;
+     sqrt(_\ba)/sqrt(_\bc) final text
 
 OpenBSD                          July 6, 2017                          OpenBSD
Index: precedence.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/subsup/precedence.out_ascii,v
retrieving revision 1.1
retrieving revision 1.2
diff -Lregress/eqn/subsup/precedence.out_ascii -Lregress/eqn/subsup/precedence.out_ascii -u -p -r1.1 -r1.2
--- regress/eqn/subsup/precedence.out_ascii
+++ regress/eqn/subsup/precedence.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      s\bsu\bub\bbs\bsu\bup\bp-\b-p\bpr\bre\bec\bce\bed\bde\ben\bnc\bce\be - precedence of subscripts and superscripts
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text _\bx^_1_^2 + _\be~^_\bx^__\bs<-> ; I_I\bI^_\bI + I^I\bI__\bI final text
+     initial text (_\bx^)_(1_)^2 + (_\be~)^((_\bx^)__\bs<->) ; I_I\bI^_\bI + I^(I\bI__\bI) final text
 
 OpenBSD                          July 6, 2017                          OpenBSD
Index: noarg.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/subsup/noarg.out_ascii,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/eqn/subsup/noarg.out_ascii -Lregress/eqn/subsup/noarg.out_ascii -u -p -r1.3 -r1.4
--- regress/eqn/subsup/noarg.out_ascii
+++ regress/eqn/subsup/noarg.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      s\bsu\bub\bbs\bsu\bup\bp-\b-n\bno\boa\bar\brg\bg - empty subscripts and superscripts
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text _\bx_1^^ final text
+     initial text _\bx_(1^)^ final text
 
 OpenBSD                          July 4, 2017                          OpenBSD
Index: sub_group.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/subsup/sub_group.out_ascii,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/eqn/subsup/sub_group.out_ascii -Lregress/eqn/subsup/sub_group.out_ascii -u -p -r1.3 -r1.4
--- regress/eqn/subsup/sub_group.out_ascii
+++ regress/eqn/subsup/sub_group.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      s\bsu\bub\bbs\bsu\bup\bp-\b-s\bsu\bub\bb_\b_g\bgr\bro\bou\bup\bp - grouping of subscripts
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text _\bx__\bi + _\bx__\bj_1 + (_\bM__\bi)__\bj final text
+     initial text _\bx__\bi + _\bx_(_\bj_1) + (_\bM__\bi)__\bj final text
 
 OpenBSD                          July 4, 2017                          OpenBSD
Index: combine.out_ascii
===================================================================
RCS file: /home/cvs/mandoc/mandoc/regress/eqn/subsup/combine.out_ascii,v
retrieving revision 1.3
retrieving revision 1.4
diff -Lregress/eqn/subsup/combine.out_ascii -Lregress/eqn/subsup/combine.out_ascii -u -p -r1.3 -r1.4
--- regress/eqn/subsup/combine.out_ascii
+++ regress/eqn/subsup/combine.out_ascii
@@ -4,6 +4,6 @@ N\bNA\bAM\bME\bE
      s\bsu\bub\bbs\bsu\bup\bp-\b-c\bco\bom\bmb\bbi\bin\bne\be - combination of subscripts and superscripts
 
 D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
-     initial text _\bx_1^2 + _\be^_\bx_2 final text
+     initial text _\bx_1^2 + _\be^(_\bx_2) final text
 
 OpenBSD                          July 4, 2017                          OpenBSD
--
 To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-07-07 19:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-07 19:07 mandoc: add parentheses to the output where required for disambiguation schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).