Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
30926012
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
30926012
编写于
11月 12, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support unicode escapes in chars and strings
上级
ff624892
变更
7
展开全部
隐藏空白更改
内联
并排
Showing
7 changed file
with
310 addition
and
238 deletion
+310
-238
compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java
...ntend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java
+1
-1
compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java
...t/lang/resolve/constants/CompileTimeConstantResolver.java
+48
-17
compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java
.../lang/types/expressions/BasicExpressionTypingVisitor.java
+4
-7
compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex
compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex
+1
-1
compiler/frontend/src/org/jetbrains/jet/lexer/_JetLexer.java
compiler/frontend/src/org/jetbrains/jet/lexer/_JetLexer.java
+243
-212
compiler/testData/checkerWithErrorTypes/full/StringTemplates.jet
...r/testData/checkerWithErrorTypes/full/StringTemplates.jet
+1
-0
compiler/testData/checkerWithErrorTypes/quick/IncorrectCharacterLiterals.jet
...heckerWithErrorTypes/quick/IncorrectCharacterLiterals.jet
+12
-0
未找到文件。
compiler/frontend/src/org/jetbrains/jet/checkers/CheckerTestUtil.java
浏览文件 @
30926012
...
...
@@ -198,7 +198,7 @@ public class CheckerTestUtil {
opened
.
pop
();
}
assert
opened
.
isEmpty
()
:
"Stack is not empty
"
;
assert
opened
.
isEmpty
()
:
"Stack is not empty
: "
+
opened
;
}
else
{
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/constants/CompileTimeConstantResolver.java
浏览文件 @
30926012
...
...
@@ -165,29 +165,60 @@ public class CompileTimeConstantResolver {
return
error
;
}
// Strip the quotes
if
(
text
.
charAt
(
0
)
!=
'\''
||
text
.
charAt
(
text
.
length
()
-
1
)
!=
'\''
)
{
return
new
ErrorValue
(
"Incorre
t character constant
"
);
return
new
ErrorValue
(
"Incorre
ct character literal
"
);
}
text
=
text
.
substring
(
1
,
text
.
length
()
-
1
);
text
=
text
.
substring
(
1
,
text
.
length
()
-
1
);
// now there're no quotes
if
(
text
.
length
()
==
0
)
{
return
new
ErrorValue
(
"Empty character literal"
);
}
else
if
(
text
.
length
()
==
1
)
{
if
(
text
.
charAt
(
0
)
==
'\\'
)
{
return
new
ErrorValue
(
"Illegal escape: "
+
text
);
}
else
{
return
new
ErrorValue
(
"Empty character literal"
);
}
if
(
text
.
charAt
(
0
)
!=
'\\'
)
{
// No escape
if
(
text
.
length
()
==
1
)
{
return
new
CharValue
(
text
.
charAt
(
0
));
}
}
else
if
(
text
.
length
()
==
2
&&
text
.
charAt
(
0
)
==
'\\'
)
{
Character
escaped
=
translateEscape
(
text
.
charAt
(
1
));
if
(
escaped
==
null
)
{
return
new
ErrorValue
(
"Illegal escape: "
+
text
);
}
return
new
CharValue
(
escaped
);
}
else
{
return
new
ErrorValue
(
"Too many characters in character literal"
);
return
new
ErrorValue
(
"Too many characters in a character literal"
+
text
);
}
return
escapedStringToCharValue
(
text
);
}
@NotNull
public
static
CompileTimeConstant
<?>
escapedStringToCharValue
(
@NotNull
String
text
)
{
assert
text
.
length
()
>
0
&&
text
.
charAt
(
0
)
==
'\\'
:
"Only escaped sequences must be passed to this routine: "
+
text
;
// Escape
String
escape
=
text
.
substring
(
1
);
// strip the slash
switch
(
escape
.
length
())
{
case
0
:
// bare slash
return
illegalEscape
(
text
);
case
1
:
// one-char escape
Character
escaped
=
translateEscape
(
escape
.
charAt
(
0
));
if
(
escaped
==
null
)
{
return
illegalEscape
(
text
);
}
return
new
CharValue
(
escaped
);
case
5
:
// unicode escape
if
(
escape
.
charAt
(
0
)
==
'u'
)
{
try
{
Integer
intValue
=
Integer
.
valueOf
(
escape
.
substring
(
1
),
16
);
return
new
CharValue
((
char
)
intValue
.
intValue
());
}
catch
(
NumberFormatException
e
)
{
// Will be reported below
}
}
break
;
}
return
illegalEscape
(
text
);
}
private
static
ErrorValue
illegalEscape
(
String
text
)
{
return
new
ErrorValue
(
"Illegal escape: "
+
text
);
}
@Nullable
...
...
compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java
浏览文件 @
30926012
...
...
@@ -840,18 +840,15 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
@Override
public
void
visitEscapeStringTemplateEntry
(
JetEscapeStringTemplateEntry
entry
)
{
// TODO : Check escape
String
text
=
entry
.
getText
();
assert
text
.
length
()
==
2
&&
text
.
charAt
(
0
)
==
'\\'
;
char
escaped
=
text
.
charAt
(
1
);
C
haracter
character
=
CompileTimeConstantResolver
.
translateEscape
(
escaped
);
if
(
character
==
null
)
{
C
ompileTimeConstant
<?>
character
=
CompileTimeConstantResolver
.
escapedStringToCharValue
(
text
);
if
(
character
instanceof
ErrorValue
)
{
context
.
trace
.
report
(
ILLEGAL_ESCAPE_SEQUENCE
.
on
(
entry
));
value
[
0
]
=
CompileTimeConstantResolver
.
OUT_OF_RANGE
;
}
else
{
builder
.
append
(
character
);
builder
.
append
(
((
CharValue
)
character
).
getValue
()
);
}
}
});
...
...
@@ -866,7 +863,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
public
JetType
visitAnnotatedExpression
(
JetAnnotatedExpression
expression
,
ExpressionTypingContext
data
)
{
return
facade
.
getType
(
expression
.
getBaseExpression
(),
data
);
}
@Override
public
JetType
visitJetElement
(
JetElement
element
,
ExpressionTypingContext
context
)
{
context
.
trace
.
report
(
UNSUPPORTED
.
on
(
element
,
getClass
().
getCanonicalName
()));
...
...
compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex
浏览文件 @
30926012
...
...
@@ -92,7 +92,7 @@ HEX_SIGNIFICAND={HEX_INTEGER_LITERAL}|0[Xx]{HEX_DIGIT}*\.{HEX_DIGIT}+
CHARACTER_LITERAL
=
"'"
([^\\\
'\n]|{ESCAPE_SEQUENCE})*("'
"|
\\
)?
// TODO: introduce symbols (e.g. 'foo) as another way to write string literals
STRING_LITERAL=
\"
([^
\\\"\n
]|{ESCAPE_SEQUENCE})*(
\"
|
\\
)?
ESCAPE_SEQUENCE=
\\
[^
\n
]
ESCAPE_SEQUENCE=
\\
(u{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}{HEX_DIGIT}|[^
\n
])
// ANY_ESCAPE_SEQUENCE =
\\
[^]
THREE_QUO = (
\"\"\"
)
...
...
compiler/frontend/src/org/jetbrains/jet/lexer/_JetLexer.java
浏览文件 @
30926012
此差异已折叠。
点击以展开。
compiler/testData/checkerWithErrorTypes/full/StringTemplates.jet
浏览文件 @
30926012
...
...
@@ -18,4 +18,5 @@ fun demo() {
"foo${bar + map { "foo" }}sdfsdf"
"foo${bar + map {
"foo$sdf${ buzz{}}" }}sdfsdf"
"a<!ILLEGAL_ESCAPE_SEQUENCE!>\u<!> <!ILLEGAL_ESCAPE_SEQUENCE!>\u<!>0 <!ILLEGAL_ESCAPE_SEQUENCE!>\u<!>00 <!ILLEGAL_ESCAPE_SEQUENCE!>\u<!>000 \u0000 \u0AaA <!ILLEGAL_ESCAPE_SEQUENCE!>\u<!>0AAz.length( ) + \u0022b"
}
\ No newline at end of file
compiler/testData/checkerWithErrorTypes/quick/IncorrectCharacterLiterals.jet
浏览文件 @
30926012
...
...
@@ -23,4 +23,16 @@ fun test() {
<!ERROR_COMPILE_TIME_VALUE!>'\123'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\ra'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\000'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\000'<!>
'\u0000'
'\u000a'
'\u000A'
<!ERROR_COMPILE_TIME_VALUE!>'\u'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\u0'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\u00'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\u000'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\u000z'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\\u000'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\'<!>
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录