node/lib/metasm/metasm/parse.rb
def parse_instruction(lexer)
		lexer = new_asmprepro(lexer) if lexer.kind_of? String

		i = Instruction.new self

		# find prefixes, break on opcode name
		while tok = lexer.readtok and parse_prefix(i, tok.raw)
			lexer.skip_space_eol
		end
		return if not tok

		# allow '.' in opcode name
		tok = tok.dup
		while ntok = lexer.nexttok and ntok.type == :punct and ntok.raw == '.'
			tok.raw << lexer.readtok.raw
			ntok = lexer.readtok
			raise tok, 'invalid opcode name' if not ntok or ntok.type != :string
			tok.raw << ntok.raw
		end

		raise tok, 'invalid opcode' if not opcode_list_byname[tok.raw]

		i.opname = tok.raw
		i.backtrace = tok.backtrace
		lexer.skip_space

		# find arguments list
		loop do
			break if not ntok = lexer.nexttok
			break if i.args.empty? and opcode_list_byname[ntok.raw] and opcode_list_byname[i.opname].find { |op| op.args.empty? }
			break if not arg = parse_argument(lexer)
			i.args << arg
			lexer.skip_space
			break if not ntok = lexer.nexttok or ntok.type != :punct or ntok.raw != ','
			lexer.readtok
			lexer.skip_space_eol
		end

		if not parse_instruction_checkproto(i)
			raise tok, "invalid opcode arguments #{i.to_s.inspect}, allowed : #{opcode_list_byname[i.opname].to_a.map { |o| o.args }.inspect}"
		end
		parse_instruction_fixup(i)

		i
	end
# parses prefix/name/arguments
# returns an +Instruction+ or raise a ParseError
# if the parameter is a String, a custom AsmPP is built - XXX it will not be able to create labels (eg jmp 1b / jmp $)
parses prefix/name/arguments
returns an +Instruction+ or raise a ParseError
if the parameter is a String, a custom AsmPP is built - XXX it will not be able to create labels
parses prefix / name / arguments returns an + Instruction + or raise a ParseError if the parameter is a String a custom AsmPP is built - XXX it will not be able to create labels
def parse_instruction(lexer)
		lexer = new_asmprepro(lexer) if lexer.kind_of? String
		i = Instruction.new self
		while tok = lexer.readtok and parse_prefix(i, tok.raw)
			lexer.skip_space_eol
		end
		return if not tok
		tok = tok.dup
		while ntok = lexer.nexttok and ntok.type == :punct and ntok.raw == '.'
			tok.raw << lexer.readtok.raw
			ntok = lexer.readtok
			raise tok, 'invalid opcode name' if not ntok or ntok.type != :string
			tok.raw << ntok.raw
		end
		raise tok, 'invalid opcode' if not opcode_list_byname[tok.raw]
		i.opname = tok.raw
		i.backtrace = tok.backtrace
		lexer.skip_space
		loop do
			break if not ntok = lexer.nexttok
			break if i.args.empty? and opcode_list_byname[ntok.raw] and opcode_list_byname[i.opname].find { |op| op.args.empty? }
			break if not arg = parse_argument(lexer)
			i.args << arg
			lexer.skip_space
			break if not ntok = lexer.nexttok or ntok.type != :punct or ntok.raw != ','
			lexer.readtok
			lexer.skip_space_eol
		end
		if not parse_instruction_checkproto(i)
			raise tok, "invalid opcode arguments #{i.to_s.inspect}, allowed : #{opcode_list_byname[i.opname].to_a.map { |o| o.args }.inspect}"
		end
		parse_instruction_fixup(i)
		i
	end
def parse_instruction ( lexer ) lexer = new_asmprepro ( lexer ) if lexer . kind_of? String i = Instruction . new self while tok = lexer . readtok and parse_prefix ( i , tok . raw ) lexer . skip_space_eol end return if not tok tok = tok . dup while ntok = lexer . nexttok and ntok . type == :punct and ntok . raw == '.' tok . raw << lexer . readtok . raw ntok = lexer . readtok raise tok , 'invalid opcode name' if not ntok or ntok . type != :string tok . raw << ntok . raw end raise tok , 'invalid opcode' if not opcode_list_byname [ tok . raw ] i . opname = tok . raw i . backtrace = tok . backtrace lexer . skip_space loop do break if not ntok = lexer . nexttok break if i . args . empty? and opcode_list_byname [ ntok . raw ] and opcode_list_byname [ i . opname ] . find { | op | op . args . empty? } break if not arg = parse_argument ( lexer ) i . args << arg lexer . skip_space break if not ntok = lexer . nexttok or ntok . type != :punct or ntok . raw != ',' lexer . readtok lexer . skip_space_eol end if not parse_instruction_checkproto ( i ) raise tok , "invalid opcode arguments #{i.to_s.inspect}, allowed : #{opcode_list_byname[i.opname].to_a.map { |o| o.args }.inspect}" end parse_instruction_fixup ( i ) i end
parses prefix/name/arguments
returns an +Instruction+ or raise a ParseError
if the parameter is a String, a custom AsmPP is built - XXX it will not be able to create labels (eg jmp 1b / jmp $)
parses prefix / name / arguments returns an + Instruction + or raise a ParseError if the parameter is a String a custom AsmPP is built - XXX it will not be able to create labels ( eg jmp 1b / jmp $ )
# find prefixes, break on opcode name # allow '.' in opcode name # find arguments list
lexer