node/lib/metasm/metasm/parse.rb
def parse_parser_instruction(tok)
		case tok.raw.downcase
		when '.align'
			e = Expression.parse(@lexer).reduce
			raise self, 'need immediate alignment size' unless e.kind_of? ::Integer
			@lexer.skip_space
			if ntok = @lexer.readtok and ntok.type == :punct and ntok.raw == ','
				@lexer.skip_space_eol
				# allow single byte value or full data statement
				if not ntok = @lexer.readtok or not ntok.type == :string or not Data::DataSpec.include?(ntok.raw)
					@lexer.unreadtok ntok
					type = 'db'
				else
					type = ntok.raw
				end
				fillwith = parse_data_data type
			else
				@lexer.unreadtok ntok
			end
			raise tok, 'syntax error' if ntok = @lexer.nexttok and ntok.type != :eol
			@cursource << Align.new(e, fillwith, tok.backtrace)

		when '.pad'
			@lexer.skip_space
			if ntok = @lexer.readtok and ntok.type != :eol
				# allow single byte value or full data statement
				if not ntok.type == :string or not Data::DataSpec.include?(ntok.raw)
					@lexer.unreadtok ntok
					type = 'db'
				else
					type = ntok.raw
				end
				fillwith = parse_data_data(type)
			else
				@lexer.unreadtok ntok
			end
			raise tok, 'syntax error' if ntok = @lexer.nexttok and ntok.type != :eol
			@cursource << Padding.new(fillwith, tok.backtrace)

		when '.offset'
			e = Expression.parse(@lexer)
			raise tok, 'syntax error' if ntok = @lexer.nexttok and ntok.type != :eol
			@cursource << Offset.new(e, tok.backtrace)

		when '.padto'
			e = Expression.parse(@lexer)
			@lexer.skip_space
			if ntok = @lexer.readtok and ntok.type == :punct and ntok.raw == ','
				@lexer.skip_space
				# allow single byte value or full data statement
				if not ntok = @lexer.readtok or not ntok.type == :string or not Data::DataSpec.include?(ntok.raw)
					@lexer.unreadtok ntok
					type = 'db'
				else
					type = ntok.raw
				end
				fillwith = parse_data_data type
			else
				@lexer.unreadtok ntok
			end
			raise tok, 'syntax error' if ntok = @lexer.nexttok and ntok.type != :eol
			@cursource << Padding.new(fillwith, tok.backtrace) << Offset.new(e, tok.backtrace)

		else
			@cpu.parse_parser_instruction(self, tok)
		end
	end
# handles special directives (alignment, changing section, ...)
# special directives start with a dot
handles special directives (alignment, changing section, ...)
special directives start with a dot
handles special directives ( alignment changing section ... ) special directives start with a dot
def parse_parser_instruction(tok)
		case tok.raw.downcase
		when '.align'
			e = Expression.parse(@lexer).reduce
			raise self, 'need immediate alignment size' unless e.kind_of? ::Integer
			@lexer.skip_space
			if ntok = @lexer.readtok and ntok.type == :punct and ntok.raw == ','
				@lexer.skip_space_eol
				if not ntok = @lexer.readtok or not ntok.type == :string or not Data::DataSpec.include?(ntok.raw)
					@lexer.unreadtok ntok
					type = 'db'
				else
					type = ntok.raw
				end
				fillwith = parse_data_data type
			else
				@lexer.unreadtok ntok
			end
			raise tok, 'syntax error' if ntok = @lexer.nexttok and ntok.type != :eol
			@cursource << Align.new(e, fillwith, tok.backtrace)
		when '.pad'
			@lexer.skip_space
			if ntok = @lexer.readtok and ntok.type != :eol
				if not ntok.type == :string or not Data::DataSpec.include?(ntok.raw)
					@lexer.unreadtok ntok
					type = 'db'
				else
					type = ntok.raw
				end
				fillwith = parse_data_data(type)
			else
				@lexer.unreadtok ntok
			end
			raise tok, 'syntax error' if ntok = @lexer.nexttok and ntok.type != :eol
			@cursource << Padding.new(fillwith, tok.backtrace)
		when '.offset'
			e = Expression.parse(@lexer)
			raise tok, 'syntax error' if ntok = @lexer.nexttok and ntok.type != :eol
			@cursource << Offset.new(e, tok.backtrace)
		when '.padto'
			e = Expression.parse(@lexer)
			@lexer.skip_space
			if ntok = @lexer.readtok and ntok.type == :punct and ntok.raw == ','
				@lexer.skip_space
				if not ntok = @lexer.readtok or not ntok.type == :string or not Data::DataSpec.include?(ntok.raw)
					@lexer.unreadtok ntok
					type = 'db'
				else
					type = ntok.raw
				end
				fillwith = parse_data_data type
			else
				@lexer.unreadtok ntok
			end
			raise tok, 'syntax error' if ntok = @lexer.nexttok and ntok.type != :eol
			@cursource << Padding.new(fillwith, tok.backtrace) << Offset.new(e, tok.backtrace)
		else
			@cpu.parse_parser_instruction(self, tok)
		end
	end
def parse_parser_instruction ( tok ) case tok . raw . downcase when '.align' e = Expression . parse ( @lexer ) . reduce raise self , 'need immediate alignment size' unless e . kind_of? :: Integer @lexer . skip_space if ntok = @lexer . readtok and ntok . type == :punct and ntok . raw == ',' @lexer . skip_space_eol if not ntok = @lexer . readtok or not ntok . type == :string or not Data :: DataSpec . include? ( ntok . raw ) @lexer . unreadtok ntok type = 'db' else type = ntok . raw end fillwith = parse_data_data type else @lexer . unreadtok ntok end raise tok , 'syntax error' if ntok = @lexer . nexttok and ntok . type != :eol @cursource << Align . new ( e , fillwith , tok . backtrace ) when '.pad' @lexer . skip_space if ntok = @lexer . readtok and ntok . type != :eol if not ntok . type == :string or not Data :: DataSpec . include? ( ntok . raw ) @lexer . unreadtok ntok type = 'db' else type = ntok . raw end fillwith = parse_data_data ( type ) else @lexer . unreadtok ntok end raise tok , 'syntax error' if ntok = @lexer . nexttok and ntok . type != :eol @cursource << Padding . new ( fillwith , tok . backtrace ) when '.offset' e = Expression . parse ( @lexer ) raise tok , 'syntax error' if ntok = @lexer . nexttok and ntok . type != :eol @cursource << Offset . new ( e , tok . backtrace ) when '.padto' e = Expression . parse ( @lexer ) @lexer . skip_space if ntok = @lexer . readtok and ntok . type == :punct and ntok . raw == ',' @lexer . skip_space if not ntok = @lexer . readtok or not ntok . type == :string or not Data :: DataSpec . include? ( ntok . raw ) @lexer . unreadtok ntok type = 'db' else type = ntok . raw end fillwith = parse_data_data type else @lexer . unreadtok ntok end raise tok , 'syntax error' if ntok = @lexer . nexttok and ntok . type != :eol @cursource << Padding . new ( fillwith , tok . backtrace ) << Offset . new ( e , tok . backtrace ) else @cpu . parse_parser_instruction ( self , tok ) end end
handles special directives (alignment, changing section, ...)
special directives start with a dot
handles special directives ( alignment changing section ... ) special directives start with a dot
# allow single byte value or full data statement # allow single byte value or full data statement # allow single byte value or full data statement
tok