зеркало из https://github.com/github/ruby.git
Use user defined parameterizing rules
This commit is contained in:
Родитель
29aaf4abe6
Коммит
f9cf923af2
|
@ -51,6 +51,10 @@ def process(f, out, path, template)
|
|||
usercode f, out, path, template
|
||||
end
|
||||
|
||||
require_relative 'dsl'
|
||||
|
||||
RIPPER_CODE_PATTERN = %r</\*% *ripper(?:\[(.*?)\])?: *(.*?) *%\*/>
|
||||
|
||||
def prelude(f, out)
|
||||
@exprs = {}
|
||||
while line = f.gets
|
||||
|
@ -58,6 +62,9 @@ def prelude(f, out)
|
|||
when /\A%%/
|
||||
out << "%%\n"
|
||||
return
|
||||
when RIPPER_CODE_PATTERN # %rule actions may contain /*% ripper: ... %*/ DSL
|
||||
out << DSL.new($2, ($1 || "").split(",")).generate << "\n"
|
||||
next
|
||||
else
|
||||
if (/^enum lex_state_(?:bits|e) \{/ =~ line)..(/^\}/ =~ line)
|
||||
case line
|
||||
|
@ -74,12 +81,10 @@ def prelude(f, out)
|
|||
end
|
||||
end
|
||||
|
||||
require_relative "dsl"
|
||||
|
||||
def grammar(f, out)
|
||||
while line = f.gets
|
||||
case line
|
||||
when %r</\*% *ripper(?:\[(.*?)\])?: *(.*?) *%\*/>
|
||||
when RIPPER_CODE_PATTERN
|
||||
out << DSL.new($2, ($1 || "").split(",")).generate << "\n"
|
||||
when %r</\*%%%\*/>
|
||||
out << "#if 0\n"
|
||||
|
|
34
parse.y
34
parse.y
|
@ -2951,6 +2951,16 @@ rb_parser_ary_free(rb_parser_t *p, rb_parser_ary_t *ary)
|
|||
|
||||
%token tLAST_TOKEN
|
||||
|
||||
/*
|
||||
* parameterizing rules
|
||||
*/
|
||||
%rule words(begin, word_list): begin ' '+ word_list tSTRING_END
|
||||
{
|
||||
$$ = make_list($3, &@$);
|
||||
/*% ripper: array!($:3) %*/
|
||||
}
|
||||
;
|
||||
|
||||
%%
|
||||
program : {
|
||||
SET_LEX_STATE(EXPR_BEG);
|
||||
|
@ -6104,11 +6114,7 @@ regexp : tREGEXP_BEG regexp_contents tREGEXP_END
|
|||
}
|
||||
;
|
||||
|
||||
words : tWORDS_BEG ' '+ word_list tSTRING_END
|
||||
{
|
||||
$$ = make_list($3, &@$);
|
||||
/*% ripper: array!($:3) %*/
|
||||
}
|
||||
words : words(tWORDS_BEG, word_list) <node>
|
||||
;
|
||||
|
||||
word_list : /* none */
|
||||
|
@ -6132,11 +6138,7 @@ word : string_content
|
|||
}
|
||||
;
|
||||
|
||||
symbols : tSYMBOLS_BEG ' '+ symbol_list tSTRING_END
|
||||
{
|
||||
$$ = make_list($3, &@$);
|
||||
/*% ripper: array!($:3) %*/
|
||||
}
|
||||
symbols : words(tSYMBOLS_BEG, symbol_list) <node>
|
||||
;
|
||||
|
||||
symbol_list : /* none */
|
||||
|
@ -6151,18 +6153,10 @@ symbol_list : /* none */
|
|||
}
|
||||
;
|
||||
|
||||
qwords : tQWORDS_BEG ' '+ qword_list tSTRING_END
|
||||
{
|
||||
$$ = make_list($3, &@$);
|
||||
/*% ripper: array!($:3) %*/
|
||||
}
|
||||
qwords : words(tQWORDS_BEG, qword_list) <node>
|
||||
;
|
||||
|
||||
qsymbols : tQSYMBOLS_BEG ' '+ qsym_list tSTRING_END
|
||||
{
|
||||
$$ = make_list($3, &@$);
|
||||
/*% ripper: array!($:3) %*/
|
||||
}
|
||||
qsymbols : words(tQSYMBOLS_BEG, qsym_list) <node>
|
||||
;
|
||||
|
||||
qword_list : /* none */
|
||||
|
|
Загрузка…
Ссылка в новой задаче