Token

A bounded part of a text

(defined in /src/Token.coffee:7)
class Token

Parameters

NameTypeDescription
typeString type of text object
indexString index of text object within containing text
textString string of this text
(defined in /src/Token.coffee:18)
constructor: (@type, @index, @text) ->
	# Store the text length as the length property of the text object
	@length = @text.length
(defined in /src/Token.coffee:24)
clone: ->
	return new @constructor(@type, @index, @text)
  • other (String|Token): Other text object or string
(defined in /src/Token.coffee:54)
join : (other) ->
	str = if typeof other is 'string' then other else other.text
	return new Token(@type, @index, @text + str)

Parameters

NameTypeDescription
patString A regular expression
flagString An XRegExp flag such as `g`
(defined in /src/Token.coffee:32)
match : (pat, flags) ->
	flags or= 'x'
	XRegExp.match @text, new XRegExp(pat, flags)

Parameters

NameTypeDescription
n=1optional = 1Number Number of characters to remove
(defined in /src/Token.coffee:70)
removeLeft : (n) ->
	n or= 1
	return new Token(@type, @index, @text.substr(n))

Parameters

NameTypeDescription
n=1optional = 1Number Number of characters to remove
(defined in /src/Token.coffee:78)
removeRight : (n) ->
	n or= 1
	max = if n < @text.length then @text.length - n else @text.length
	return new Token(@type, @index, @text.substr(0,max))
(defined in /src/Token.coffee:45)
replace : (pat, replacement) ->
	@text = XRegExp.replace @text, new XRegExp(pat), replacement
	# TODO
	return @
(defined in /src/Token.coffee:38)
replaceAll : (pat, replacement) ->
	@text = XRegExp.replace @text, new XRegExp(pat), replacement, 'all'
	# TODO
	return @
(defined in /src/Token.coffee:60)
substr : (start, len) ->
	if start < 0
		start = @text.length + start
	len or= @text.length - start
	return @text.substr(start, len)