Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Issue 373 #391

Merged
merged 7 commits into from
May 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/kernel/bootstrap/Behavior.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
++++ obsolete file
# ++++ obsolete file
class Behavior

end
14 changes: 7 additions & 7 deletions src/kernel/bootstrap/FileStat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ def file?

def ftype
case @_st_mode & S_IFMT
when S_IFBLK : 'blockSpecial'
when S_IFCHR : 'characterSpecial'
when S_IFDIR : 'directory'
when S_IFIFO : 'fifo'
when S_IFLNK : 'link'
when S_IFREG : 'file'
when S_IFSOCK : 'socket'
when S_IFBLK then 'blockSpecial'
when S_IFCHR then 'characterSpecial'
when S_IFDIR then 'directory'
when S_IFIFO then 'fifo'
when S_IFLNK then 'link'
when S_IFREG then 'file'
when S_IFSOCK then 'socket'
else 'unknown'
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/bootstrap/Hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def default_proc
end

def default_proc=(value)
raise (TypeError, "wrong default_proc type #{value.class} (expected Proc)") if !value.kind_of?(Proc) and !value.kind_of?(ExecBlock)
raise(TypeError, "wrong default_proc type #{value.class} (expected Proc)") if !value.kind_of?(Proc) and !value.kind_of?(ExecBlock)
@_st_defaultProc = value
@_st_default = nil
end
Expand Down
16 changes: 8 additions & 8 deletions src/kernel/common/ctype.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ def toprint
"\\#"
elsif isctrl
case self
when ?\n: "\\n"
when ?\t: "\\t"
when ?\a: "\\a"
when ?\v: "\\v"
when ?\f: "\\f"
when ?\r: "\\r"
when ?\e: "\\e"
when ?\b: "\\b"
when ?\n then "\\n"
when ?\t then "\\t"
when ?\a then "\\a"
when ?\v then "\\v"
when ?\f then "\\f"
when ?\r then "\\r"
when ?\e then "\\e"
when ?\b then "\\b"
end
elsif self < 32 || self > 126
str = "\\000"
Expand Down
57 changes: 37 additions & 20 deletions src/kernel/parser/grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@

#include "rubygrammar.h"

#define IS_BEG() (lex_state == EXPR_BEG || lex_state == EXPR_MID || lex_state == EXPR_VALUE || lex_state == EXPR_CLASS)
#define IS_END() (lex_state == EXPR_END || lex_state == EXPR_ENDARG || lex_state == EXPR_ENDFN)
#define ISASCII(c) isascii((int)(unsigned char)(c))
#define ISSPACE(c) (ISASCII(c) && isspace((int)(unsigned char)(c)))
#define IS_LABEL_POSSIBLE() ((lex_state == EXPR_BEG && !cmd_state) || IS_ARG(lex_state))
#define IS_SPCARG(c) (IS_ARG(ps->lex_state) && space_seen && !ISSPACE(c))


#ifndef isnumber
#define isnumber isdigit
#endif
Expand Down Expand Up @@ -3234,7 +3242,7 @@ none : /* none */ { yTrace(vps, "none:"); $$ = ram_OOP_NIL; }


#undef ISALPHA
#undef ISSPACE
// #undef ISSPACE
#undef ISALNUM
#undef ISDIGIT
#undef ISXDIGIT
Expand Down Expand Up @@ -5087,9 +5095,12 @@ static int yylex(rb_parse_state* ps)

case '<':
c = nextc(ps);

if (c == '<' &&
IS_noneOf_EXPR_END_or_DOT_ENDARG_CLASS(lex_state) &&
(! IS_ARG(lex_state) || space_seen)) {
lex_state != EXPR_DOT &&
lex_state != EXPR_CLASS &&
!IS_END() &&
(!IS_ARG(lex_state) || space_seen)) {
int token = heredoc_identifier(ps);
if (token) return token;
}
Expand Down Expand Up @@ -5176,7 +5187,7 @@ static int yylex(rb_parse_state* ps)
return tSTRING_BEG;

