#include "MathSupport.h"
#include "support/debug.h"
+#include "support/lassert.h"
namespace lyx {
+
+Inset * InsetMathHash::clone() const
+{
+ return new InsetMathHash(*this);
+}
+
+
+void InsetMathHash::write(WriteStream & os) const
+{
+ os << str_;
+}
+
+
+void InsetMathHash::metrics(MetricsInfo & mi, Dimension & dim) const
+{
+ metricsStrRedBlack(mi, dim, str_);
+}
+
+
+void InsetMathHash::draw(PainterInfo & pi, int x, int y) const
+{
+ drawStrRed(pi, x, y, str_);
+}
+
+
+void InsetMathHash::normalize(NormalStream & os) const
+{
+ os << "[hash " << str_ << "] ";
+}
+
+
MathMacroArgument::MathMacroArgument(int n)
: number_(n)
{
if (n < 1 || n > 9) {
- LYXERR0("MathMacroArgument::MathMacroArgument: wrong Argument id: " << n);
+ LYXERR0("MathMacroArgument::MathMacroArgument: wrong Argument id: "
+ << n);
+ LASSERT(false, n = 1);
}
// The profiler tells us not to use
// so we do the conversion of n to ASCII manually.
// This works because 1 <= n <= 9.
str_.resize(2);
- str_[0] = '#';
str_[1] = '0' + n;
}
{
if (n < 1 || n > 9) {
LYXERR0("MathMacroArgument::setNumber: wrong Argument id: " << n);
+ LASSERT(false, return);
}
number_ = n;
}
-void MathMacroArgument::write(WriteStream & os) const
-{
- os << str_;
-}
-
-
-void MathMacroArgument::metrics(MetricsInfo & mi, Dimension & dim) const
-{
- metricsStrRedBlack(mi, dim, str_);
-}
-
-
-void MathMacroArgument::draw(PainterInfo & pi, int x, int y) const
-{
- drawStrRed(pi, x, y, str_);
-}
-
-
void MathMacroArgument::normalize(NormalStream & os) const
{
os << "[macroarg " << str_ << "] ";
namespace lyx {
-/// A macro argument.
-class MathMacroArgument : public InsetMath {
+// A # that failed to parse
+class InsetMathHash : public InsetMath {
public:
- ///
- explicit MathMacroArgument(int number);
+ InsetMathHash(docstring const & str = docstring()) : str_('#' + str) {};
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
void draw(PainterInfo &, int x, int y) const;
///
- int number() const { return number_; }
+ void normalize(NormalStream &) const;
+ ///
+ void write(WriteStream & os) const;
+
+private:
+ Inset * clone() const;
+
+protected:
+ ///
+ docstring str_;
+};
+
+
+/// A macro argument.
+class MathMacroArgument : public InsetMathHash {
+public:
+ /// Assumes 0 < number <= 9
+ explicit MathMacroArgument(int number);
///
+ int number() const { return number_; }
+ /// Assumes 0 < n <= 9
void setNumber(int n);
///
InsetCode lyxCode() const { return MATH_MACROARG_CODE; }
///
void normalize(NormalStream &) const;
- ///
- void write(WriteStream & os) const;
private:
Inset * clone() const;
/// A number between 1 and 9
int number_;
- ///
- docstring str_;
};
}
else if (t.cat() == catParameter) {
- Token const & n = getToken();
- if (n.character())
- cell->push_back(MathAtom(new MathMacroArgument(n.character()-'0')));
+ Token const & n = nextToken();
+ char_type c = n.character();
+ if (c && '0' < c && c <= '9') {
+ cell->push_back(MathAtom(new MathMacroArgument(c - '0')));
+ getToken();
+ } else
+ cell->push_back(MathAtom(new InsetMathHash()));
}
else if (t.cat() == catActive)