Quantcast

Change OvaleLexer into an object factory to generate lexers.

Author Johnny C. Lam <jlam88@gmail.com>
Author date 2014-07-13 11:31:09
Author local date 2014-07-13 11:31:09 +0000
Committer Johnny C. Lam <jlam88@gmail.com>
Committer date 2014-07-13 11:31:09
Committer local date 2014-07-13 11:31:09 +0000
Commit 89af97dcc46b945f4ef7ad83efa3dcb4f4ab81d5
Tree 01871e98cf8ad32f949d20ce47d72ad1adf89396
Parent 025d88e818b08f41ba4719f80462eb63de43a186
Change OvaleLexer into an object factory to generate lexers.

The calling code must provide an iterator, which is typically generated
with OvaleLexer.scan.  The lexer buffers the token stream so that it may
be accessed with look-ahead capabilities.

The lexer provides two methods for accessing the buffered token stream:

Peek(k) buffers the next k tokens from the stream and returns the k'th one.
Consume(k) consumes the next k tokens from the buffer and returns the k'th one.

This allows the following code to iterate through the token stream without
consuming extra tokens.

    -- Process tokens until seeing a '}'.
    local tokenType, token = lexer:Peek()
    while tokenType ~= "}" do
        lexer:Consume()
        -- do stuff here with the token
        tokenType, token = lexer:Peek()
    end
    -- Here, the next token to be consumed is still '}'.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1540 d5049fe3-3747-40f7-a4b5-f36d6801af5f