void InfixPrinter::WriteToken(std::ostream& aOutput, const std::string& aString) { if (IsAlNum(iPrevLastChar) && (IsAlNum(aString[0]) || aString[0] == '_')) aOutput.put(' '); else if (IsSymbolic(iPrevLastChar) && IsSymbolic(aString[0])) aOutput.put(' '); aOutput.write(aString.c_str(), aString.size()); RememberLastChar(aString.back()); }
unsigned int FontDescriptorWriter::CalculateFlags( FreeTypeFaceWrapper* inFontInfo, const UIntAndGlyphEncodingInfoVector& inEncodedGlyphs) { unsigned int flags = 0; // see FreeTypeFaceWrapper::GetFontFlags for explanation, if you must if(inFontInfo->IsFixedPitch()) flags |= 1; if(inFontInfo->IsSerif()) flags |= 2; if(IsSymbolic(inFontInfo,inEncodedGlyphs)) flags |= 4; else flags |= 32; if(inFontInfo->IsScript()) flags |= 8; if(inFontInfo->IsItalic()) flags |= 64; if(inFontInfo->IsForceBold()) flags |= (1<<18); return flags; }
/** Get the name of a shell variable (returns a copy). */ char *GetSymbolName(const char *str) { char *temp; int stop; if(*str == '$') { temp = Allocate(2); temp[0] = '$'; temp[1] = 0; } else { for(stop = 0; IsSymbolic(str[stop]); stop++); temp = Allocate(stop + 1); memcpy(temp, str, stop); temp[stop] = 0; } return temp; }
void ParsedObject::ReadExpression(LispInt depth) { ReadAtom(); for (;;) { //Handle special case: a[b]. a is matched with lowest precedence!! if (iLookAhead == iParser.iEnvironment.iProgOpen->String()) { // Match opening bracket MatchToken(iLookAhead); // Read "index" argument ReadExpression(KMaxPrecedence); // Match closing bracket if (iLookAhead != iParser.iEnvironment.iProgClose->String()) throw LispErrGeneric(std::string("Expecting a ] close bracket for program block, but got ") + *iLookAhead + std::string(" instead")); MatchToken(iLookAhead); // Build into Ntn(...) const LispString* theOperator = iParser.iEnvironment.iNth->String(); InsertAtom(theOperator); Combine(2); } else { LispOperators::const_iterator opi = iParser.iInfixOperators.find(iLookAhead); if (opi == iParser.iInfixOperators.end()) { if (!IsSymbolic((*iLookAhead)[0])) return; const std::size_t origlen = iLookAhead->size(); std::size_t len = origlen; while (len > 1) { len -= 1; const LispString* lookUp = iParser.iEnvironment.HashTable().LookUp(iLookAhead->substr(0, len)); opi = iParser.iInfixOperators.find(lookUp); if (opi != iParser.iInfixOperators.end()) { const LispString* lookUpRight = iParser.iEnvironment.HashTable().LookUp(iLookAhead->substr(len, origlen - len)); if (iParser.iPrefixOperators.find(lookUpRight) != iParser.iPrefixOperators.end()) { iLookAhead = lookUp; LispInput& input = iParser.iInput; LispInt newPos = input.Position() - (origlen - len); input.SetPosition(newPos); break; } opi = iParser.iInfixOperators.end(); } } if (opi == iParser.iInfixOperators.end()) return; } if (depth < opi->second.iPrecedence) return; LispInt upper = opi->second.iPrecedence; if (!opi->second.iRightAssociative) upper--; GetOtherSide(2, upper); } } }
Token Scanner::Get(Need need) { int type = Token::EOT; old_index = index; old_line = line; eos = str + length; p = str + index; if (p >= eos) { if (need == Demand && reader) { Load(reader->more()); if (length > 0) return Get(need); } return Token("", type, 0, line, 0); } while (isspace(*p) && p < eos) { // skip initial white space if (*p == '\n') { line++; lineStart = p - str; } p++; } if (p >= eos) { if (need == Demand && reader) { Load(reader->more()); if (length > 0) return Get(need); } return Token("", type, 0, line, 0); } Token result; size_t start = p - str; if (*p == '"' || *p == '\'') { // special case for quoted tokens if (*p == '"') type = Token::StringLiteral; else type = Token::CharLiteral; char match = *p; while (++p < eos) { if (*p == match) { // find matching quote if (*(p-1) != '\\') { // if not escaped p++; // token includes matching quote break; } } } } // generic delimited comments else if (*p == Token::comBeg(0) && (!Token::comBeg(1) || *(p+1) == Token::comBeg(1))) { type = Token::Comment; while (++p < eos) { if (*p == Token::comEnd(0) && (!Token::comEnd(1) || *(p+1) == Token::comEnd(1))) { p++; if (Token::comEnd(1)) p++; break; } } } // alternate form delimited comments else if (*p == Token::altBeg(0) && (!Token::altBeg(1) || *(p+1) == Token::altBeg(1))) { type = Token::Comment; while (++p < eos) { if (*p == Token::altEnd(0) && (!Token::altEnd(1) || *(p+1) == Token::altEnd(1))) { p++; if (Token::altEnd(1)) p++; break; } } } else if (*p == '.') type = Token::Dot; else if (*p == ',') type = Token::Comma; else if (*p == ';') type = Token::Semicolon; else if (*p == '(') type = Token::LParen; else if (*p == ')') type = Token::RParen; else if (*p == '[') type = Token::LBracket; else if (*p == ']') type = Token::RBracket; else if (*p == '{') type = Token::LBrace; else if (*p == '}') type = Token::RBrace; // use lexical sub-parser for ints and floats else if (isdigit(*p)) type = GetNumeric(); else if (IsSymbolic(*p)) { type = Token::SymbolicIdent; while (IsSymbolic(*p)) p++; } else { type = Token::AlphaIdent; while (IsAlpha(*p)) p++; } size_t extent = (p - str) - start; if (extent < 1) extent = 1; // always get at least one character index = start + extent; // advance the cursor int col = start - lineStart; if (line == 0) col++; char* buf = new(__FILE__, __LINE__) char [extent + 1]; strncpy(buf, str + start, extent); buf[extent] = '\0'; if (type == Token::Comment && Token::hidecom) { delete [] buf; if (Token::comEnd(0) == '\n') { line++; lineStart = p - str; } return Get(need); } if (type == Token::AlphaIdent || // check for keyword type == Token::SymbolicIdent) { int val; if (Token::findKey(Text(buf), val)) result = Token(buf, Token::Keyword, val, line+1, col); } if (result.mType != Token::Keyword) result = Token(buf, type, 0, line+1, col); if (line+1 > (size_t) best.mLine || (line+1 == (size_t) best.mLine && col > best.mColumn)) best = result; delete [] buf; return result; }