[xruby commit] r2328 - in trunk/src/com/xruby/compiler: . codedom parser

1 view
Skip to first unread message

codesite...@google.com

unread,
Jul 1, 2008, 11:01:04 PM7/1/08
to xruby-...@googlegroups.com
Author: xue.yong.zhi
Date: Tue Jul 1 20:00:35 2008
New Revision: 2328

Modified:
trunk/src/com/xruby/compiler/RubyCompilerTest.java
trunk/src/com/xruby/compiler/codedom/AsciiValueExpression.java
trunk/src/com/xruby/compiler/parser/ruby.g

Log:
fix another parse error (?\x07) found when parsing rbyaml


Modified: trunk/src/com/xruby/compiler/RubyCompilerTest.java
==============================================================================
--- trunk/src/com/xruby/compiler/RubyCompilerTest.java (original)
+++ trunk/src/com/xruby/compiler/RubyCompilerTest.java Tue Jul 1
20:00:35 2008
@@ -227,8 +227,8 @@
}

public void test_ascii_value() {
- String[] program_texts = { "?a", "?A", "?\\n", "?\\r", "?\\C-a", "?\\M-a", "?\\M-\\C-a"};
- int[] results = {97, 65, 10, 13, 1, 225, 129};
+ String[] program_texts = {"?\\x0A", "?\\x07", "?\\x77", "?a", "?A", "?\\n", "?\\r", "?\\C-a", "?\\M-a", "?\\M-\\C-a"};
+ int[] results = {10, 7, 119, 97, 65, 10, 13, 1, 225, 129};

compile_run_and_compare_result(program_texts, results);
}

Modified: trunk/src/com/xruby/compiler/codedom/AsciiValueExpression.java
==============================================================================
--- trunk/src/com/xruby/compiler/codedom/AsciiValueExpression.java (original)
+++ trunk/src/com/xruby/compiler/codedom/AsciiValueExpression.java Tue
Jul 1 20:00:35 2008
@@ -1,4 +1,4 @@
-/**
+/**
* Copyright 2005-2007 Xue Yong Zhi
* Distributed under the BSD License
*/
@@ -7,7 +7,7 @@

