I know this doesn't quite answer your question but I find your approach a bit heavy for such (apparently) simple files to parse. Instanciating objects for each state will not help performance if that's what your aiming at. This leads me to my shameless plug: you should have a look at my tokenizer/parser modules and how I use them to parse JSON. You can find them here:
- Parser : https://github.com/Floby/node-parser - Tokenizer : https://github.com/Floby/node-tokenizer - parsing JSON : https://github.com/Floby/node-json-streams - A little article that I haven't finished yet about parsing : http://projects.flo.by/parsing-streams/ Hope this will help you. But I admit you'd need a good understanding of how closures work. On Wednesday, 6 February 2013 23:24:03 UTC+1, Ismael Gorissen wrote: > > So I need to parse .strings file. These files are created for the > localization of mobile application on iOS. A .strings file can contain > multiple lines comment (/* */ or /** */), simple line comment (//), keys > and the associated values ("keyname" = "keyvalue";). > > For this I thought about state pattern : > > - InitState -> found / -> CommentState -> found * -> MultiCommentState > (store characters and be careful about the and */) -> end of comment > callback 'onCommentFound' -> InitState > - InitState -> found / -> CommentState -> found / -> > SimpleCommentState (store characters) -> end of comment callback > 'onCommentFound' -> InitState > - ... > > I use async module to use the 'forEachSeries' function with which I can > iterate synchronously on all characters. > The state are extensible. > > - State is a abstract class > - CommentState, subclass of State, override handle method > - ... > - Action is a abstract class > - StoreAction, subclass of Action, override perform method > - ... > > I also using callbacks to handle the character with the current state of > the parser, and perform an action to ensure that the context remain correct. > > Sorry for my english :/ > > And thank you to help me. > > Le mercredi 6 février 2013 14:01:21 UTC+1, ajlopez a écrit : >> >> Nice, I love parsers! ;-) >> >> Ismael, can you point me your use cases? >> >> I don't sure what is a Key, Value, Comment, etc... The states are >> extensible? >> >> Do you use async? Or only callbacks? I see a require('async') in your >> code, but not sure in which case is needed. >> >> Node.js is a great tool, and JavaScript is so flexible. For testing, you >> can start small, using simple require('assert'). Some simple use: >> https://github.com/ajlopez/SimpleGlobals >> (see test.js, test folder, package.json the test definition) >> >> When you you need async testing, you can switch to a library, as the >> recommended in this thread. >> >> Angel "Java" Lopez >> @ajlopez >> >> On Wed, Feb 6, 2013 at 9:12 AM, Ismael Gorissen <ismael....@gmail.com>wrote: >> >>> Hi, >>> >>> I use Node.js for some months now and I created a module named >>> Node-StringsParser <https://github.com/PinchProject/Node-StringsParser>. >>> Since I started to learn the JavaScript language and Node.js 6 months ago, >>> I need some advice : >>> >>> - how to test well the module >>> - on my code (if I code well or not), best practice >>> - ... >>> >>> Thank you. >>> >>> -- >>> -- >>> Job Board: http://jobs.nodejs.org/ >>> Posting guidelines: >>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >>> You received this message because you are subscribed to the Google >>> Groups "nodejs" group. >>> To post to this group, send email to nod...@googlegroups.com >>> To unsubscribe from this group, send email to >>> nodejs+un...@googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/group/nodejs?hl=en?hl=en >>> >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "nodejs" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to nodejs+un...@googlegroups.com. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >> >> -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to nodejs@googlegroups.com To unsubscribe from this group, send email to nodejs+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.