소스 검색

Combine emit()/emit_first() internally.

tags/v0.3
Ben Kurtovic 11 년 전
부모
커밋
ebf99d722c
2개의 변경된 파일13개의 추가작업 그리고 54개의 파일을 삭제
  1. +7
    -53
      mwparserfromhell/parser/tokenizer.c
  2. +6
    -1
      mwparserfromhell/parser/tokenizer.h

+ 7
- 53
mwparserfromhell/parser/tokenizer.c 파일 보기

@@ -347,7 +347,7 @@ static void* Tokenizer_fail_route(Tokenizer* self)
/*
Write a token to the end of the current token stack.
*/
static int Tokenizer_emit(Tokenizer* self, PyObject* token)
static int Tokenizer_emit_token(Tokenizer* self, PyObject* token, int first)
{
PyObject* instance;

@@ -356,7 +356,8 @@ static int Tokenizer_emit(Tokenizer* self, PyObject* token)
instance = PyObject_CallObject(token, NULL);
if (!instance)
return -1;
if (PyList_Append(self->topstack->stack, instance)) {
if (first ? PyList_Insert(self->topstack->stack, 0, instance) :
PyList_Append(self->topstack->stack, instance)) {
Py_DECREF(instance);
return -1;
}
@@ -367,8 +368,8 @@ static int Tokenizer_emit(Tokenizer* self, PyObject* token)
/*
Write a token to the end of the current token stack.
*/
static int Tokenizer_emit_kwargs(Tokenizer* self, PyObject* token,
PyObject* kwargs)
static int Tokenizer_emit_token_kwargs(Tokenizer* self, PyObject* token,
PyObject* kwargs, int first)
{
PyObject* instance;

@@ -381,55 +382,8 @@ static int Tokenizer_emit_kwargs(Tokenizer* self, PyObject* token,
Py_DECREF(kwargs);
return -1;
}
if (PyList_Append(self->topstack->stack, instance)) {
Py_DECREF(instance);
Py_DECREF(kwargs);
return -1;
}
Py_DECREF(instance);
Py_DECREF(kwargs);
return 0;
}

/*
Write a token to the beginning of the current token stack.
*/
static int Tokenizer_emit_first(Tokenizer* self, PyObject* token)
{
PyObject* instance;

if (Tokenizer_push_textbuffer(self))
return -1;
instance = PyObject_CallObject(token, NULL);
if (!instance)
return -1;
if (PyList_Insert(self->topstack->stack, 0, instance)) {
Py_DECREF(instance);
return -1;
}
Py_DECREF(instance);
return 0;
}

/*
Write a token to the beginning of the current token stack, with kwargs.
Steals a reference to kwargs.
*/
static int Tokenizer_emit_first_kwargs(Tokenizer* self, PyObject* token,
PyObject* kwargs)
{
PyObject* instance;

if (Tokenizer_push_textbuffer(self)) {
Py_DECREF(kwargs);
return -1;
}
instance = PyObject_Call(token, NOARGS, kwargs);
if (!instance) {
Py_DECREF(kwargs);
return -1;
}
if (PyList_Insert(self->topstack->stack, 0, instance)) {
if (first ? PyList_Insert(self->topstack->stack, 0, instance):
PyList_Append(self->topstack->stack, instance)) {
Py_DECREF(instance);
Py_DECREF(kwargs);
return -1;


+ 6
- 1
mwparserfromhell/parser/tokenizer.h 파일 보기

@@ -214,13 +214,18 @@ typedef struct {
} Tokenizer;


/* Macros for accessing Tokenizer data: */
/* Macros related to Tokenizer functions: */

#define Tokenizer_READ(self, delta) (*PyUnicode_AS_UNICODE(Tokenizer_read(self, delta)))
#define Tokenizer_READ_BACKWARDS(self, delta) \
(*PyUnicode_AS_UNICODE(Tokenizer_read_backwards(self, delta)))
#define Tokenizer_CAN_RECURSE(self) (self->depth < MAX_DEPTH && self->cycles < MAX_CYCLES)

#define Tokenizer_emit(self, token) Tokenizer_emit_token(self, token, 0)
#define Tokenizer_emit_first(self, token) Tokenizer_emit_token(self, token, 1)
#define Tokenizer_emit_kwargs(self, token, kwargs) Tokenizer_emit_token_kwargs(self, token, kwargs, 0)
#define Tokenizer_emit_first_kwargs(self, token, kwargs) Tokenizer_emit_token_kwargs(self, token, kwargs, 1)


/* Macros for accessing HTML tag definitions: */



불러오는 중...
취소
저장