This commit is contained in:
Michael Matuzak 2016-10-11 17:59:26 -07:00
parent 3a52f4399c
commit e8ca1f9bcd
4 changed files with 17 additions and 9 deletions

View File

@ -11,7 +11,8 @@ function assembler (input) {
directive(), directive(),
instruction(), instruction(),
label(), label(),
mona.eol() mona.eol(),
mona.eof()
) )
), ),
input input

View File

@ -24,16 +24,24 @@ function instructionName () {
function instruction () { function instruction () {
return mona.sequence((s) => { return mona.sequence((s) => {
const i = s(instructionName()) const i = s(
mona.followedBy(
instructionName(),
mona.maybe(mona.eol())
)
)
const args = s( const args = s(
mona.maybe( mona.maybe(
mona.and( mona.and(
mona.spaces(), mona.spaces(),
parameters() mona.followedBy(
parameters(),
mona.maybe(mona.eol())
)
) )
) )
) )
const nl = s(mona.eol())
return mona.value({ return mona.value({
instruction: i, instruction: i,
args: args args: args

View File

@ -8,10 +8,9 @@ tap.test('should parse the basics', (t) => {
{ {
directive: '.org', directive: '.org',
args: [ args: [
[ {
'address', 'address': 'C000'
'C000' }
]
] ]
}, },
{ {

View File

@ -5,7 +5,7 @@ const instructionParser = require('../parsers/instruction')
tap.test('will parse an instruction', (t) => { tap.test('will parse an instruction', (t) => {
t.plan(1) t.plan(1)
t.deepEqual(mona.parse(instructionParser(), 'sei\n'), { t.deepEqual(mona.parse(instructionParser(), 'sei\n'), {
args: [], args: null,
instruction: 'sei' instruction: 'sei'
}) })
}) })