15
15
# perl -MParse::RecDescent - MathGrammar LaTeXML::MathGrammar
16
16
# ================================================================================
17
17
# Startup actions: import the constructors
18
- { BEGIN{ use LaTeXML::MathParser qw(:constructors);
18
+ { BEGIN{ use LaTeXML::MathParser qw(:constructors);
19
19
#### $::RD_TRACE=1;
20
20
}}
21
-
21
+
22
22
# Rules section
23
23
# ========================================
24
24
# Naming Conventions:
27
27
# Initial lowercase : internal rules.
28
28
# ========================================
29
29
# For internal rules
30
- # moreFoos[$foo] : Looks for more Foo's w/appropriate punctuation or operators,
30
+ # moreFoos[$foo] : Looks for more Foo's w/appropriate punctuation or operators,
31
31
# whatever is appropriate, and combines it with whatever was passed in
32
32
# as pattern arg. Typically, the last clause would be simply
33
33
# | { $arg[0]; }
@@ -65,7 +65,7 @@ Anything : AnythingAny /^\Z/ { $item[1]; }
65
65
66
66
#======================================================================
67
67
AnythingAny :
68
- Formulae
68
+ Formulae
69
69
| OPEN Formulae CLOSE { Fence($item[1],$item[2],$item[3]); }
70
70
| modifierFormulae
71
71
| OPEN modifierFormula CLOSE { Fence($item[1],$item[2],$item[3]); }
@@ -79,7 +79,7 @@ AnythingAny :
79
79
| FLOATSUPERSCRIPT { NewScript(Absent(),$item[1]); }
80
80
| FLOATSUBSCRIPT { NewScript(Absent(),$item[1]); }
81
81
| AnyOp Expression { Apply($item[1],Absent(),$item[2]);}
82
-
82
+
83
83
# a top level rule for sub and superscripts that can accept all sorts of junk.
84
84
Subscript : <rulevar: local $MaxAbsDepth = $LaTeXML::MathParser::MAX_ABS_DEPTH>
85
85
Subscript :
@@ -98,7 +98,7 @@ aSubscript :
98
98
99
99
aSuperscript :
100
100
supops
101
- | Formulae
101
+ | Formulae
102
102
| AnyOp Expression { Apply($item[1],Absent(),$item[2]);}
103
103
| AnyOp
104
104
@@ -109,7 +109,7 @@ aSuperscript :
109
109
# Expression(s) separated by punctuation, relational operators or metarelational
110
110
# operators [Think of $a=b=c$ vs $a=b, c=d$ vs. $a=b,c,d$ .. ]
111
111
# and group them into Formulae (collections of relations), including relations
112
- # which have punctuated collections of Expression(s) on either the LHS or RHS,
112
+ # which have punctuated collections of Expression(s) on either the LHS or RHS,
113
113
# as well as `multirelation' like a = b = c, or simply punctuated collections of
114
114
# Expression(s)
115
115
@@ -129,7 +129,7 @@ endPunct : PUNCT | PERIOD
129
129
130
130
Formula : Expression extendFormula[$item[1]]
131
131
132
- # extendFormula[$expression] ; expression might be followed by punct Expression...
132
+ # extendFormula[$expression] ; expression might be followed by punct Expression...
133
133
# or relop Expression... or arrow Expression or nothing.
134
134
extendFormula :
135
135
/^\Z/ { $arg[0];} # short circuit!
@@ -138,7 +138,7 @@ extendFormula :
138
138
| relop /^\Z/ { NewFormula($arg[0],$item[1], Absent()); }
139
139
| { $arg[0]; }
140
140
141
- # maybeRHS[$expr,(punct,$expr)*];
141
+ # maybeRHS[$expr,(punct,$expr)*];
142
142
# Could have RELOP Expression (which means the (collected LHS) relation RHS)
143
143
# or done (just collection)
144
144
maybeRHS :
@@ -270,7 +270,7 @@ ExpressionsNoBars : Expressions
270
270
# Abstractly, things combined by operators binding tighter than multiplication
271
271
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
272
272
273
- Factor :
273
+ Factor :
274
274
# These 2nd two are Iffy; hopefully the 1st rule will protect from backtrack?
275
275
OPEN ARRAY CLOSE addScripts[Fence($item[1],$item[2],$item[3])]
276
276
# perhaps only when OPEN or CLOSED is { or } ??
@@ -317,7 +317,7 @@ ATOM_OR_ID : ATOM | ID | ARRAY
317
317
# Note f g h => f*g*h, but f g h x => f(g(h(x))) Seems like what people mean...
318
318
# Should there be a special case for trigs?
319
319
barearg : aBarearg moreBareargs[$item[1]]
320
- aBarearg :
320
+ aBarearg :
321
321
preScripted['FUNCTION'] addArgs[$item[1]]
322
322
| preScripted['OPFUNCTION'] addOpFunArgs[$item[1]]
323
323
| preScripted['TRIGFUNCTION'] addTrigFunArgs[$item[1]]
@@ -335,7 +335,7 @@ moreBareargs :
335
335
336
336
# A variation that does not allow a bare trig function
337
337
trigBarearg : aTrigBarearg moreTrigBareargs[$item[1]]
338
- aTrigBarearg :
338
+ aTrigBarearg :
339
339
preScripted['FUNCTION'] addArgs[$item[1]]
340
340
| preScripted['OPFUNCTION'] addOpFunArgs[$item[1]]
341
341
| preScripted['ATOM_OR_ID'] maybeArgs[$item[1]]
@@ -348,7 +348,7 @@ moreTrigBareargs :
348
348
/^\Z/ { $arg[0];} # short circuit!
349
349
| MulOp aTrigBarearg
350
350
moreTrigBareargs[ApplyNary($item[1],$arg[0],$item[2])]
351
- | aTrigBarearg
351
+ | aTrigBarearg
352
352
moreTrigBareargs[ApplyNary(InvisibleTimes(),$arg[0],$item[1])]
353
353
| { $arg[0]; }
354
354
@@ -397,7 +397,7 @@ maybeBraket :
397
397
ketExpression : <rulevar: local $forbidVertBar = 1>
398
398
ketExpression : <rulevar: local $forbidLRAngle = 1>
399
399
ketExpression : Formulae
400
- | METARELOP | ARROW | AddOp | MulOp | MODIFIEROP
400
+ | METARELOP | MODIFIEROP
401
401
402
402
#======================================================================
403
403
# absExpression; need to be careful about misinterpreting the next |
@@ -446,19 +446,19 @@ inpreScripted :
446
446
factorOpen :
447
447
AddOp balancedClose[$arg[0]] addScripts[Fence($arg[0],$item[1],$item[2])] # For (-)
448
448
# Parenthesized Operator possibly w/scripts
449
- | preScripted['bigop'] balancedClose[$arg[0]]
449
+ | preScripted['bigop'] balancedClose[$arg[0]]
450
450
addScripts[Fence($arg[0],$item[1],$item[2])] Factor
451
451
{ Apply($item[3],$item[4]); }
452
452
# Parenthesized Operator including a pre-factor
453
- | Factor preScripted['bigop'] balancedClose[$arg[0]]
453
+ | Factor preScripted['bigop'] balancedClose[$arg[0]]
454
454
addScripts[Fence($arg[0],
455
455
Apply(InvisibleTimes(),$item[1],$item[2]),$item[3])] Factor
456
456
{ Apply($item[4],$item[5]); }
457
457
# read expression too? match subcases.
458
458
| Expression factorOpenExpr[$arg[0],$item[1]]
459
459
# Empty OPEN CLOSE ?
460
460
| balancedClose[$arg[0]] addScripts[Fence($arg[0],$item[1])]
461
- # Sequence starting with an operator ?
461
+ # Sequence starting with an operator ?
462
462
| AnyOp factorOpenExpr[$arg[0],$item[1]]
463
463
464
464
# factorOpenExpr[$open,$expr]; Try to recognize various things that start
@@ -491,13 +491,13 @@ FormulaNOBar : Formula
491
491
492
492
# The "such that" that can appear in a sets like {a "such that" predicate(a)}
493
493
# accept vertical bars, and colon
494
- suchThatOp : MIDDLE | VERTBAR
494
+ suchThatOp : MIDDLE | VERTBAR
495
495
| /METARELOP:colon:\d+/ { Lookup($item[1]); }
496
496
# ================================================================================
497
497
# Function args, etc.
498
498
499
499
# maybeArgs[$function] ; Add arguments to an identifier, but only if made explict.
500
- maybeArgs :
500
+ maybeArgs :
501
501
/^\Z/ { $arg[0];} # short circuit!
502
502
| APPLYOP requireArgs[$arg[0]]
503
503
| { $arg[0]; }
@@ -512,7 +512,7 @@ doubtArgs :
512
512
| { IsNotationAllowed('MaybeFunctions'); } OPEN forbidArgs[$arg[0],$item[2]]
513
513
| { $arg[0]; }
514
514
515
- # forbidArgs[$unknown,$open]; Got a suspicious pattern: an unknown and open.
515
+ # forbidArgs[$unknown,$open]; Got a suspicious pattern: an unknown and open.
516
516
# If the following seems to be an argument list, warn.
517
517
forbidArgs :
518
518
Argument (argPunct Argument)(s) balancedClose[$arg[1]]
@@ -528,7 +528,7 @@ requireArgs :
528
528
balancedClose[$item[1]]
529
529
{ ApplyDelimited($arg[0],$item[1],$item[2],
530
530
map(@$_,@{$item[3]}),$item[4]); }
531
- # Hmm, should only be applicable to _some_ functions ???
531
+ # Hmm, should only be applicable to _some_ functions ???
532
532
| barearg { Apply($arg[0],$item[1]); }
533
533
534
534
# addArgs[$function]; We've got a function; Add following arguments to a
@@ -602,7 +602,7 @@ addOpArgs :
602
602
| APPLYOP(?) Factor moreOpArgFactors[$item[2]] { Apply($arg[0],$item[3]);}
603
603
| { $arg[0]; }
604
604
605
- # moreOpArgFactors[$factor1] : Similar to moreFactors,
605
+ # moreOpArgFactors[$factor1] : Similar to moreFactors,
606
606
# but w/o evalAtOp since that most likely belongs to the operator, not
607
607
# the factors.
608
608
moreOpArgFactors :
@@ -623,7 +623,7 @@ addIntOpArgs :
623
623
| APPLYOP(?) IntFactor moreIntOpArgFactors[$item[2]] { Apply($arg[0],$item[3]);}
624
624
| { $arg[0]; }
625
625
626
- # moreIntOpArgFactors[$factor1] : Similar to moreOpArgFactors,
626
+ # moreIntOpArgFactors[$factor1] : Similar to moreOpArgFactors,
627
627
# but recognizing d as diff
628
628
moreIntOpArgFactors :
629
629
/^\Z/ { $arg[0];} # short circuit!
@@ -659,7 +659,7 @@ nestOperators :
659
659
| FUNCTION addScripts[$item[1]] { recApply(@arg,$item[2]); }
660
660
| OPFUNCTION addScripts[$item[1]] { recApply(@arg,$item[2]); }
661
661
| TRIGFUNCTION addScripts[$item[1]] { recApply(@arg,$item[2]); }
662
- | OPEN Expression balancedClose[$item[1]]
662
+ | OPEN Expression balancedClose[$item[1]]
663
663
{ recApply(@arg[0..$#arg-1],
664
664
ApplyDelimited($arg[$#arg],$item[1],$item[2],$item[3])); }
665
665
| { recApply(@arg); }
@@ -692,20 +692,19 @@ addOpDecoration :
692
692
| { $arg[0]; }
693
693
694
694
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
695
- # Pseudo-Terminals.
695
+ # Pseudo-Terminals.
696
696
# Useful combinations or subsets of terminals.
697
697
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
698
698
# A generalized relational operator or arrow
699
699
# Note we disallow < or > if we're parsing the contents of a bra or ket!
700
- relop :
700
+ relop :
701
701
{ ($forbidLRAngle ? 1 : undef); } /RELOP:(less|greater)-than:\d+/ <commit> <reject>
702
702
| RELOP addOpDecoration[$item[1]]
703
703
| ARROW addOpDecoration[$item[1]]
704
704
705
705
# Check out whether diffop should be treated as bigop or operator
706
- # It depends on the binding
706
+ # It depends on the binding
707
707
bigop : BIGOP | SUMOP | INTOP | LIMITOP | DIFFOP
708
- operator: OPERATOR
709
708
710
709
# SUPOP is really only \prime(s) (?)
711
710
supops : SUPOP(s) { New(undef,
@@ -729,7 +728,7 @@ evalAtOp : VERTBAR
729
728
# These correspond to the TeX tokens.
730
729
# The Lexer strings are of the form TYPE:NAME:NUMBER where
731
730
# TYPE is the grammatical role, or part of speech,
732
- # NAME is the specific name (semantic or presentation) of the token
731
+ # NAME is the specific name (semantic or presentation) of the token
733
732
# NUMBER is the position of the specific token in the current token sequence.
734
733
#
735
734
# NOTE: RecDescent doesn't clearly distinguish lexing from parsing
@@ -793,7 +792,6 @@ INTOP : /INTOP:\S*:\d+/ { Lookup($item[1]); }
793
792
LIMITOP : /LIMITOP:\S*:\d+/ { Lookup($item[1]); }
794
793
DIFFOP : /DIFFOP:\S*:\d+/ { Lookup($item[1]); }
795
794
OPERATOR : /OPERATOR:\S*:\d+/ { Lookup($item[1]); }
796
- ##DIFF : /DIFF:\S*:\d+/ { Lookup($item[1]); }
797
795
POSTSUBSCRIPT : /POSTSUBSCRIPT:\S*:\d+/ { Lookup($item[1]); }
798
796
POSTSUPERSCRIPT : /POSTSUPERSCRIPT:\S*:\d+/ { Lookup($item[1]); }
799
797
FLOATSUPERSCRIPT : /FLOATSUPERSCRIPT:\S*:\d+/ { Lookup($item[1]); }
0 commit comments