void nip::parse::Parser::block_start() { if (accept(LEFT_BRACKET)) { block_type.push_back(BRACKETS); newlines(); } else if (accept(COLON)) { block_type.push_back(INDENTATION); newlines(); if (expect(INDENT, "expected indent")) { return; } } else { error("expected the start of a block"); } }
void nip::parse::Parser::metadata_field() { if (accept(KEY_DOCS)) { if (expect(LIT_STRING, "expected string literal")) { ; // Add documentation string } } else if (accept(KEY_OP)) { if (accept(KEY_LEFT)) { if (accept(LIT_INT)) { ; // Add left-assosiative operator with appropriate precidence. } } else if (accept(KEY_RIGHT)) { if (accept(LIT_INT)) { ; // Add right-assosiative operator with appropriate precidence. } } else { // Add general data } } else if (accept(IDENTIFIER)) { newlines(); } else { error("expected identifier"); } }
void nip::parse::Parser::type_definition() { if (accept(IDENTIFIER)) { block_start(); while (accept(KEY_CASE)) { type_name(); newlines(); } } else { error("expected identifier"); } }
void nip::parse::Parser::element() { if (accept(KEY_TRAIT)) { trait_declaration(); } else if (accept(KEY_INTRIN)) { intrinsic_declaration(); } else if (accept(KEY_DEFINE)) { function_definition(); } else if (accept(KEY_INSTANCE)) { instance_definition(); } else if (accept(KEY_PERMIT)) { permission_definition(); } else if (accept(KEY_ABOUT)) { about_section(); } else if (accept(KEY_TYPE)) { if (accept(KEY_SYNONYM)) { type_synonym(); } else { type_definition(); } } else if (accept(KEY_VOCAB)) { if (accept(KEY_SYNONYM)) { vocabulary_synonym(); } else { vocabulary_definition(); } } else if (accept(KEY_IMPORT)) { import_element(); } else if (accept(KEY_EXPORT)) { // export_element(); // Not implimented error("export isn't a supported language feature"); } else { while (!is(NEWLINE, SEMI_COLON)) { term(); } } endofstatement(); newlines(); }
int getPlayers() { static const int BUFFERSIZE = 10; int i, noPlayers; char buffer[BUFFERSIZE]; do { printf("Enter a number of human players between 0 - 4\n"); scanf("%d", &noPlayers); } while ((noPlayers > 4) || (noPlayers < 0)); for (i = 0; i < noPlayers; i++) { printf("Enter player %d's name:\n", (i + 1)); scanf(" %s", buffer); /*printf("string entered: %s\n", buffer);*/newlines(1); strcpy(playerArr[i], buffer); } return noPlayers; }
void playerTurn(table *t, player *p, deck *d) { char ans; ans = 'd'; assert((t) && (p) && (d)); while ((ans != 's') && (p->playerHand->bust != 1)) { printf("Hit: h\tStay: s\n"); newlines(1); tabs(t->margin); spaces(t->buffer); ans = getchar(); if (ans == 'h') { dealCard(t, d, p, 1); } assessHand(p->playerHand); displayTable(t, 1); } }
/** * Test strings quoted with double quotes, single quotes, strings * containing newlines, and strings containing unicode characters. */ TEST(CssTokenizerTest, String) { istringstream in("\"string\" 'string' 'string\\\nstring' '\\12EF'"), inBad1("'string\n'"), inBad2("'string"), newlines("'\\\n \\\r\n \\\r'"); CssTokenizer t(&in), tBad1(&inBad1), tBad2(&inBad2), tNewlines(&newlines); EXPECT_EQ(Token::STRING, t.readNextToken()); EXPECT_EQ(Token::WHITESPACE, t.readNextToken()); EXPECT_EQ(Token::STRING, t.readNextToken()); EXPECT_EQ(Token::WHITESPACE, t.readNextToken()); EXPECT_EQ(Token::STRING, t.readNextToken()); EXPECT_EQ(Token::WHITESPACE, t.readNextToken()); EXPECT_EQ(Token::STRING, t.readNextToken()); EXPECT_THROW(tBad1.readNextToken(), ParseException*); EXPECT_THROW(tBad2.readNextToken(), ParseException*); ASSERT_EQ(Token::STRING, tNewlines.readNextToken()); EXPECT_STREQ("'\\\n \\\r\n \\\r'", tNewlines.getToken()->str.c_str()); }