1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
// Copyright (c) 1996 James Clark
// See the file copying.txt for copying permission.
#ifndef SchemeParser_INCLUDED
#define SchemeParser_INCLUDED 1
#include "Interpreter.h"
#include "Expression.h"
#include <OpenSP/Owner.h>
#ifdef DSSSL_NAMESPACE
namespace DSSSL_NAMESPACE {
#endif
class LangObj;
class SchemeParser : public Messenger {
public:
SchemeParser(Interpreter &, Owner<InputSource> &);
void parse();
void parseStandardChars();
void parseMapSdataEntity(const StringC &name, const StringC &text);
void parseNameChars();
void parseSeparatorChars();
void parseFeatures();
void parseGrovePlan();
bool parseExpression(Owner<Expression> &);
private:
SchemeParser(const SchemeParser &); // undefined
void operator=(const SchemeParser &); // undefined
enum {
allowEndOfEntity = 01,
allowFalse = 02,
allowKeyword = 04,
allowOpenParen = 010,
allowCloseParen = 020,
allowIdentifier = 040,
allowPeriod = 0100,
allowOtherExpr = 0200, // number, character, glyph-id, quote, backquote
allowExpressionKey = 0400,
allowKeyDefine = 01000,
allowKeyElse = 02000,
allowKeyArrow = 04000, // =>
allowString = 010000,
allowHashOptional = 020000,
allowHashKey = 040000,
allowHashRest = 0100000,
allowUnquote = 0200000,
allowUnquoteSplicing = 0400000,
allowQuasiquoteKey = 01000000,
allowVector = 02000000,
allowHashContents = 04000000,
allowExpr = (allowFalse|allowKeyword|allowOpenParen|allowIdentifier
|allowString|allowHashOptional|allowHashKey|allowHashRest
|allowOtherExpr)
};
enum Token {
tokenEndOfEntity,
tokenTrue,
tokenFalse,
tokenString,
tokenIdentifier,
tokenKeyword,
tokenChar,
tokenNumber,
tokenGlyphId,
tokenOpenParen,
tokenCloseParen,
tokenPeriod,
tokenVector,
tokenQuote,
tokenQuasiquote,
tokenUnquote,
tokenUnquoteSplicing,
tokenHashRest,
tokenHashOptional,
tokenHashKey,
tokenHashContents,
tokenVoid
};
bool doDefine();
bool doDefineUnit();
bool doQuery();
bool doElement();
bool doOrElement();
bool doDefault();
bool doId();
bool doRoot();
bool doMode();
bool doDeclareInitialValue();
bool doDeclareCharacteristic();
bool doDeclareCharCharacteristicAndProperty();
bool doDeclareFlowObjectClass();
bool doDeclareClassAttribute();
bool doDeclareIdAttribute();
bool doDeclareFlowObjectMacro();
bool doDeclareDefaultLanguage();
bool doDefineLanguage();
bool doCollate();
bool doMultiCollatingElement();
bool doCollatingSymbol();
bool doCollatingOrder();
bool doWeights();
bool doToupper();
bool doTolower();
bool doDeclareCharProperty();
bool doAddCharProperties();
bool doAssociation();
bool skipForm();
bool parseDefine(Identifier *&, Owner<Expression> &);
bool parseSpecialQuery(Owner<Expression> &expr, const char *query);
bool parseExpression(unsigned allowed, Owner<Expression> &,
Identifier::SyntacticKey &, Token &);
bool parseBegin(Owner<Expression> &expr);
bool parseBody(Owner<Expression> &expr);
bool parseSet(Owner<Expression> &expr);
bool parseLambda(Owner<Expression> &);
bool parseLet(Owner<Expression> &);
bool parseLetStar(Owner<Expression> &);
bool parseLetrec(Owner<Expression> &);
bool parseBindingsAndBody(Vector<const Identifier *> &vars,
NCVector<Owner<Expression> > &inits,
Owner<Expression> &body);
bool parseBindingsAndBody1(Vector<const Identifier *> &vars,
NCVector<Owner<Expression> > &inits,
Owner<Expression> &body);
bool parseQuote(Owner<Expression> &);
bool parseIf(Owner<Expression> &);
bool parseCond(Owner<Expression> &, bool opt = 0);
bool parseCase(Owner<Expression> &);
bool parseOr(Owner<Expression> &);
bool parseAnd(Owner<Expression> &, bool opt = 0);
bool parseMake(Owner<Expression> &);
bool parseStyle(Owner<Expression> &);
bool parseWithMode(Owner<Expression> &);
bool parseFormals(Vector<const Identifier *> &,
NCVector<Owner<Expression> > &,
int &, bool &, int &);
bool parseDatum(unsigned otherAllowed, ELObj *&, Location &, Token &);
bool parseSelfEvaluating(unsigned otherAllowed, ELObj *&, Token &);
bool parseAbbreviation(const char *, ELObj *&);
bool parseQuasiquote(Owner<Expression> &);
bool parseQuasiquoteTemplate(unsigned level,
unsigned allowed,
Owner<Expression> &,
Identifier::SyntacticKey &,
Token &,
bool &spliced);
void createQuasiquoteAbbreviation(const char *, Owner<Expression> &);
bool parseRuleBody(Owner<Expression> &, ProcessingMode::RuleType &);
bool parseRuleBody(Owner<Expression> &, Owner<Expression> &,
ProcessingMode::RuleType &, bool);
bool getToken(unsigned, Token &);
bool handleNumber(unsigned, Token &);
bool handleIdentifier(unsigned, Token &);
void extendToken();
bool scanString();
void skipComment();
void skipIntertokenSpace();
bool peekDefine();
bool tokenRecover(unsigned, Token &);
bool scanString(unsigned, Token &);
ELObj *convertAfiiGlyphId(const StringC &);
Identifier *lookup(const StringC &str);
ProcessingMode *lookupProcessingMode(const StringC &);
void dispatchMessage(Message &);
void dispatchMessage(const Message &);
void initMessage(Message &msg);
bool dsssl2() const;
Interpreter *interp_;
Owner<InputSource> in_;
StringC currentToken_;
ProcessingMode *defMode_;
const char *afiiPublicId_;
bool dsssl2_;
LangObj *lang_;
};
inline
Identifier *SchemeParser::lookup(const StringC &str)
{
return interp_->lookup(str);
}
inline
ProcessingMode *SchemeParser::lookupProcessingMode(const StringC &name)
{
return interp_->lookupProcessingMode(name);
}
inline
bool SchemeParser::dsssl2() const
{
return dsssl2_;
}
#ifdef DSSSL_NAMESPACE
}
#endif
#endif /* not SchemeParser_INCLUDED */
|