private StringAstNode ParseString(AstNode?parent) { if (_scanner.GetToken() != SyntaxKind.StringLiteral) { return(null); } var node = new StringAstNode(_scanner.GetTokenOffset(), parent) { Value = _scanner.GetValue() }; return(Finalize(node)); }
private PropertyAstNode?ParseProperty(AstNode?parent, IDictionary <string, AstNode> seen) { var node = new PropertyAstNode(_scanner.GetTokenOffset(), parent); var key = ParseString(node); if (key == null) { if (_scanner.GetToken() == SyntaxKind.Unknown) { // Error property key must be double quoted var keyNode = new StringAstNode(_scanner.GetTokenOffset(), _scanner.GetTokenLength(), node) { Value = _scanner.GetValue() }; key = keyNode; ScanNext(); // Consume unknown } else { return(null); } } node.KeyNode = key; var isSeen = seen.ContainsKey(key.Value); if (isSeen) { // Error duplicate object key var seenNode = seen[key.Value]; if (seenNode is ObjectAstNode) { // Error duplicate object key at position } } else { seen[key.Value] = node; } if (_scanner.GetToken() == SyntaxKind.ColonToken) { node.ColonOffset = _scanner.GetTokenOffset(); ScanNext(); // Consume colon } else { // Error colon expected } var value = ParseValue(node); if (value == null) { // Error value expected return(null); } node.ValueNode = value; node.Length = value.Offset + value.Length - node.Offset; return(node); }