JsonParser.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using Jint.Native.Object;
  6. using Jint.Parser;
  7. using Jint.Parser.Ast;
  8. using Jint.Runtime;
  9. namespace Jint.Native.Json
  10. {
  11. public class JsonParser
  12. {
  13. private readonly Engine _engine;
  14. public JsonParser(Engine engine)
  15. {
  16. _engine = engine;
  17. }
  18. private Extra _extra;
  19. private int _index; // position in the stream
  20. private int _length; // length of the stream
  21. private int _lineNumber;
  22. private int _lineStart;
  23. private Location _location;
  24. private Token _lookahead;
  25. private string _source;
  26. private State _state;
  27. private static bool IsDecimalDigit(char ch)
  28. {
  29. return (ch >= '0' && ch <= '9');
  30. }
  31. private static bool IsHexDigit(char ch)
  32. {
  33. return
  34. ch >= '0' && ch <= '9' ||
  35. ch >= 'a' && ch <= 'f' ||
  36. ch >= 'A' && ch <= 'F'
  37. ;
  38. }
  39. private static bool IsOctalDigit(char ch)
  40. {
  41. return ch >= '0' && ch <= '7';
  42. }
  43. private static bool IsWhiteSpace(char ch)
  44. {
  45. return (ch == ' ') ||
  46. (ch == '\t') ||
  47. (ch == '\n') ||
  48. (ch == '\r');
  49. }
  50. private static bool IsLineTerminator(char ch)
  51. {
  52. return (ch == 10) || (ch == 13) || (ch == 0x2028) || (ch == 0x2029);
  53. }
  54. private static bool IsNullChar(char ch)
  55. {
  56. return ch == 'n'
  57. || ch == 'u'
  58. || ch == 'l'
  59. || ch == 'l'
  60. ;
  61. }
  62. private static bool IsTrueOrFalseChar(char ch)
  63. {
  64. return ch == 't'
  65. || ch == 'r'
  66. || ch == 'u'
  67. || ch == 'e'
  68. || ch == 'f'
  69. || ch == 'a'
  70. || ch == 'l'
  71. || ch == 's'
  72. ;
  73. }
  74. private char ScanHexEscape(char prefix)
  75. {
  76. int code = char.MinValue;
  77. int len = (prefix == 'u') ? 4 : 2;
  78. for (int i = 0; i < len; ++i)
  79. {
  80. if (_index < _length && IsHexDigit(_source.CharCodeAt(_index)))
  81. {
  82. char ch = _source.CharCodeAt(_index++);
  83. code = code * 16 + "0123456789abcdef".IndexOf(ch.ToString(), StringComparison.OrdinalIgnoreCase);
  84. }
  85. else
  86. {
  87. throw new JavaScriptException(_engine.SyntaxError, string.Format("Expected hexadecimal digit:{0}", _source));
  88. }
  89. }
  90. return (char)code;
  91. }
  92. private void SkipWhiteSpace()
  93. {
  94. while (_index < _length)
  95. {
  96. char ch = _source.CharCodeAt(_index);
  97. if (IsWhiteSpace(ch))
  98. {
  99. ++_index;
  100. }
  101. else
  102. {
  103. break;
  104. }
  105. }
  106. }
  107. private Token ScanPunctuator()
  108. {
  109. int start = _index;
  110. char code = _source.CharCodeAt(_index);
  111. switch ((int) code)
  112. {
  113. // Check for most common single-character punctuators.
  114. case 46: // . dot
  115. case 40: // ( open bracket
  116. case 41: // ) close bracket
  117. case 59: // ; semicolon
  118. case 44: // , comma
  119. case 123: // { open curly brace
  120. case 125: // } close curly brace
  121. case 91: // [
  122. case 93: // ]
  123. case 58: // :
  124. case 63: // ?
  125. case 126: // ~
  126. ++_index;
  127. return new Token
  128. {
  129. Type = Tokens.Punctuator,
  130. Value = code.ToString(),
  131. LineNumber = _lineNumber,
  132. LineStart = _lineStart,
  133. Range = new[] {start, _index}
  134. };
  135. }
  136. throw new JavaScriptException(_engine.SyntaxError, string.Format(Messages.UnexpectedToken, code));
  137. }
  138. private Token ScanNumericLiteral()
  139. {
  140. char ch = _source.CharCodeAt(_index);
  141. int start = _index;
  142. string number = "";
  143. if (ch != '.')
  144. {
  145. number = _source.CharCodeAt(_index++).ToString();
  146. ch = _source.CharCodeAt(_index);
  147. // Hex number starts with '0x'.
  148. // Octal number starts with '0'.
  149. if (number == "0")
  150. {
  151. // decimal number starts with '0' such as '09' is illegal.
  152. if (ch > 0 && IsDecimalDigit(ch))
  153. {
  154. throw new Exception(Messages.UnexpectedToken);
  155. }
  156. }
  157. while (IsDecimalDigit(_source.CharCodeAt(_index)))
  158. {
  159. number += _source.CharCodeAt(_index++).ToString();
  160. }
  161. ch = _source.CharCodeAt(_index);
  162. }
  163. if (ch == '.')
  164. {
  165. number += _source.CharCodeAt(_index++).ToString();
  166. while (IsDecimalDigit(_source.CharCodeAt(_index)))
  167. {
  168. number += _source.CharCodeAt(_index++).ToString();
  169. }
  170. ch = _source.CharCodeAt(_index);
  171. }
  172. if (ch == 'e' || ch == 'E')
  173. {
  174. number += _source.CharCodeAt(_index++).ToString();
  175. ch = _source.CharCodeAt(_index);
  176. if (ch == '+' || ch == '-')
  177. {
  178. number += _source.CharCodeAt(_index++).ToString();
  179. }
  180. if (IsDecimalDigit(_source.CharCodeAt(_index)))
  181. {
  182. while (IsDecimalDigit(_source.CharCodeAt(_index)))
  183. {
  184. number += _source.CharCodeAt(_index++).ToString();
  185. }
  186. }
  187. else
  188. {
  189. throw new Exception(Messages.UnexpectedToken);
  190. }
  191. }
  192. return new Token
  193. {
  194. Type = Tokens.Number,
  195. Value = Double.Parse(number, NumberStyles.AllowDecimalPoint | NumberStyles.AllowExponent, CultureInfo.InvariantCulture),
  196. LineNumber = _lineNumber,
  197. LineStart = _lineStart,
  198. Range = new[] {start, _index}
  199. };
  200. }
  201. private Token ScanBooleanLiteral()
  202. {
  203. int start = _index;
  204. string s = "";
  205. while (IsTrueOrFalseChar(_source.CharCodeAt(_index)))
  206. {
  207. s += _source.CharCodeAt(_index++).ToString();
  208. }
  209. if (s == "true" || s == "false")
  210. {
  211. return new Token
  212. {
  213. Type = Tokens.BooleanLiteral,
  214. Value = s == "true",
  215. LineNumber = _lineNumber,
  216. LineStart = _lineStart,
  217. Range = new[] { start, _index }
  218. };
  219. }
  220. else
  221. {
  222. throw new JavaScriptException(_engine.SyntaxError, string.Format(Messages.UnexpectedToken, s));
  223. }
  224. }
  225. private Token ScanNullLiteral()
  226. {
  227. int start = _index;
  228. string s = "";
  229. while (IsNullChar(_source.CharCodeAt(_index)))
  230. {
  231. s += _source.CharCodeAt(_index++).ToString();
  232. }
  233. if (s == Null.Text)
  234. {
  235. return new Token
  236. {
  237. Type = Tokens.NullLiteral,
  238. Value = Null.Instance,
  239. LineNumber = _lineNumber,
  240. LineStart = _lineStart,
  241. Range = new[] { start, _index }
  242. };
  243. }
  244. else
  245. {
  246. throw new JavaScriptException(_engine.SyntaxError, string.Format(Messages.UnexpectedToken, s));
  247. }
  248. }
  249. private Token ScanStringLiteral()
  250. {
  251. string str = "";
  252. char quote = _source.CharCodeAt(_index);
  253. int start = _index;
  254. ++_index;
  255. while (_index < _length)
  256. {
  257. char ch = _source.CharCodeAt(_index++);
  258. if (ch == quote)
  259. {
  260. quote = char.MinValue;
  261. break;
  262. }
  263. if (ch <= 31)
  264. {
  265. throw new JavaScriptException(_engine.SyntaxError, string.Format("Invalid character '{0}', position:{1}, string:{2}", ch, _index, _source));
  266. }
  267. if (ch == '\\')
  268. {
  269. ch = _source.CharCodeAt(_index++);
  270. if (ch > 0 || !IsLineTerminator(ch))
  271. {
  272. switch (ch)
  273. {
  274. case 'n':
  275. str += '\n';
  276. break;
  277. case 'r':
  278. str += '\r';
  279. break;
  280. case 't':
  281. str += '\t';
  282. break;
  283. case 'u':
  284. case 'x':
  285. int restore = _index;
  286. char unescaped = ScanHexEscape(ch);
  287. if (unescaped > 0)
  288. {
  289. str += unescaped.ToString();
  290. }
  291. else
  292. {
  293. _index = restore;
  294. str += ch.ToString();
  295. }
  296. break;
  297. case 'b':
  298. str += "\b";
  299. break;
  300. case 'f':
  301. str += "\f";
  302. break;
  303. case 'v':
  304. str += "\x0B";
  305. break;
  306. default:
  307. if (IsOctalDigit(ch))
  308. {
  309. int code = "01234567".IndexOf(ch);
  310. if (_index < _length && IsOctalDigit(_source.CharCodeAt(_index)))
  311. {
  312. code = code * 8 + "01234567".IndexOf(_source.CharCodeAt(_index++));
  313. // 3 digits are only allowed when string starts
  314. // with 0, 1, 2, 3
  315. if ("0123".IndexOf(ch) >= 0 &&
  316. _index < _length &&
  317. IsOctalDigit(_source.CharCodeAt(_index)))
  318. {
  319. code = code * 8 + "01234567".IndexOf(_source.CharCodeAt(_index++));
  320. }
  321. }
  322. str += ((char)code).ToString();
  323. }
  324. else
  325. {
  326. str += ch.ToString();
  327. }
  328. break;
  329. }
  330. }
  331. else
  332. {
  333. ++_lineNumber;
  334. if (ch == '\r' && _source.CharCodeAt(_index) == '\n')
  335. {
  336. ++_index;
  337. }
  338. }
  339. }
  340. else if (IsLineTerminator(ch))
  341. {
  342. break;
  343. }
  344. else
  345. {
  346. str += ch.ToString();
  347. }
  348. }
  349. if (quote != 0)
  350. {
  351. throw new JavaScriptException(_engine.SyntaxError, string.Format(Messages.UnexpectedToken, _source));
  352. }
  353. return new Token
  354. {
  355. Type = Tokens.String,
  356. Value = str,
  357. LineNumber = _lineNumber,
  358. LineStart = _lineStart,
  359. Range = new[] {start, _index}
  360. };
  361. }
  362. private Token Advance()
  363. {
  364. SkipWhiteSpace();
  365. if (_index >= _length)
  366. {
  367. return new Token
  368. {
  369. Type = Tokens.EOF,
  370. LineNumber = _lineNumber,
  371. LineStart = _lineStart,
  372. Range = new[] {_index, _index}
  373. };
  374. }
  375. char ch = _source.CharCodeAt(_index);
  376. // Very common: ( and ) and ;
  377. if (ch == 40 || ch == 41 || ch == 58)
  378. {
  379. return ScanPunctuator();
  380. }
  381. // String literal starts with double quote (#34).
  382. // Single quote (#39) are not allowed in JSON.
  383. if (ch == 34)
  384. {
  385. return ScanStringLiteral();
  386. }
  387. // Dot (.) char #46 can also start a floating-point number, hence the need
  388. // to check the next character.
  389. if (ch == 46)
  390. {
  391. if (IsDecimalDigit(_source.CharCodeAt(_index + 1)))
  392. {
  393. return ScanNumericLiteral();
  394. }
  395. return ScanPunctuator();
  396. }
  397. if (IsDecimalDigit(ch))
  398. {
  399. return ScanNumericLiteral();
  400. }
  401. if (ch == 't' || ch == 'f')
  402. {
  403. return ScanBooleanLiteral();
  404. }
  405. if (ch == 'n')
  406. {
  407. return ScanNullLiteral();
  408. }
  409. return ScanPunctuator();
  410. }
  411. private Token CollectToken()
  412. {
  413. _location = new Location
  414. {
  415. Start = new Position
  416. {
  417. Line = _lineNumber,
  418. Column = _index - _lineStart
  419. }
  420. };
  421. Token token = Advance();
  422. _location.End = new Position
  423. {
  424. Line = _lineNumber,
  425. Column = _index - _lineStart
  426. };
  427. if (token.Type != Tokens.EOF)
  428. {
  429. var range = new[] {token.Range[0], token.Range[1]};
  430. string value = _source.Slice(token.Range[0], token.Range[1]);
  431. _extra.Tokens.Add(new Token
  432. {
  433. Type = token.Type,
  434. Value = value,
  435. Range = range,
  436. });
  437. }
  438. return token;
  439. }
  440. private Token Lex()
  441. {
  442. Token token = _lookahead;
  443. _index = token.Range[1];
  444. _lineNumber = token.LineNumber.HasValue ? token.LineNumber.Value : 0;
  445. _lineStart = token.LineStart;
  446. _lookahead = (_extra.Tokens != null) ? CollectToken() : Advance();
  447. _index = token.Range[1];
  448. _lineNumber = token.LineNumber.HasValue ? token.LineNumber.Value : 0;
  449. _lineStart = token.LineStart;
  450. return token;
  451. }
  452. private void Peek()
  453. {
  454. int pos = _index;
  455. int line = _lineNumber;
  456. int start = _lineStart;
  457. _lookahead = (_extra.Tokens != null) ? CollectToken() : Advance();
  458. _index = pos;
  459. _lineNumber = line;
  460. _lineStart = start;
  461. }
  462. private void MarkStart()
  463. {
  464. if (_extra.Loc.HasValue)
  465. {
  466. _state.MarkerStack.Push(_index - _lineStart);
  467. _state.MarkerStack.Push(_lineNumber);
  468. }
  469. if (_extra.Range != null)
  470. {
  471. _state.MarkerStack.Push(_index);
  472. }
  473. }
  474. private T MarkEnd<T>(T node) where T : SyntaxNode
  475. {
  476. if (_extra.Range != null)
  477. {
  478. node.Range = new[] {_state.MarkerStack.Pop(), _index};
  479. }
  480. if (_extra.Loc.HasValue)
  481. {
  482. node.Location = new Location
  483. {
  484. Start = new Position
  485. {
  486. Line = _state.MarkerStack.Pop(),
  487. Column = _state.MarkerStack.Pop()
  488. },
  489. End = new Position
  490. {
  491. Line = _lineNumber,
  492. Column = _index - _lineStart
  493. }
  494. };
  495. PostProcess(node);
  496. }
  497. return node;
  498. }
  499. public T MarkEndIf<T>(T node) where T : SyntaxNode
  500. {
  501. if (node.Range != null || node.Location != null)
  502. {
  503. if (_extra.Loc.HasValue)
  504. {
  505. _state.MarkerStack.Pop();
  506. _state.MarkerStack.Pop();
  507. }
  508. if (_extra.Range != null)
  509. {
  510. _state.MarkerStack.Pop();
  511. }
  512. }
  513. else
  514. {
  515. MarkEnd(node);
  516. }
  517. return node;
  518. }
  519. public SyntaxNode PostProcess(SyntaxNode node)
  520. {
  521. if (_extra.Source != null)
  522. {
  523. node.Location.Source = _extra.Source;
  524. }
  525. return node;
  526. }
  527. public ObjectInstance CreateArrayInstance(IEnumerable<JsValue> values)
  528. {
  529. return _engine.Array.Construct(values.ToArray());
  530. }
  531. // Throw an exception
  532. private void ThrowError(Token token, string messageFormat, params object[] arguments)
  533. {
  534. ParserError error;
  535. string msg = System.String.Format(messageFormat, arguments);
  536. if (token.LineNumber.HasValue)
  537. {
  538. error = new ParserError("Line " + token.LineNumber + ": " + msg)
  539. {
  540. Index = token.Range[0],
  541. LineNumber = token.LineNumber.Value,
  542. Column = token.Range[0] - _lineStart + 1
  543. };
  544. }
  545. else
  546. {
  547. error = new ParserError("Line " + _lineNumber + ": " + msg)
  548. {
  549. Index = _index,
  550. LineNumber = _lineNumber,
  551. Column = _index - _lineStart + 1
  552. };
  553. }
  554. error.Description = msg;
  555. throw error;
  556. }
  557. // Throw an exception because of the token.
  558. private void ThrowUnexpected(Token token)
  559. {
  560. if (token.Type == Tokens.EOF)
  561. {
  562. ThrowError(token, Messages.UnexpectedEOS);
  563. }
  564. if (token.Type == Tokens.Number)
  565. {
  566. ThrowError(token, Messages.UnexpectedNumber);
  567. }
  568. if (token.Type == Tokens.String)
  569. {
  570. ThrowError(token, Messages.UnexpectedString);
  571. }
  572. // BooleanLiteral, NullLiteral, or Punctuator.
  573. ThrowError(token, Messages.UnexpectedToken, token.Value as string);
  574. }
  575. // Expect the next token to match the specified punctuator.
  576. // If not, an exception will be thrown.
  577. private void Expect(string value)
  578. {
  579. Token token = Lex();
  580. if (token.Type != Tokens.Punctuator || !value.Equals(token.Value))
  581. {
  582. ThrowUnexpected(token);
  583. }
  584. }
  585. // Return true if the next token matches the specified punctuator.
  586. private bool Match(string value)
  587. {
  588. return _lookahead.Type == Tokens.Punctuator && value.Equals(_lookahead.Value);
  589. }
  590. private ObjectInstance ParseJsonArray()
  591. {
  592. var elements = new List<JsValue>();
  593. Expect("[");
  594. while (!Match("]"))
  595. {
  596. if (Match(","))
  597. {
  598. Lex();
  599. elements.Add(Null.Instance);
  600. }
  601. else
  602. {
  603. elements.Add(ParseJsonValue());
  604. if (!Match("]"))
  605. {
  606. Expect(",");
  607. }
  608. }
  609. }
  610. Expect("]");
  611. return CreateArrayInstance(elements);
  612. }
  613. public ObjectInstance ParseJsonObject()
  614. {
  615. Expect("{");
  616. var obj = _engine.Object.Construct(Arguments.Empty);
  617. while (!Match("}"))
  618. {
  619. Tokens type = _lookahead.Type;
  620. if (type != Tokens.String)
  621. {
  622. ThrowUnexpected(Lex());
  623. }
  624. var name = Lex().Value.ToString();
  625. if (PropertyNameContainsInvalidChar0To31(name))
  626. {
  627. throw new JavaScriptException(_engine.SyntaxError, string.Format("Invalid character in property name '{0}'", name));
  628. }
  629. Expect(":");
  630. var value = ParseJsonValue();
  631. obj.FastAddProperty(name, value, true, true, true);
  632. if (!Match("}"))
  633. {
  634. Expect(",");
  635. }
  636. }
  637. Expect("}");
  638. return obj;
  639. }
  640. private bool PropertyNameContainsInvalidChar0To31(string s)
  641. {
  642. const int max = 31;
  643. for (var i = 0; i < s.Length; i++)
  644. {
  645. var val = (int)s[i];
  646. if (val <= max)
  647. return true;
  648. }
  649. return false;
  650. }
  651. /// <summary>
  652. /// Optimization.
  653. /// By calling Lex().Value for each type, we parse the token twice.
  654. /// It was already parsed by the peek() method.
  655. /// _lookahead.Value already contain the value.
  656. /// </summary>
  657. /// <returns></returns>
  658. private JsValue ParseJsonValue()
  659. {
  660. Tokens type = _lookahead.Type;
  661. MarkStart();
  662. switch (type)
  663. {
  664. case Tokens.NullLiteral:
  665. var v = Lex().Value;
  666. return Null.Instance;
  667. case Tokens.BooleanLiteral:
  668. return new JsValue((bool)Lex().Value);
  669. case Tokens.String:
  670. return new JsValue((string)Lex().Value);
  671. case Tokens.Number:
  672. return new JsValue((double)Lex().Value);
  673. }
  674. if (Match("["))
  675. {
  676. return ParseJsonArray();
  677. }
  678. if (Match("{"))
  679. {
  680. return ParseJsonObject();
  681. }
  682. ThrowUnexpected(Lex());
  683. // can't be reached
  684. return Null.Instance;
  685. }
  686. public JsValue Parse(string code)
  687. {
  688. return Parse(code, null);
  689. }
  690. public JsValue Parse(string code, ParserOptions options)
  691. {
  692. _source = code;
  693. _index = 0;
  694. _lineNumber = (_source.Length > 0) ? 1 : 0;
  695. _lineStart = 0;
  696. _length = _source.Length;
  697. _lookahead = null;
  698. _state = new State
  699. {
  700. AllowIn = true,
  701. LabelSet = new HashSet<string>(),
  702. InFunctionBody = false,
  703. InIteration = false,
  704. InSwitch = false,
  705. LastCommentStart = -1,
  706. MarkerStack = new Stack<int>()
  707. };
  708. _extra = new Extra
  709. {
  710. Range = new int[0],
  711. Loc = 0,
  712. };
  713. if (options != null)
  714. {
  715. if (!System.String.IsNullOrEmpty(options.Source))
  716. {
  717. _extra.Source = options.Source;
  718. }
  719. if (options.Tokens)
  720. {
  721. _extra.Tokens = new List<Token>();
  722. }
  723. }
  724. try
  725. {
  726. MarkStart();
  727. Peek();
  728. JsValue jsv = ParseJsonValue();
  729. Peek();
  730. Tokens type = _lookahead.Type;
  731. object value = _lookahead.Value;
  732. if(_lookahead.Type != Tokens.EOF)
  733. {
  734. throw new JavaScriptException(_engine.SyntaxError, string.Format("Unexpected {0} {1}", _lookahead.Type, _lookahead.Value));
  735. }
  736. return jsv;
  737. }
  738. finally
  739. {
  740. _extra = new Extra();
  741. }
  742. }
  743. private class Extra
  744. {
  745. public int? Loc;
  746. public int[] Range;
  747. public string Source;
  748. public List<Token> Tokens;
  749. }
  750. private enum Tokens
  751. {
  752. NullLiteral,
  753. BooleanLiteral,
  754. String,
  755. Number,
  756. Punctuator,
  757. EOF,
  758. };
  759. class Token
  760. {
  761. public Tokens Type;
  762. public object Value;
  763. public int[] Range;
  764. public int? LineNumber;
  765. public int LineStart;
  766. }
  767. static class Messages
  768. {
  769. public const string UnexpectedToken = "Unexpected token {0}";
  770. public const string UnexpectedNumber = "Unexpected number";
  771. public const string UnexpectedString = "Unexpected string";
  772. public const string UnexpectedEOS = "Unexpected end of input";
  773. };
  774. }
  775. }