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
e9e4c133
Commit
e9e4c133
authored
May 04, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2161 from nobu/embedded_document
Embedded document
parents
07b9f2de
8b13efc2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
14 deletions
+39
-14
src/parse.y
src/parse.y
+34
-13
test/t/syntax.rb
test/t/syntax.rb
+5
-1
No files found.
src/parse.y
View file @
e9e4c133
...
...
@@ -3417,15 +3417,15 @@ skip(parser_state *p, char term)
}
}
static
mrb_bool
peek
_n(parser_state *p, int c
, int n)
static
int
peek
c_n(parser_state *p
, int n)
{
node *list = 0;
int c0;
do {
c0 = nextc(p);
if (c0 < 0) return
FALSE
;
if (c0 < 0) return
c0
;
list = push(list, (node*)(intptr_t)c0);
} while(n--);
if (p->pb) {
...
...
@@ -3434,8 +3434,13 @@ peek_n(parser_state *p, int c, int n)
else {
p->pb = list;
}
if (c0 == c) return TRUE;
return FALSE;
return c0;
}
static mrb_bool
peek_n(parser_state *p, int c, int n)
{
return peekc_n(p, n) == c && c >= 0;
}
#define peek(p,c) peek_n((p), (c), 0)
...
...
@@ -3454,7 +3459,7 @@ peeks(parser_state *p, const char *s)
}
else
#endif
if (p->s && p->s + len
>
= p->send) {
if (p->s && p->s + len
<
= p->send) {
if (memcmp(p->s, s, len) == 0) return TRUE;
}
return FALSE;
...
...
@@ -3470,6 +3475,10 @@ skips(parser_state *p, const char *s)
for (;;) {
c = nextc(p);
if (c < 0) return c;
if (c == '\n') {
p->lineno++;
p->column = 0;
}
if (c == *s) break;
}
s++;
...
...
@@ -3477,7 +3486,10 @@ skips(parser_state *p, const char *s)
int len = strlen(s);
while (len--) {
nextc(p);
if (nextc(p) == '\n') {
p->lineno++;
p->column = 0;
}
}
return TRUE;
}
...
...
@@ -4189,14 +4201,23 @@ parser_yylex(parser_state *p)
case '=':
if (p->column == 1) {
if (peeks(p, "begin ") || peeks(p, "begin\n")) {
if (skips(p, "\n=end ")) {
goto retry;
static const char begin[] = "begin";
static const char end[] = "\n=end";
if (peeks(p, begin)) {
c = peekc_n(p, sizeof(begin)-1);
if (c < 0 || isspace(c)) {
do {
if (!skips(p, end)) {
yyerror(p, "embedded document meets end of file");
return 0;
}
if (skips(p, "\n=end\n")) {
c = nextc(p);
} while (!(c < 0 || isspace(c)));
if (c != '\n') skip(p, '\n');
p->lineno++;
p->column = 0;
goto retry;
}
goto retry;
}
}
if (p->lstate == EXPR_FNAME || p->lstate == EXPR_DOT) {
...
...
test/t/syntax.rb
View file @
e9e4c133
...
...
@@ -307,5 +307,9 @@ this is a comment that has =end with spaces after it
=begin this is a comment
this is a comment that has extra after =begin and =end with spaces after it
=end
true
line
=
__LINE__
=begin this is a comment
this is a comment that has extra after =begin and =end with tabs after it
=end
xxxxxxxxxxxxxxxxxxxxxxxxxx
assert_equal
(
line
+
4
,
__LINE__
)
end
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