Ejemplo n.º 1
0
void TParser::ParseStatement(void)
{
    InsertLineMarker();

    //--Call the appropriate parsing function based on
    //--the statement's first token.
    switch (token) {

	case tcIdentifier: {

	    //--Search for the identifier and enter it if
	    //--necessary.  Append the symbol table node handle
	    //--to the icode.
	    TSymtabNode *pNode = Find(pToken->String());
	    icode.Put(pNode);

	    //--Based on how the identifier is defined,
	    //--parse an assignment statement or a procedure call.
	    if (pNode->defn.how == dcUndefined) {
		pNode->defn.how = dcVariable;
		SetType(pNode->pType, pDummyType);
		ParseAssignment(pNode);
	    }
	    else if (pNode->defn.how == dcProcedure) {
		ParseSubroutineCall(pNode, true);
	    }
	    else ParseAssignment(pNode);

	    break;
	}

	case tcREPEAT:      ParseREPEAT();      break;
	case tcWHILE:       ParseWHILE();       break;
	case tcIF:          ParseIF();          break;
	case tcFOR:         ParseFOR();         break;
	case tcCASE:        ParseCASE();        break;
	case tcBEGIN:       ParseCompound();    break;
    }

    //--Resynchronize at a proper statement ending.
    if (token != tcEndOfFile) {
	Resync(tlStatementFollow, tlStatementStart);
    }
}
Ejemplo n.º 2
0
bool Style::Parse(const char* t, size_t maxLen, Doc* doc) {
// "background: #8f8; width: 100%; height: 100%;"
#define TSTART (t + startv)
#define TLEN (i - startv)
	size_t startk = -1;
	size_t eq     = -1;
	size_t startv = -1;
	int    nerror = 0;
	for (size_t i = 0; true; i++) {
		bool eof = t[i] == 0 || i == maxLen;
		if (t[i] == 32) {
		} else if (t[i] == ':')
			eq = i;
		else if (t[i] == ';' || (eof && startv != -1)) {
			// clang-format off
			bool ok = true;
			if (MATCH(t, startk, eq, "background"))		                { ok = ParseSingleAttrib(TSTART, TLEN, &Color::Parse, CatBackground, *this); }
			else if (MATCH(t, startk, eq, "color"))		                { ok = ParseSingleAttrib(TSTART, TLEN, &Color::Parse, CatColor, *this); }
			else if (MATCH(t, startk, eq, "width"))		                { ok = ParseSingleAttrib(TSTART, TLEN, &Size::Parse, CatWidth, *this); }
			else if (MATCH(t, startk, eq, "height"))		            { ok = ParseSingleAttrib(TSTART, TLEN, &Size::Parse, CatHeight, *this); }
			else if (MATCH(t, startk, eq, "padding"))		            { ok = ParseCompound(TSTART, TLEN, &StyleBox::Parse, CatPadding_Left, *this); }
			else if (MATCH(t, startk, eq, "margin"))		            { ok = ParseCompound(TSTART, TLEN, &StyleBox::Parse, CatMargin_Left, *this); }
			else if (MATCH(t, startk, eq, "display"))		            { ok = ParseSingleAttrib(TSTART, TLEN, &ParseDisplayType, CatDisplay, *this); }
			else if (MATCH(t, startk, eq, "position"))		            { ok = ParseSingleAttrib(TSTART, TLEN, &ParsePositionType, CatPosition, *this); }
			else if (MATCH(t, startk, eq, "border"))		            { ok = ParseDirect(TSTART, TLEN, &ParseBorder, *this); }
			else if (MATCH(t, startk, eq, "border-radius"))		        { ok = ParseSingleAttrib(TSTART, TLEN, &Size::Parse, CatBorderRadius, *this); }
			//else if ( MATCH(t, startk, eq, "left") )                  { ok = ParseSingleAttrib( TSTART, TLEN, &Size::Parse, CatLeft, *this ); }
			//else if ( MATCH(t, startk, eq, "right") )                 { ok = ParseSingleAttrib( TSTART, TLEN, &Size::Parse, CatRight, *this ); }
			//else if ( MATCH(t, startk, eq, "top") )                   { ok = ParseSingleAttrib( TSTART, TLEN, &Size::Parse, CatTop, *this ); }
			//else if ( MATCH(t, startk, eq, "bottom") )                { ok = ParseSingleAttrib( TSTART, TLEN, &Size::Parse, CatBottom, *this ); }
			else if (MATCH(t, startk, eq, "break"))                     { ok = ParseSingleAttrib(TSTART, TLEN, &ParseBreakType, CatBreak, *this); }
			else if (MATCH(t, startk, eq, "canfocus"))                  { ok = ParseBool(TSTART, TLEN, CatCanFocus, *this); }
			else if (MATCH(t, startk, eq, "cursor"))                    { ok = ParseSingleAttrib(TSTART, TLEN, &ParseCursor, CatCursor, *this); }
			else if (MATCH(t, startk, eq, "flow-context"))              { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFlowContext, CatFlowContext, *this); }
			else if (MATCH(t, startk, eq, "flow-axis"))                 { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFlowAxis, CatFlowAxis, *this); }
			else if (MATCH(t, startk, eq, "flow-direction-horizontal")) { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFlowDirection, CatFlowDirection_Horizontal, *this); }
			else if (MATCH(t, startk, eq, "flow-direction-vertical"))   { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFlowDirection, CatFlowDirection_Vertical, *this); }
			else if (MATCH(t, startk, eq, "box-sizing"))                { ok = ParseSingleAttrib(TSTART, TLEN, &ParseBoxSize, CatBoxSizing, *this); }
			else if (MATCH(t, startk, eq, "font-size"))                 { ok = ParseSingleAttrib(TSTART, TLEN, &Size::Parse, CatFontSize, *this); }
			else if (MATCH(t, startk, eq, "font-family"))               { ok = ParseSingleAttrib(TSTART, TLEN, &ParseFontFamily, CatFontFamily, *this); }
			else if (MATCH(t, startk, eq, "text-align-vertical"))       { ok = ParseSingleAttrib(TSTART, TLEN, &ParseTextAlignVertical, CatText_Align_Vertical, *this); }
			else if (MATCH(t, startk, eq, "left"))                      { ok = ParseSingleAttrib(TSTART, TLEN, &ParseHorizontalBinding, CatLeft, *this); }
			else if (MATCH(t, startk, eq, "hcenter"))                   { ok = ParseSingleAttrib(TSTART, TLEN, &ParseHorizontalBinding, CatHCenter, *this); }
			else if (MATCH(t, startk, eq, "right"))                     { ok = ParseSingleAttrib(TSTART, TLEN, &ParseHorizontalBinding, CatRight, *this); }
			else if (MATCH(t, startk, eq, "top"))                       { ok = ParseSingleAttrib(TSTART, TLEN, &ParseVerticalBinding, CatTop, *this); }
			else if (MATCH(t, startk, eq, "vcenter"))                   { ok = ParseSingleAttrib(TSTART, TLEN, &ParseVerticalBinding, CatVCenter, *this); }
			else if (MATCH(t, startk, eq, "bottom"))                    { ok = ParseSingleAttrib(TSTART, TLEN, &ParseVerticalBinding, CatBottom, *this); }
			else if (MATCH(t, startk, eq, "baseline"))                  { ok = ParseSingleAttrib(TSTART, TLEN, &ParseVerticalBinding, CatBaseline, *this); }
			else if (MATCH(t, startk, eq, "bump"))                      { ok = ParseSingleAttrib(TSTART, TLEN, &ParseBump, CatBump, *this); }
			// clang-format on
			else {
				ok = false;
				ParseFail("Parse failed - unknown property: '%.*s'\n", int(eq - startk), t + startk);
			}
			if (!ok)
				nerror++;
			eq     = -1;
			startk = -1;
			startv = -1;
		} else {
			if (startk == -1)
				startk = i;
			else if (startv == -1 && eq != -1)
				startv = i;
		}

		if (eof)
			break;
	}
	return nerror == 0;
#undef TSTART
#undef TLEN
}