Cleanup of buffering text/strings.
This removes the need to use ||= and such, which should speed things up a bit and keeps the code cleaner.
This commit is contained in:
parent
ca6f422036
commit
970ce27283
|
@ -29,6 +29,9 @@ module Oga
|
||||||
@tokens = []
|
@tokens = []
|
||||||
@stack = []
|
@stack = []
|
||||||
@top = 0
|
@top = 0
|
||||||
|
|
||||||
|
@string_buffer = ''
|
||||||
|
@text_buffer = ''
|
||||||
end
|
end
|
||||||
|
|
||||||
def lex(data)
|
def lex(data)
|
||||||
|
@ -75,11 +78,17 @@ module Oga
|
||||||
@tokens << token
|
@tokens << token
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def emit_text_buffer
|
||||||
|
add_token(:T_TEXT, @text_buffer)
|
||||||
|
|
||||||
|
@text_buffer = ''
|
||||||
|
end
|
||||||
|
|
||||||
def emit_string_buffer
|
def emit_string_buffer
|
||||||
add_token(:T_STRING, @string_buffer)
|
add_token(:T_STRING, @string_buffer)
|
||||||
advance_column
|
advance_column
|
||||||
|
|
||||||
@string_buffer = nil
|
@string_buffer = ''
|
||||||
end
|
end
|
||||||
|
|
||||||
%%{
|
%%{
|
||||||
|
@ -109,8 +118,11 @@ module Oga
|
||||||
dquote = '"';
|
dquote = '"';
|
||||||
squote = "'";
|
squote = "'";
|
||||||
|
|
||||||
|
action buffer_text {
|
||||||
|
@text_buffer << text
|
||||||
|
}
|
||||||
|
|
||||||
action buffer_string {
|
action buffer_string {
|
||||||
@string_buffer ||= ''
|
|
||||||
@string_buffer << text
|
@string_buffer << text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,8 +196,7 @@ module Oga
|
||||||
|
|
||||||
cdata := |*
|
cdata := |*
|
||||||
cdata_end => {
|
cdata_end => {
|
||||||
add_token(:T_TEXT, @cdata_buffer)
|
emit_text_buffer
|
||||||
@cdata_buffer = nil
|
|
||||||
|
|
||||||
t(:T_CDATA_END)
|
t(:T_CDATA_END)
|
||||||
|
|
||||||
|
@ -194,7 +205,7 @@ module Oga
|
||||||
|
|
||||||
# Consume everything else character by character and store it in a
|
# Consume everything else character by character and store it in a
|
||||||
# separate buffer.
|
# separate buffer.
|
||||||
any => { @cdata_buffer << text };
|
any => buffer_text;
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
main := |*
|
main := |*
|
||||||
|
@ -211,8 +222,6 @@ module Oga
|
||||||
cdata_start => {
|
cdata_start => {
|
||||||
t(:T_CDATA_START)
|
t(:T_CDATA_START)
|
||||||
|
|
||||||
@cdata_buffer = ''
|
|
||||||
|
|
||||||
fgoto cdata;
|
fgoto cdata;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue