Escape quotes in string literals
This commit is contained in:
parent
356b4d4eea
commit
0c5f39e416
@ -76,9 +76,14 @@
|
||||
return new PureToken(TokenKind.NumberLiteral, s, null, Window.Position); // TODO: actually parse number (here or in the lexer?)
|
||||
}
|
||||
|
||||
private string EscapeStringLiteral(string s)
|
||||
{
|
||||
return s.Replace("'", "''");
|
||||
}
|
||||
|
||||
public PureToken CreateStringLiteral(string s)
|
||||
{
|
||||
return new PureToken(TokenKind.StringLiteral, "'" + s + "'", s, Window.Position);
|
||||
return new PureToken(TokenKind.StringLiteral, "'" + EscapeStringLiteral(s) + "'", s, Window.Position);
|
||||
}
|
||||
|
||||
public PureToken CreateDoubleQuotedStringLiteral(string s)
|
||||
|
@ -347,9 +347,14 @@ namespace Parser
|
||||
}
|
||||
}
|
||||
|
||||
nodes.Add(ParseExpression());
|
||||
var expression = ParseExpression();
|
||||
if (expression != null)
|
||||
{
|
||||
nodes.Add(expression);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return Factory.ArrayElementList(nodes);
|
||||
}
|
||||
|
||||
@ -699,9 +704,20 @@ namespace Parser
|
||||
}
|
||||
|
||||
var forAssignment = (AssignmentExpressionNode) expression;
|
||||
var commas = new List<TokenNode>();
|
||||
while (CurrentToken.Kind == TokenKind.Comma
|
||||
|| CurrentToken.Kind == TokenKind.Semicolon)
|
||||
{
|
||||
commas.Add(Factory.Token(EatToken()));
|
||||
}
|
||||
if (commas.Count == 0)
|
||||
{
|
||||
commas = null;
|
||||
}
|
||||
|
||||
var body = ParseStatements();
|
||||
var endKeyword = Factory.Token(EatIdentifier("end"));
|
||||
return Factory.ForStatement(forKeyword, forAssignment, body, endKeyword);
|
||||
return Factory.ForStatement(forKeyword, forAssignment, body, endKeyword, commas);
|
||||
}
|
||||
|
||||
public StatementNode ParseStatementCore()
|
||||
|
@ -489,21 +489,28 @@ namespace Parser
|
||||
TokenNode forKeyword,
|
||||
AssignmentExpressionNode forAssignment,
|
||||
StatementListNode body,
|
||||
TokenNode endKeyword)
|
||||
TokenNode endKeyword,
|
||||
List<TokenNode> optionalCommasAfterAssignment)
|
||||
{
|
||||
var children = new List<SyntaxNode>
|
||||
{
|
||||
forKeyword,
|
||||
forAssignment,
|
||||
body,
|
||||
endKeyword
|
||||
};
|
||||
if (optionalCommasAfterAssignment != null)
|
||||
{
|
||||
children.AddRange(optionalCommasAfterAssignment);
|
||||
}
|
||||
|
||||
children.Add(body);
|
||||
children.Add(endKeyword);
|
||||
var result = new ForStatementNode(
|
||||
children,
|
||||
forKeyword,
|
||||
forAssignment,
|
||||
body,
|
||||
endKeyword);
|
||||
endKeyword,
|
||||
optionalCommasAfterAssignment);
|
||||
SetParent(result);
|
||||
return result;
|
||||
}
|
||||
|
@ -545,6 +545,7 @@ namespace Parser
|
||||
{
|
||||
public TokenNode ForKeyword { get; }
|
||||
public AssignmentExpressionNode ForAssignment { get; }
|
||||
public List<TokenNode> OptionalCommasAfterAssignment { get; }
|
||||
public StatementListNode Body { get; }
|
||||
public TokenNode EndKeyword { get; }
|
||||
|
||||
@ -553,12 +554,15 @@ namespace Parser
|
||||
TokenNode forKeyword,
|
||||
AssignmentExpressionNode forAssignment,
|
||||
StatementListNode body,
|
||||
TokenNode endKeyword) : base(children)
|
||||
TokenNode endKeyword,
|
||||
List<TokenNode> optionalCommasAfterAssignment
|
||||
) : base(children)
|
||||
{
|
||||
ForKeyword = forKeyword;
|
||||
ForAssignment = forAssignment;
|
||||
Body = body;
|
||||
EndKeyword = endKeyword;
|
||||
OptionalCommasAfterAssignment = optionalCommasAfterAssignment;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user