case '?':
if (IS_EXPR_END_or_ENDARG(lex_state)) {
if (IS_END()) {
SET_lexState( EXPR_BEG);
*ps->lexvalH = OOP_OF_SMALL_LONG_( ps->tokenOffset());
return '?';
Expand Down Expand Up @@ -5576,7 +5587,12 @@ static int yylex(rb_parse_state* ps)
// can trigger other grammar actions such as closing a non-parenthesized
// list of args for a method call. doing the POP here can result
// in POP re-ordering that disagrees with the grammar.
SET_lexState( EXPR_END);
if (c == ')') {
SET_lexState(EXPR_ENDFN);
} else {
SET_lexState(EXPR_ENDARG);
}

*ps->lexvalH = OOP_OF_SMALL_LONG_( ps->tokenOffset()); // srcOffsetSi
return c;

Expand All @@ -5593,8 +5609,7 @@ static int yylex(rb_parse_state* ps)
*ps->lexvalH = OOP_OF_SMALL_LONG_( ps->tokenOffset());
return tCOLON2;
}
if (IS_EXPR_END_or_ENDARG(lex_state)
|| isSpace(c, ps)) {
if (IS_END() || isSpace(c, ps)) {
pushback(c, ps);
SET_lexState( EXPR_BEG);
*ps->lexvalH = OOP_OF_SMALL_LONG_( ps->tokenOffset());
Expand Down Expand Up @@ -5677,19 +5692,14 @@ static int yylex(rb_parse_state* ps)
return '~';

case '(':
ps->command_start = TRUE;
if (IS_EXPR_BEG_or_MID(lex_state)) {
if (IS_BEG()) {
c = tLPAREN;
}
else if (space_seen) {
if (lex_state == EXPR_CMDARG) {
c = tLPAREN_ARG;
}
else if (lex_state == EXPR_ARG) {
rb_warning(ps, "don't put space before argument parentheses");
c = '(';
}
else if (IS_SPCARG(-1)) {
c = tLPAREN_ARG;
}

// TODO: paren_nest++;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the issues with this todo pending? Do you have any code that doesn't parse because of this in particular?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignore me, Chrome didn't refresh the code for some reason..

COND_PUSH(ps, 0);
CMDARG_PUSH(ps, 0);
SET_lexState( EXPR_BEG);
Expand Down Expand Up @@ -5723,7 +5733,7 @@ static int yylex(rb_parse_state* ps)
return c;

case '{':
if (IS_ARG_or_END(lex_state))
if (IS_ARG_or_END(lex_state) || lex_state == EXPR_ENDFN)
c = '{'; /* block (primary) */
else if (lex_state == EXPR_ENDARG)
c = tLBRACE_ARG; /* block (expr) */
Expand Down Expand Up @@ -6057,10 +6067,11 @@ static int yylex(rb_parse_state* ps)
needsNameToken = TRUE;
}
}
if ((lex_state == EXPR_BEG && !cmd_state) || IS_ARG(lex_state)) {

if (IS_LABEL_POSSIBLE()) {
int p_c = *(ps->lex_p); // actual peek
if (ch_equals(':', p_c) && !(ps->lex_p + 1 < ps->lex_pend && (ps->lex_p)[1] == ':')) {
lex_state = EXPR_BEG;
SET_lexState(EXPR_BEG);
nextc(ps);
NODE* symqO = rb_parser_sym( tok(ps) , ps);
*ps->lexvalH = RpNameToken::s( ps, symqO );
Expand All @@ -6075,6 +6086,12 @@ static int yylex(rb_parse_state* ps)
int64 resWordOffset = ps->lineStartOffset + ps->tokStartDelta; // zero based
LexStateKind state = lex_state;
SET_lexState( kw->state);
if (state == EXPR_FNAME) {
NODE* symqO = rb_parser_sym( kw->name , ps);
*ps->lexvalH = RpNameToken::s( ps, symqO );

return kw->id[0];
}

omObjSType *srcOfs = OOP_OF_SMALL_LONG_(resWordOffset + 1); // one based
AstSymbolEType a_sym = kw->a_sym;
Expand Down
6 changes: 4 additions & 2 deletions src/kernel/parser/rubyparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ typedef enum {
EXPR_END = 2, /* newline significant, +/- is a operator. */
EXPR_ARG = 4, /* newline significant, +/- is a operator. */
EXPR_CMDARG = 8, /* newline significant, +/- is a operator. */
EXPR_ENDARG = 0x10, /* newline significant, +/- is a operator. */
EXPR_ENDARG = 0x10, /* newline significant, +/- is a operator, and unbound braces */
EXPR_MID = 0x20, /* newline significant, +/- is a operator. */
EXPR_FNAME = 0x40, /* ignore newline, no reserved words. */
EXPR_DOT = 0x80, /* right after `.' or `::', no reserved words. */
EXPR_CLASS = 0x100 /* immediate after `class', no here document. */
EXPR_CLASS = 0x100, /* immediate after `class', no here document. */
EXPR_VALUE = 0x200, /* like EXPR_BEG but label is disallowed */
EXPR_ENDFN = 0x400 /* newline significant, +/- is a operator, and unbound braces */
} LexStateKind;

class rb_parse_state ;
Expand Down
1 change: 1 addition & 0 deletions src/test/vmunit.conf
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ CaseTest.rb
# testEvalLineNumber.rb
testMassign.rb
# tests that require simple.rb
InvokeTest.rb
ArgsTest.rb
ArrayTest.rb
HashTest.rb
Expand Down
1 change: 0 additions & 1 deletion src/test/vmunit2.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# This is a list of tests that must be run through invoking
# $MAGLEV_HOME/bin/maglev-ruby (or, cannot be invoked from Smalltalk).

InvokeTest.rb
DigestTest.rb
Trac592.rb
Trac930.rb
Expand Down