public class AsciiValueExpression extends Expression {
private int value_;
-
+
public AsciiValueExpression(String value) {

if (value.startsWith("?\\M-\\C-")) {
@@ -27,11 +27,14 @@
case 'r':
value_ = '\r';
return;
+ case 'x':
+ value_ = Integer.valueOf(value.substring(3), 16);
+ return;
default:
//TODO more escped value
value_ = (int)value.charAt(2);
return;
-
+
}
} else {
value_ = (int)value.charAt(1);

Modified: trunk/src/com/xruby/compiler/parser/ruby.g
==============================================================================
--- trunk/src/com/xruby/compiler/parser/ruby.g (original)
+++ trunk/src/com/xruby/compiler/parser/ruby.g Tue Jul 1 20:00:35 2008
@@ -2,7 +2,7 @@
package com.xruby.compiler.parser;
}

-/**
+/**
* Copyright 2005-2007 Xue Yong Zhi
* Distributed under the BSD License
*/
@@ -152,7 +152,7 @@
mrhs
{is_parallel_assignment = true;}
)
- {
+ {
if (is_parallel_assignment && !has_extra_comma) {
#statementWithoutModifier =
#(#[MULTIPLE_ASSIGN, "MULTIPLE_ASSIGN"], #statementWithoutModifier);
} else if (is_parallel_assignment && has_extra_comma) {
@@ -204,7 +204,7 @@

aliasStatement
: "alias"^ (options{greedy=true;}:LINE_BREAK!)?
- (GLOBAL_VARIABLE (LINE_BREAK!)? GLOBAL_VARIABLE
+ (GLOBAL_VARIABLE (LINE_BREAK!)? GLOBAL_VARIABLE
|undef_parameter (LINE_BREAK!)? undef_parameter
)
;
@@ -248,7 +248,7 @@
(IDENTIFIER (options{greedy=true;}:ASSIGN_WITH_NO_LEADING_SPACE)?
|FUNCTION (options{greedy=true;}:ASSIGN_WITH_NO_LEADING_SPACE)?
|CONSTANT (options{greedy=true;}:ASSIGN_WITH_NO_LEADING_SPACE)?
- |GLOBAL_VARIABLE
+ |GLOBAL_VARIABLE
|INSTANCE_VARIABLE
|CLASS_VARIABLE
|UNARY_PLUS_MINUS_METHOD_NAME
@@ -350,7 +350,7 @@
| EXCLUSIVE_RANGE^ (options{greedy=true;}:LINE_BREAK!)?
)
logicalOrExpression
- )*
+ )*
;

//||
@@ -608,7 +608,7 @@
protected
expression_substituation
: ( LCURLY_BLOCK! (compoundStatement)? RCURLY!
- | GLOBAL_VARIABLE
+ | GLOBAL_VARIABLE
| INSTANCE_VARIABLE
| CLASS_VARIABLE
)
@@ -651,7 +651,7 @@

numeric
: INTEGER
- | HEX
+ | HEX
| BINARY
| OCTAL
| FLOAT
@@ -675,8 +675,8 @@
;

primaryExpressionThatCanNotBeMethodName
- : INSTANCE_VARIABLE
- | GLOBAL_VARIABLE
+ : INSTANCE_VARIABLE
+ | GLOBAL_VARIABLE
| CLASS_VARIABLE
| predefinedValue
| numeric
@@ -687,10 +687,10 @@
| LPAREN_WITH_NO_LEADING_SPACE^ compoundStatement RPAREN!
| ifExpression
| unlessExpression
- | whileExpression
- | untilExpression
- | caseExpression
- | forExpression
+ | whileExpression
+ | untilExpression
+ | caseExpression
+ | forExpression
| exceptionHandlingExpression
| moduleDefinition
| classDefinition
@@ -699,7 +699,7 @@

primaryExpression
: primaryExpressionThatCanNotBeMethodName
- | primaryExpressionThatCanBeMethodName
+ | primaryExpressionThatCanBeMethodName
;

arrayReferenceArgument
@@ -823,13 +823,13 @@

/*
FIXME
-cname : tIDENTIFIER
+cname : tIDENTIFIER
| tCONSTANT
;

-cpath : tCOLON3 cname
- | cname
- | primary_value tCOLON2 cname
+cpath : tCOLON3 cname
+ | cname
+ | primary_value tCOLON2 cname
;
*/
className
@@ -838,7 +838,7 @@
;

methodDefinition
- : "def"^ {++is_in_method_defination;}
+ : "def"^ {++is_in_method_defination;}
(options{greedy=true;}:LINE_BREAK!)?
methodName {enterScope();}
methodDefinitionArgument
@@ -862,8 +862,8 @@
: ( operatorAsMethodname
| keywordAsMethodName
| (id:IDENTIFIER
- |function:FUNCTION
- |constant:CONSTANT
+ |function:FUNCTION
+ |constant:CONSTANT
)
(methodNameSupplement{is_singleton_method = true;}|ASSIGN_WITH_NO_LEADING_SPACE)?
| (LPAREN!|LPAREN_WITH_NO_LEADING_SPACE!)
@@ -1071,7 +1071,7 @@
//The following methods are to be implemented in the subclass.
//In fact they should be "abstract", but antlr refuses to generate
//abstract class. We can either insert "abstract" keyword manually
- //after the lexer is generated, or simply use assert() to prevent
+ //after the lexer is generated, or simply use assert() to prevent
//these function to run (so you have to overide them). I choosed
//the later approach.
protected boolean expectOperator(int k) throws CharStreamException
{assert(false);return false;}
@@ -1302,7 +1302,7 @@
_saveIndex=text.length();
matchNot(EOF_CHAR);
text.setLength(_saveIndex);
-
+
if (0 == delimiter_count)
{
$setType(DOUBLE_QUOTE_STRING);
@@ -1407,7 +1407,7 @@
_saveIndex=text.length();
matchNot(EOF_CHAR);
text.setLength(_saveIndex);
- $setType(type1);
+ $setType(type1);
}
else
{
@@ -1471,7 +1471,7 @@
)
;

-GLOBAL_VARIABLE
+GLOBAL_VARIABLE
: '$' '-' (IDENTIFIER_CONSTANT_AND_KEYWORD|'#')?
| '$' IDENTIFIER_CONSTANT_AND_KEYWORD
| '$' (options{greedy=true;}:'0'..'9')+
@@ -1502,7 +1502,7 @@
| '0'! ('x'!|'X'!) HEX_CONTENT {$setType(HEX);}
| '0' (
//Use semantic prediction to avoid 0.times
- {(LA(2)>='0')&&(LA(2)<='9')}? FLOAT_WITH_LEADING_DOT {$setType(FLOAT);}
+ {(LA(2)>='0')&&(LA(2)<='9')}? FLOAT_WITH_LEADING_DOT {$setType(FLOAT);}
|/*none*/
)
| NON_ZERO_DECIMAL (
@@ -1517,8 +1517,9 @@
| "..." {$setType(EXCLUSIVE_RANGE);}
| '?' (
{isAsciiValueTerminator(LA(2))}? (~('\\'|' '|'\n'|'\r')) {$setType(ASCII_VALUE);}
- |'\\' ~('C' | 'M') {$setType(ASCII_VALUE);}
+ |'\\' ~('C' | 'M' | 'x') {$setType(ASCII_VALUE);}
|('\\' ('C'|'M') '-')+ ('a'..'z' | '?') {$setType(ASCII_VALUE);}
+ |'\\' 'x' HEX_CONTENT {$setType(ASCII_VALUE);}
|{$setType(QUESTION);} //If it does not "look like"(not depend on
context!) integer, then it is QUESTION operator.
)
;

Reply all
Reply to author
Forward
0 new messages