Use 4 spaces for C/Java code.
This commit is contained in:
parent
4e2dca2fd9
commit
d2742cfdde
|
@ -8,5 +8,11 @@ trim_trailing_whitespace = true
|
||||||
[*.{y,rb,rl}]
|
[*.{y,rb,rl}]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|
||||||
[*.{h,h},ext/oga/xml/*.rl]
|
[*.{h,c,java}]
|
||||||
indent_size = 2
|
indent_size = 4
|
||||||
|
|
||||||
|
[ext/liboga/*.rl]
|
||||||
|
indent_size = 4
|
||||||
|
|
||||||
|
[ext/liboga/org/liboga/xml/*.rl]
|
||||||
|
indent_size = 4
|
||||||
|
|
|
@ -14,17 +14,17 @@ VALUE oga_cLexer;
|
||||||
* liboga_xml_lexer_callback(self, "on_string", encoding, ts, te);
|
* liboga_xml_lexer_callback(self, "on_string", encoding, ts, te);
|
||||||
*/
|
*/
|
||||||
void liboga_xml_lexer_callback(
|
void liboga_xml_lexer_callback(
|
||||||
VALUE self,
|
VALUE self,
|
||||||
const char *name,
|
const char *name,
|
||||||
rb_encoding *encoding,
|
rb_encoding *encoding,
|
||||||
const char *ts,
|
const char *ts,
|
||||||
const char *te
|
const char *te
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
VALUE value = rb_enc_str_new(ts, te - ts, encoding);
|
VALUE value = rb_enc_str_new(ts, te - ts, encoding);
|
||||||
VALUE method = rb_intern(name);
|
VALUE method = rb_intern(name);
|
||||||
|
|
||||||
rb_funcall(self, method, 1, value);
|
rb_funcall(self, method, 1, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,9 +36,9 @@ void liboga_xml_lexer_callback(
|
||||||
*/
|
*/
|
||||||
void liboga_xml_lexer_callback_simple(VALUE self, const char *name)
|
void liboga_xml_lexer_callback_simple(VALUE self, const char *name)
|
||||||
{
|
{
|
||||||
VALUE method = rb_intern(name);
|
VALUE method = rb_intern(name);
|
||||||
|
|
||||||
rb_funcall(self, method, 0);
|
rb_funcall(self, method, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
%% write data;
|
%% write data;
|
||||||
|
@ -55,33 +55,33 @@ void liboga_xml_lexer_callback_simple(VALUE self, const char *name)
|
||||||
*/
|
*/
|
||||||
VALUE oga_xml_lexer_advance(VALUE self)
|
VALUE oga_xml_lexer_advance(VALUE self)
|
||||||
{
|
{
|
||||||
/* Pull the data in from Ruby land. */
|
/* Pull the data in from Ruby land. */
|
||||||
VALUE data_ivar = rb_ivar_get(self, rb_intern("@data"));
|
VALUE data_ivar = rb_ivar_get(self, rb_intern("@data"));
|
||||||
|
|
||||||
/* Make sure that all data passed back to Ruby has the proper encoding. */
|
/* Make sure that all data passed back to Ruby has the proper encoding. */
|
||||||
rb_encoding *encoding = rb_enc_get(data_ivar);
|
rb_encoding *encoding = rb_enc_get(data_ivar);
|
||||||
|
|
||||||
char *data_str_val = StringValuePtr(data_ivar);
|
char *data_str_val = StringValuePtr(data_ivar);
|
||||||
|
|
||||||
const char *p = data_str_val;
|
const char *p = data_str_val;
|
||||||
const char *pe = data_str_val + strlen(data_str_val);
|
const char *pe = data_str_val + strlen(data_str_val);
|
||||||
const char *eof = pe;
|
const char *eof = pe;
|
||||||
const char *ts, *te;
|
const char *ts, *te;
|
||||||
|
|
||||||
int act = 0;
|
int act = 0;
|
||||||
int cs = 0;
|
int cs = 0;
|
||||||
int top = 0;
|
int top = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Fixed stack size is enough since the lexer doesn't use that many nested
|
Fixed stack size is enough since the lexer doesn't use that many nested
|
||||||
fcalls.
|
fcalls.
|
||||||
*/
|
*/
|
||||||
int stack[8];
|
int stack[8];
|
||||||
|
|
||||||
%% write init;
|
%% write init;
|
||||||
%% write exec;
|
%% write exec;
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
%%{
|
%%{
|
||||||
|
@ -99,20 +99,20 @@ VALUE oga_xml_lexer_advance(VALUE self)
|
||||||
|
|
||||||
# Machine for processing double quoted strings.
|
# Machine for processing double quoted strings.
|
||||||
string_dquote := |*
|
string_dquote := |*
|
||||||
^dquote+ => {
|
^dquote+ => {
|
||||||
liboga_xml_lexer_callback(self, "on_string", encoding, ts, te);
|
liboga_xml_lexer_callback(self, "on_string", encoding, ts, te);
|
||||||
};
|
};
|
||||||
|
|
||||||
dquote => { fret; };
|
dquote => { fret; };
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
# Machine for processing single quoted strings.
|
# Machine for processing single quoted strings.
|
||||||
string_squote := |*
|
string_squote := |*
|
||||||
^squote+ => {
|
^squote+ => {
|
||||||
liboga_xml_lexer_callback(self, "on_string", encoding, ts, te);
|
liboga_xml_lexer_callback(self, "on_string", encoding, ts, te);
|
||||||
};
|
};
|
||||||
|
|
||||||
squote => { fret; };
|
squote => { fret; };
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
# DOCTYPES
|
# DOCTYPES
|
||||||
|
@ -128,33 +128,33 @@ VALUE oga_xml_lexer_advance(VALUE self)
|
||||||
doctype_start = '<!DOCTYPE'i whitespace+;
|
doctype_start = '<!DOCTYPE'i whitespace+;
|
||||||
|
|
||||||
action start_doctype {
|
action start_doctype {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_start_doctype");
|
liboga_xml_lexer_callback_simple(self, "on_start_doctype");
|
||||||
fcall doctype;
|
fcall doctype;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Machine for processing doctypes. Doctype values such as the public
|
# Machine for processing doctypes. Doctype values such as the public
|
||||||
# and system IDs are treated as T_STRING tokens.
|
# and system IDs are treated as T_STRING tokens.
|
||||||
doctype := |*
|
doctype := |*
|
||||||
'PUBLIC' | 'SYSTEM' => {
|
'PUBLIC' | 'SYSTEM' => {
|
||||||
liboga_xml_lexer_callback(self, "on_doctype_type", encoding, ts, te);
|
liboga_xml_lexer_callback(self, "on_doctype_type", encoding, ts, te);
|
||||||
};
|
};
|
||||||
|
|
||||||
# Lex the public/system IDs as regular strings.
|
# Lex the public/system IDs as regular strings.
|
||||||
dquote => { fcall string_dquote; };
|
dquote => { fcall string_dquote; };
|
||||||
squote => { fcall string_squote; };
|
squote => { fcall string_squote; };
|
||||||
|
|
||||||
# Whitespace inside doctypes is ignored since there's no point in
|
# Whitespace inside doctypes is ignored since there's no point in
|
||||||
# including it.
|
# including it.
|
||||||
whitespace;
|
whitespace;
|
||||||
|
|
||||||
identifier => {
|
identifier => {
|
||||||
liboga_xml_lexer_callback(self, "on_doctype_name", encoding, ts, te);
|
liboga_xml_lexer_callback(self, "on_doctype_name", encoding, ts, te);
|
||||||
};
|
};
|
||||||
|
|
||||||
'>' => {
|
'>' => {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_doctype_end");
|
liboga_xml_lexer_callback_simple(self, "on_doctype_end");
|
||||||
fret;
|
fret;
|
||||||
};
|
};
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
# CDATA
|
# CDATA
|
||||||
|
@ -171,18 +171,18 @@ VALUE oga_xml_lexer_advance(VALUE self)
|
||||||
cdata_end = ']]>';
|
cdata_end = ']]>';
|
||||||
|
|
||||||
action start_cdata {
|
action start_cdata {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_cdata_start");
|
liboga_xml_lexer_callback_simple(self, "on_cdata_start");
|
||||||
fcall cdata;
|
fcall cdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Machine that for processing the contents of CDATA tags. Everything
|
# Machine that for processing the contents of CDATA tags. Everything
|
||||||
# inside a CDATA tag is treated as plain text.
|
# inside a CDATA tag is treated as plain text.
|
||||||
cdata := |*
|
cdata := |*
|
||||||
any* cdata_end => {
|
any* cdata_end => {
|
||||||
liboga_xml_lexer_callback(self, "on_text", encoding, ts, te - 3);
|
liboga_xml_lexer_callback(self, "on_text", encoding, ts, te - 3);
|
||||||
liboga_xml_lexer_callback_simple(self, "on_cdata_end");
|
liboga_xml_lexer_callback_simple(self, "on_cdata_end");
|
||||||
fret;
|
fret;
|
||||||
};
|
};
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
# Comments
|
# Comments
|
||||||
|
@ -200,18 +200,18 @@ VALUE oga_xml_lexer_advance(VALUE self)
|
||||||
comment_end = '-->';
|
comment_end = '-->';
|
||||||
|
|
||||||
action start_comment {
|
action start_comment {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_comment_start");
|
liboga_xml_lexer_callback_simple(self, "on_comment_start");
|
||||||
fcall comment;
|
fcall comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Machine used for processing the contents of a comment. Everything
|
# Machine used for processing the contents of a comment. Everything
|
||||||
# inside a comment is treated as plain text (similar to CDATA tags).
|
# inside a comment is treated as plain text (similar to CDATA tags).
|
||||||
comment := |*
|
comment := |*
|
||||||
any* comment_end => {
|
any* comment_end => {
|
||||||
liboga_xml_lexer_callback(self, "on_text", encoding, ts, te - 3);
|
liboga_xml_lexer_callback(self, "on_text", encoding, ts, te - 3);
|
||||||
liboga_xml_lexer_callback_simple(self, "on_comment_end");
|
liboga_xml_lexer_callback_simple(self, "on_comment_end");
|
||||||
fret;
|
fret;
|
||||||
};
|
};
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
# XML declaration tags
|
# XML declaration tags
|
||||||
|
@ -222,26 +222,26 @@ VALUE oga_xml_lexer_advance(VALUE self)
|
||||||
xml_decl_end = '?>';
|
xml_decl_end = '?>';
|
||||||
|
|
||||||
action start_xml_decl {
|
action start_xml_decl {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_xml_decl_start");
|
liboga_xml_lexer_callback_simple(self, "on_xml_decl_start");
|
||||||
fcall xml_decl;
|
fcall xml_decl;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Machine that processes the contents of an XML declaration tag.
|
# Machine that processes the contents of an XML declaration tag.
|
||||||
xml_decl := |*
|
xml_decl := |*
|
||||||
xml_decl_end => {
|
xml_decl_end => {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_xml_decl_end");
|
liboga_xml_lexer_callback_simple(self, "on_xml_decl_end");
|
||||||
fret;
|
fret;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Attributes and their values (e.g. version="1.0").
|
# Attributes and their values (e.g. version="1.0").
|
||||||
identifier => {
|
identifier => {
|
||||||
liboga_xml_lexer_callback(self, "on_attribute", encoding, ts, te);
|
liboga_xml_lexer_callback(self, "on_attribute", encoding, ts, te);
|
||||||
};
|
};
|
||||||
|
|
||||||
dquote => { fcall string_dquote; };
|
dquote => { fcall string_dquote; };
|
||||||
squote => { fcall string_squote; };
|
squote => { fcall string_squote; };
|
||||||
|
|
||||||
any;
|
any;
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
# Elements
|
# Elements
|
||||||
|
@ -253,9 +253,9 @@ VALUE oga_xml_lexer_advance(VALUE self)
|
||||||
# namespace (if any). Remaining work is delegated to a dedicated
|
# namespace (if any). Remaining work is delegated to a dedicated
|
||||||
# machine.
|
# machine.
|
||||||
action start_element {
|
action start_element {
|
||||||
liboga_xml_lexer_callback(self, "on_element_start", encoding, ts + 1, te);
|
liboga_xml_lexer_callback(self, "on_element_start", encoding, ts + 1, te);
|
||||||
|
|
||||||
fcall element_head;
|
fcall element_head;
|
||||||
}
|
}
|
||||||
|
|
||||||
element_start = '<' identifier;
|
element_start = '<' identifier;
|
||||||
|
@ -267,62 +267,62 @@ VALUE oga_xml_lexer_advance(VALUE self)
|
||||||
# For example, in `<p foo="bar">` the element head is ` foo="bar"`.
|
# For example, in `<p foo="bar">` the element head is ` foo="bar"`.
|
||||||
#
|
#
|
||||||
element_head := |*
|
element_head := |*
|
||||||
whitespace | '=';
|
whitespace | '=';
|
||||||
|
|
||||||
newline => {
|
newline => {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_newline");
|
liboga_xml_lexer_callback_simple(self, "on_newline");
|
||||||
};
|
};
|
||||||
|
|
||||||
# Attribute names.
|
# Attribute names.
|
||||||
identifier => {
|
identifier => {
|
||||||
liboga_xml_lexer_callback(self, "on_attribute", encoding, ts, te);
|
liboga_xml_lexer_callback(self, "on_attribute", encoding, ts, te);
|
||||||
};
|
};
|
||||||
|
|
||||||
# Attribute values.
|
# Attribute values.
|
||||||
dquote => { fcall string_dquote; };
|
dquote => { fcall string_dquote; };
|
||||||
squote => { fcall string_squote; };
|
squote => { fcall string_squote; };
|
||||||
|
|
||||||
# The closing character of the open tag.
|
# The closing character of the open tag.
|
||||||
('>' | '/') => {
|
('>' | '/') => {
|
||||||
fhold;
|
fhold;
|
||||||
fret;
|
fret;
|
||||||
};
|
};
|
||||||
*|;
|
*|;
|
||||||
|
|
||||||
main := |*
|
main := |*
|
||||||
element_start => start_element;
|
element_start => start_element;
|
||||||
doctype_start => start_doctype;
|
doctype_start => start_doctype;
|
||||||
cdata_start => start_cdata;
|
cdata_start => start_cdata;
|
||||||
comment_start => start_comment;
|
comment_start => start_comment;
|
||||||
xml_decl_start => start_xml_decl;
|
xml_decl_start => start_xml_decl;
|
||||||
|
|
||||||
# Enter the body of the tag. If HTML mode is enabled and the current
|
# Enter the body of the tag. If HTML mode is enabled and the current
|
||||||
# element is a void element we'll close it and bail out.
|
# element is a void element we'll close it and bail out.
|
||||||
'>' => {
|
'>' => {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_element_open_end");
|
liboga_xml_lexer_callback_simple(self, "on_element_open_end");
|
||||||
};
|
};
|
||||||
|
|
||||||
# Regular closing tags.
|
# Regular closing tags.
|
||||||
'</' identifier '>' => {
|
'</' identifier '>' => {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_element_end");
|
liboga_xml_lexer_callback_simple(self, "on_element_end");
|
||||||
};
|
};
|
||||||
|
|
||||||
# Self closing elements that are not handled by the HTML mode.
|
# Self closing elements that are not handled by the HTML mode.
|
||||||
'/>' => {
|
'/>' => {
|
||||||
liboga_xml_lexer_callback_simple(self, "on_element_end");
|
liboga_xml_lexer_callback_simple(self, "on_element_end");
|
||||||
};
|
};
|
||||||
|
|
||||||
# Note that this rule should be declared at the very bottom as it
|
# Note that this rule should be declared at the very bottom as it
|
||||||
# will otherwise take precedence over the other rules.
|
# will otherwise take precedence over the other rules.
|
||||||
^('<' | '>')+ => {
|
^('<' | '>')+ => {
|
||||||
liboga_xml_lexer_callback(self, "on_text", encoding, ts, te);
|
liboga_xml_lexer_callback(self, "on_text", encoding, ts, te);
|
||||||
};
|
};
|
||||||
*|;
|
*|;
|
||||||
}%%
|
}%%
|
||||||
|
|
||||||
void Init_liboga_xml_lexer()
|
void Init_liboga_xml_lexer()
|
||||||
{
|
{
|
||||||
oga_cLexer = rb_define_class_under(oga_mXML, "Lexer", rb_cObject);
|
oga_cLexer = rb_define_class_under(oga_mXML, "Lexer", rb_cObject);
|
||||||
|
|
||||||
rb_define_method(oga_cLexer, "advance_native", oga_xml_lexer_advance, 0);
|
rb_define_method(oga_cLexer, "advance_native", oga_xml_lexer_advance, 0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue