Skip to content

Instantly share code, notes, and snippets.

@StanAngeloff
Created August 24, 2010 18:03
Show Gist options
  • Select an option

  • Save StanAngeloff/547998 to your computer and use it in GitHub Desktop.

Select an option

Save StanAngeloff/547998 to your computer and use it in GitHub Desktop.
StringScanner = null
( ->
setState = (target, matches, values) ->
target.head = values?.head ? target.head
target.last = values?.last ? target.last
target.captures = matches.slice 1
target.match = matches[0]
class StringScanner
constructor: (source) ->
@source = source.toString()
@reset()
scan: (regexp) ->
if (matches = regexp.exec @getRemainder()) and matches.index is 0
setState @, matches,
head: @head + matches[0].length
last: @head
else
setState @, []
)()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment