void Writer::writeEndStructure(char endChar) { if (m_Context.empty() || m_Context.top().endChar != endChar) { if (!std::uncaught_exception()) YSON_THROW(std::string("Incorrect position for '") + endChar + "'"); else return; } switch (m_State) { case AT_START_OF_VALUE_NO_COMMA: case AT_START_OF_STRUCTURE: if (formatting() == FORMAT) outdent(); break; case AT_END_OF_VALUE: if (formatting() == FORMAT) { outdent(); *m_Stream << '\n'; writeIndentationImpl(); } break; case AT_START_OF_LINE_NO_COMMA: case AT_START_OF_LINE_BEFORE_COMMA: if (formatting() == FORMAT) { outdent(); writeIndentationImpl(); } break; default: YSON_THROW(std::string("Incorrect position for '") + endChar + "'"); } m_Context.pop(); *m_Stream << endChar; m_State = AT_END_OF_VALUE; }
void do_end_element(const std::string& qName, const std::string& /* namespaceURI */) { if(!seen_root_) do_decl(""); preoutdent(empty_); if(empty_) stream_ << "/>"; else stream_ << "</" << qName << ">"; outdent(empty_); empty_ = false; } // do_end_element
static int scan_newline(luna_lexer_t *self) { int curr = 0; int prev = self->indent_stack[self->indents]; ++self->lineno; while (accept(' ')) ++curr; if (curr > prev) { token(INDENT); self->indent_stack[++self->indents] = curr; } else if (curr < prev) { while (self->indent_stack[self->indents] > curr) { ++self->outdents; --self->indents; } outdent(self); } else { token(NEWLINE); } return 1; }
void on_dict_end(void *ctx, const char *code, const char *name) { outdent(); }
void do_end_element(const std::string& /* qName */, const std::string& /* namespaceURI */) { outdent(); current_ = current_.getParentNode(); } // do_end_element
int luna_scan(luna_lexer_t *self) { int c; token(ILLEGAL); // deferred outdents if (self->outdents) return outdent(self); // scan scan: switch (c = next) { case ' ': case '\t': goto scan; case '(': return token(LPAREN); case ')': return token(RPAREN); case '{': return token(LBRACE); case '}': return token(RBRACE); case '[': return token(LBRACK); case ']': return token(RBRACK); case ',': return token(COMMA); case '.': return token(OP_DOT); case '%': return token(OP_MOD); case '^': return token(OP_BIT_XOR); case '~': return token(OP_BIT_NOT); case '?': return token(QMARK); case ':': return token(COLON); case '@': self->tok.value.as_string = "self"; return token(ID); case '+': switch (next) { case '+': return token(OP_INCR); case '=': return token(OP_PLUS_ASSIGN); default: return undo, token(OP_PLUS); } case '-': switch (next) { case '-': return token(OP_DECR); case '=': return token(OP_MINUS_ASSIGN); default: return undo, token(OP_MINUS); } case '*': switch (next) { case '=': return token(OP_MUL_ASSIGN); case '*': return token(OP_POW); default: return undo, token(OP_MUL); } case '/': return '=' == next ? token(OP_DIV_ASSIGN) : (undo, token(OP_DIV)); case '!': return '=' == next ? token(OP_NEQ) : (undo, token(OP_NOT)); case '=': return '=' == next ? token(OP_EQ) : (undo, token(OP_ASSIGN)); case '&': switch (next) { case '&': return '=' == next ? token(OP_AND_ASSIGN) : (undo, token(OP_AND)); default: return undo, token(OP_BIT_AND); } case '|': switch (next) { case '|': return '=' == next ? token(OP_OR_ASSIGN) : (undo, token(OP_OR)); default: return undo, token(OP_BIT_OR); } case '<': switch (next) { case '=': return token(OP_LTE); case '<': return token(OP_BIT_SHL); default: return undo, token(OP_LT); } case '>': switch (next) { case '=': return token(OP_GTE); case '>': return token(OP_BIT_SHR); default: return undo, token(OP_GT); } case '#': while ((c = next) != '\n' && c) ; undo; goto scan; case '\n': return scan_newline(self); case '"': case '\'': return scan_string(self, c); case 0: if (self->indents) { --self->indents; return token(OUTDENT); } token(EOS); return 0; default: if (isalpha(c) || '_' == c) return scan_ident(self, c); if (isdigit(c) || '.' == c) return scan_number(self, c); error("illegal character"); return 0; } }