mirror of
https://github.com/emkay/parser-6502.git
synced 2024-12-21 15:29:19 +00:00
yep
This commit is contained in:
parent
cb0e34d1e3
commit
5e098fe69d
@ -25,7 +25,7 @@ function instructionName () {
|
||||
function instruction () {
|
||||
return mona.sequence((s) => {
|
||||
const i = s(instructionName())
|
||||
const space = s(mona.spaces())
|
||||
const space = s(mona.maybe(mona.spaces()))
|
||||
const args = s(mona.maybe(parameters()))
|
||||
// const nl = s(mona.eol())
|
||||
return mona.value({
|
||||
|
@ -1,18 +1,13 @@
|
||||
const mona = require('mona')
|
||||
|
||||
function quotedChar () {
|
||||
return mona.or(mona.noneOf('"'),
|
||||
mona.and(mona.string('""'),
|
||||
return mona.or(
|
||||
mona.noneOf('"'),
|
||||
mona.and(
|
||||
mona.string('""'),
|
||||
mona.value('"')))
|
||||
}
|
||||
|
||||
function alphanum () {
|
||||
return mona.join(
|
||||
mona.value('alphanum'),
|
||||
mona.string('background3')
|
||||
)
|
||||
}
|
||||
|
||||
function bit () {
|
||||
return mona.join(
|
||||
mona.value('digit'),
|
||||
@ -68,9 +63,23 @@ function address () {
|
||||
)
|
||||
}
|
||||
|
||||
// this is the fallthrough parser
|
||||
function alphanum () {
|
||||
return mona.join(
|
||||
mona.value('alphanum'),
|
||||
mona.and(
|
||||
mona.not(bit()),
|
||||
mona.not(address()),
|
||||
mona.not(binary()),
|
||||
mona.not(bit()),
|
||||
mona.not(string()),
|
||||
mona.text(mona.alphanum())
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
function parameter () {
|
||||
return mona.collect(
|
||||
mona.or(
|
||||
return mona.or(
|
||||
address(),
|
||||
binary(),
|
||||
hex(),
|
||||
@ -78,12 +87,10 @@ function parameter () {
|
||||
bit(),
|
||||
alphanum()
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
function parameters () {
|
||||
return mona.map(a => a.map(b => b[0]),
|
||||
mona.split(
|
||||
return mona.split(
|
||||
parameter(),
|
||||
mona.or(
|
||||
mona.and(mona.string(','), mona.spaces()),
|
||||
@ -91,7 +98,6 @@ function parameters () {
|
||||
mona.spaces()
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -8,7 +8,10 @@ tap.test('should parse the basics', (t) => {
|
||||
{
|
||||
directive: '.org',
|
||||
args: [
|
||||
'$,C000'
|
||||
[
|
||||
'address',
|
||||
'C000'
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
|
@ -4,7 +4,7 @@ const instructionParser = require('../parsers/instruction')
|
||||
|
||||
tap.test('will parse an instruction', (t) => {
|
||||
t.plan(1)
|
||||
t.deepEqual(mona.parse(instructionParser(), 'sei'), {
|
||||
t.deepEqual(mona.parse(instructionParser(), 'sei\n'), {
|
||||
args: null,
|
||||
instruction: 'sei'
|
||||
})
|
||||
@ -12,7 +12,7 @@ tap.test('will parse an instruction', (t) => {
|
||||
|
||||
tap.test('will parse an instruction with args', (t) => {
|
||||
t.plan(1)
|
||||
t.deepEqual(mona.parse(instructionParser(), 'stx $2000'), {
|
||||
t.deepEqual(mona.parse(instructionParser(), 'stx $2000\n'), {
|
||||
args: [
|
||||
[
|
||||
'address',
|
||||
@ -25,7 +25,7 @@ tap.test('will parse an instruction with args', (t) => {
|
||||
|
||||
tap.test('will parse an instruction with multiple args', (t) => {
|
||||
t.plan(1)
|
||||
t.deepEqual(mona.parse(instructionParser(), 'lda background3, x'), {
|
||||
t.deepEqual(mona.parse(instructionParser(), 'lda background3, x\n'), {
|
||||
args: ['background3', 'x'],
|
||||
instruction: 'lda'
|
||||
})
|
||||
|
@ -11,6 +11,21 @@ tap.test('should parse direct memory address param', (t) => {
|
||||
])
|
||||
})
|
||||
|
||||
tap.test('should parse alphanum param', (t) => {
|
||||
t.plan(1)
|
||||
const input = 'background3'
|
||||
t.deepEqual(mona.parse(parsers.alphanum(), input), [
|
||||
'alphanum',
|
||||
'background3'
|
||||
])
|
||||
})
|
||||
|
||||
tap.test('should not parse alphanum param if empty', (t) => {
|
||||
t.plan(1)
|
||||
const input = ''
|
||||
t.notOk(mona.parse(parsers.alphanum(), input))
|
||||
})
|
||||
|
||||
tap.test('should parse hex param', (t) => {
|
||||
t.plan(1)
|
||||
const input = '#$FF'
|
||||
@ -31,13 +46,10 @@ tap.test('should parse binary param', (t) => {
|
||||
|
||||
tap.test('should parse param', (t) => {
|
||||
t.plan(1)
|
||||
|
||||
const input = '#%00000001'
|
||||
t.deepEqual(mona.parse(parsers.parameter(), input), [
|
||||
[
|
||||
'binary',
|
||||
'00000001'
|
||||
]
|
||||
])
|
||||
})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user