Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
10990503
Commit
10990503
authored
Dec 29, 2020
by
Seeker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Treat tabs as 8 spaces in squiggly heredocs
parent
4683a196
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
37 deletions
+56
-37
include/mruby/compile.h
include/mruby/compile.h
+0
-1
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
+28
-18
mrbgems/mruby-compiler/core/y.tab.c
mrbgems/mruby-compiler/core/y.tab.c
+28
-18
No files found.
include/mruby/compile.h
View file @
10990503
...
...
@@ -100,7 +100,6 @@ enum mrb_string_type {
struct
mrb_parser_heredoc_info
{
mrb_bool
allow_indent
:
1
;
mrb_bool
remove_indent
:
1
;
char
indent_char
;
size_t
indent
;
mrb_ast_node
*
indented
;
mrb_bool
line_head
:
1
;
...
...
mrbgems/mruby-compiler/core/parse.y
View file @
10990503
...
...
@@ -4664,16 +4664,29 @@ parse_string(parser_state *p)
if (hinf->remove_indent && hinf->indent > 0) {
node *tmp = hinf->indented;
while (tmp) {
node *n = tmp->car;
size_t indent = (size_t)n->car;
if (indent > hinf->indent)
indent = hinf->indent;
node *pair = tmp->car;
const char *str = (char*)pair->car;
size_t len = (size_t)pair->cdr;
size_t indent = 0;
size_t offset = 0;
for (size_t i = 0; i < len; i++) {
size_t size;
if (str[i] == '\n')
break;
else if (str[i] == '\t')
size = 8;
else if (ISSPACE(str[i]))
size = 1;
else
break;
if (indent + size > hinf->indent)
break;
indent += size;
++offset;
}
if (indent > 0) {
node *pair = n->cdr;
const char *str = (char*)pair->car;
size_t len = (size_t)pair->cdr;
pair->car = (node*)(str + indent);
pair->cdr = (node*)(len - indent);
pair->car = (node*)(str + offset);
pair->cdr = (node*)(len - offset);
}
tmp = tmp->cdr;
}
...
...
@@ -4699,19 +4712,17 @@ parse_string(parser_state *p)
node *nd = new_str(p, tok(p), toklen(p));
pylval.nd = nd;
if (head) {
hinf->indented = push(hinf->indented,
cons((node*)spaces, nd->cdr)
);
hinf->indented = push(hinf->indented,
nd->cdr
);
if ((hinf->indent == -1 || spaces < hinf->indent) && (!empty || !line_head))
hinf->indent = spaces;
}
return tHD_STRING_MID;
}
if (hinf && hinf->line_head && empty) {
if (ISSPACE(c)) {
if (hinf->indent_char == -1)
hinf->indent_char = c;
if (c == hinf->indent_char)
++spaces;
}
if (c == '\t')
spaces += 8;
else if (ISSPACE(c))
++spaces;
else
empty = FALSE;
}
...
...
@@ -4789,7 +4800,7 @@ parse_string(parser_state *p)
pylval.nd = nd;
if (hinf) {
if (head) {
hinf->indented = push(hinf->indented,
cons((node*)spaces, nd->cdr)
);
hinf->indented = push(hinf->indented,
nd->cdr
);
if (hinf->indent == -1 || spaces < hinf->indent)
hinf->indent = spaces;
}
...
...
@@ -5009,7 +5020,6 @@ heredoc_identifier(parser_state *p)
info->type = (string_type)type;
info->allow_indent = indent || squiggly;
info->remove_indent = squiggly;
info->indent_char = -1;
info->indent = -1;
info->indented = NULL;
info->line_head = TRUE;
...
...
mrbgems/mruby-compiler/core/y.tab.c
View file @
10990503
...
...
@@ -11049,16 +11049,29 @@ parse_string(parser_state *p)
if
(
hinf
->
remove_indent
&&
hinf
->
indent
>
0
)
{
node
*
tmp
=
hinf
->
indented
;
while
(
tmp
)
{
node *n = tmp->car;
size_t indent = (size_t)n->car;
if (indent > hinf->indent)
indent = hinf->indent;
node
*
pair
=
tmp
->
car
;
const
char
*
str
=
(
char
*
)
pair
->
car
;
size_t
len
=
(
size_t
)
pair
->
cdr
;
size_t
indent
=
0
;
size_t
offset
=
0
;
for
(
size_t
i
=
0
;
i
<
len
;
i
++
)
{
size_t
size
;
if
(
str
[
i
]
==
'\n'
)
break
;
else
if
(
str
[
i
]
==
'\t'
)
size
=
8
;
else
if
(
ISSPACE
(
str
[
i
]))
size
=
1
;
else
break
;
if
(
indent
+
size
>
hinf
->
indent
)
break
;
indent
+=
size
;
++
offset
;
}
if
(
indent
>
0
)
{
node *pair = n->cdr;
const char *str = (char*)pair->car;
size_t len = (size_t)pair->cdr;
pair->car = (node*)(str + indent);
pair->cdr = (node*)(len - indent);
pair
->
car
=
(
node
*
)(
str
+
offset
);
pair
->
cdr
=
(
node
*
)(
len
-
offset
);
}
tmp
=
tmp
->
cdr
;
}
...
...
@@ -11084,19 +11097,17 @@ parse_string(parser_state *p)
node
*
nd
=
new_str
(
p
,
tok
(
p
),
toklen
(
p
));
pylval
.
nd
=
nd
;
if
(
head
)
{
hinf->indented = push(hinf->indented,
cons((node*)spaces, nd->cdr)
);
hinf
->
indented
=
push
(
hinf
->
indented
,
nd
->
cdr
);
if
((
hinf
->
indent
==
-
1
||
spaces
<
hinf
->
indent
)
&&
(
!
empty
||
!
line_head
))
hinf
->
indent
=
spaces
;
}
return
tHD_STRING_MID
;
}
if
(
hinf
&&
hinf
->
line_head
&&
empty
)
{
if (ISSPACE(c)) {
if (hinf->indent_char == -1)
hinf->indent_char = c;
if (c == hinf->indent_char)
++spaces;
}
if
(
c
==
'\t'
)
spaces
+=
8
;
else
if
(
ISSPACE
(
c
))
++
spaces
;
else
empty
=
FALSE
;
}
...
...
@@ -11174,7 +11185,7 @@ parse_string(parser_state *p)
pylval
.
nd
=
nd
;
if
(
hinf
)
{
if
(
head
)
{
hinf->indented = push(hinf->indented,
cons((node*)spaces, nd->cdr)
);
hinf
->
indented
=
push
(
hinf
->
indented
,
nd
->
cdr
);
if
(
hinf
->
indent
==
-
1
||
spaces
<
hinf
->
indent
)
hinf
->
indent
=
spaces
;
}
...
...
@@ -11394,7 +11405,6 @@ heredoc_identifier(parser_state *p)
info
->
type
=
(
string_type
)
type
;
info
->
allow_indent
=
indent
||
squiggly
;
info
->
remove_indent
=
squiggly
;
info->indent_char = -1;
info
->
indent
=
-
1
;
info
->
indented
=
NULL
;
info
->
line_head
=
TRUE
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment