Skip to content

prathe/pgn.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced JavaScript PGN parser for nodeJS and RequireJS

Parse PGN chess games into a JavaScript object. The parser works both in the backend and the frontend. The tests have been made to run under nodeJS.

Features

  • Based on the PGN Specifications
  • Support tagpairs
  • Support SAN (Standard Algebraic Notation) and LAN (Long Algebraic Notation)
  • Support SAC (Symbolic Annotation Code) and NAG (Numeric Annotation Glyph)
  • Movenumbers are optional
  • Infinite comments
  • Infinite Recursive Annotation Variation (RAV)
  • Output is JSON
  • Support commands into comments (such as the clock) which is not in the specs but is accepted as an extension of the specifications.
  • In the browser the JavaScript files are loaded with the RequireJS module loader
  • Very fast parser when used on the server side with nodeJS

Parse PGN in the browser with RequireJS

  • Look at the example folder for a live example.

Environment Setup for nodeJS development

Generate the parser

This command will generate a myfile.js file in the current directory
jison pgn/pgn.jison

You will need to manually wrap to output file generated by Jison inside a CommonJS module
require.def(function(require, exports, module) { /* output of jison here */ });

Launch the parser test suite

node /path/to/r.js tests/pgn/all.js

Enhancements

The parser has been coded at the time Jison didn’t support start conditions. It may be possible to simplify the lexer with that features. The lack of this feature at the time of coding have added complexity to the lexer which will disappear when rewritten using start conditions.

License

Copyright © 2011 Philippe Rathé

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Advanced JavaScript chess games parser (PGN)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published