node/lib/metasm/metasm/parse.rb
# reads a token, handles macros/comments/etc
reads a token, handles macros/comments/etc
reads a token handles macros / comments / etc
def readtok
		tok = super()
		return tok if not tok or tok.alreadyapp
		if tok.type == :punct and tok.raw[0] == ?;
			tok.type = :eol
			begin
				tok = tok.dup
				while ntok = super() and ntok.type != :eol
					tok.raw << ntok.raw
				end
				tok.raw << ntok.raw if ntok
			rescue ParseError
			end
		end
		if @may_apreprocess and tok.type == :string
			if @macro[tok.raw]
				@macro[tok.raw].apply(tok, self, @program).reverse_each { |t| unreadtok t }
				tok = readtok
			else
				if ntok = super() and ntok.type == :space and nntok = super() and nntok.type == :string and (nntok.raw == 'macro' or nntok.raw == 'equ')
					puts "W: asm: redefinition of macro #{tok.raw} at #{tok.backtrace_str}, previous definition at #{@macro[tok.raw].name.backtrace_str}" if @macro[tok.raw]
					m = Macro.new tok
					if nntok.raw == 'macro'
						m.parse_definition self
					else
						raise nntok if not etok = readtok
						unreadtok etok
						raise nntok if not v = Expression.parse(self)
						etok = etok.dup
						etok.type = :string
						etok.value = v
						etok.raw = v.to_s
						m.body << etok
					end
					@macro[tok.raw] = m
					tok = readtok
				else
					unreadtok nntok
					unreadtok ntok
				end
			end
		end
		tok.alreadyapp = true if tok
		tok
	end
def readtok tok = super ( ) return tok if not tok or tok . alreadyapp if tok . type == :punct and tok . raw [ 0 ] == ?; tok . type = :eol begin tok = tok . dup while ntok = super ( ) and ntok . type != :eol tok . raw << ntok . raw end tok . raw << ntok . raw if ntok rescue ParseError end end if @may_apreprocess and tok . type == :string if @macro [ tok . raw ] @macro [ tok . raw ] . apply ( tok , self , @program ) . reverse_each { | t | unreadtok t } tok = readtok else if ntok = super ( ) and ntok . type == :space and nntok = super ( ) and nntok . type == :string and ( nntok . raw == 'macro' or nntok . raw == 'equ' ) puts "W: asm: redefinition of macro #{tok.raw} at #{tok.backtrace_str}, previous definition at #{@macro[tok.raw].name.backtrace_str}" if @macro [ tok . raw ] m = Macro . new tok if nntok . raw == 'macro' m . parse_definition self else raise nntok if not etok = readtok unreadtok etok raise nntok if not v = Expression . parse ( self ) etok = etok . dup etok . type = :string etok . value = v etok . raw = v . to_s m . body << etok end @macro [ tok . raw ] = m tok = readtok else unreadtok nntok unreadtok ntok end end end tok . alreadyapp = true if tok tok end
reads a token, handles macros/comments/etc
reads a token handles macros / comments / etc
# handle ; comments # unterminated string # handle macros # XXX this allows nested macro definition.. # equ