mirror of
https://github.com/emkay/parser-6502.git
synced 2025-01-14 22:30:59 +00:00
new line fixes
This commit is contained in:
parent
353bab4dfd
commit
3a52f4399c
@ -19,13 +19,12 @@ function directiveName () {
|
|||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
// <directive> ::= <directive-name> [<spaces> <parameter>]*
|
|
||||||
function directive () {
|
function directive () {
|
||||||
return mona.sequence((s) => {
|
return mona.sequence((s) => {
|
||||||
const d = s(directiveName())
|
const d = s(directiveName())
|
||||||
const space = s(mona.spaces())
|
const space = s(mona.spaces())
|
||||||
const args = s(parameters())
|
const args = s(parameters())
|
||||||
// const nl = s(mona.eol())
|
const nl = s(mona.eol())
|
||||||
|
|
||||||
return mona.value({
|
return mona.value({
|
||||||
directive: d,
|
directive: d,
|
||||||
|
@ -25,9 +25,15 @@ function instructionName () {
|
|||||||
function instruction () {
|
function instruction () {
|
||||||
return mona.sequence((s) => {
|
return mona.sequence((s) => {
|
||||||
const i = s(instructionName())
|
const i = s(instructionName())
|
||||||
const space = s(mona.maybe(mona.spaces()))
|
const args = s(
|
||||||
const args = s(mona.maybe(parameters()))
|
mona.maybe(
|
||||||
// const nl = s(mona.eol())
|
mona.and(
|
||||||
|
mona.spaces(),
|
||||||
|
parameters()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
const nl = s(mona.eol())
|
||||||
return mona.value({
|
return mona.value({
|
||||||
instruction: i,
|
instruction: i,
|
||||||
args: args
|
args: args
|
||||||
|
@ -2,12 +2,16 @@ const mona = require('mona')
|
|||||||
|
|
||||||
function label () {
|
function label () {
|
||||||
return mona.sequence((s) => {
|
return mona.sequence((s) => {
|
||||||
const label = s(mona.text(mona.alphanum()))
|
const label = s(
|
||||||
const end = s(mona.string(':'))
|
mona.followedBy(
|
||||||
// const nl = s(mona.eol())
|
mona.text(mona.alphanum(), {min: 1}),
|
||||||
|
mona.string(':'),
|
||||||
|
mona.eol()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
return mona.value({
|
return mona.value({
|
||||||
label: `${label}${end}`
|
label
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -16,14 +16,14 @@ function string () {
|
|||||||
return mona.between(
|
return mona.between(
|
||||||
mona.string('"'),
|
mona.string('"'),
|
||||||
mona.string('"'),
|
mona.string('"'),
|
||||||
mona.text(quotedChar())
|
mona.text(quotedChar(), {min: 1})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function hex () {
|
function hex () {
|
||||||
return mona.and(
|
return mona.and(
|
||||||
mona.string('#$'),
|
mona.string('#$'),
|
||||||
mona.text(mona.digit(16))
|
mona.text(mona.digit(16), {min: 1})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,14 +31,14 @@ function binary () {
|
|||||||
return mona.and(
|
return mona.and(
|
||||||
mona.maybe(mona.string('#')),
|
mona.maybe(mona.string('#')),
|
||||||
mona.string('%'),
|
mona.string('%'),
|
||||||
mona.text(mona.digit(2))
|
mona.text(mona.digit(2), {min: 1})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function address () {
|
function address () {
|
||||||
return mona.and(
|
return mona.and(
|
||||||
mona.string('$'),
|
mona.string('$'),
|
||||||
mona.text(mona.alphanum())
|
mona.text(mona.alphanum(), {min: 1})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +51,8 @@ function alphanum () {
|
|||||||
mona.not(hex()),
|
mona.not(hex()),
|
||||||
mona.not(string()),
|
mona.not(string()),
|
||||||
mona.text(
|
mona.text(
|
||||||
mona.alphanum()
|
mona.alphanum(),
|
||||||
|
{min: 1}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ tap.test('should parse the basics', (t) => {
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'RESET:'
|
label: 'RESET'
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
@ -4,7 +4,7 @@ const directiveParser = require('../parsers/directive')
|
|||||||
|
|
||||||
tap.test('will parse a directive', (t) => {
|
tap.test('will parse a directive', (t) => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(directiveParser(), '.inesprg 1'), {
|
t.deepEqual(mona.parse(directiveParser(), '.inesprg 1\n'), {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
'bit': '1'
|
'bit': '1'
|
||||||
@ -16,7 +16,7 @@ tap.test('will parse a directive', (t) => {
|
|||||||
|
|
||||||
tap.test('will parse a directive with direct address', (t) => {
|
tap.test('will parse a directive with direct address', (t) => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(directiveParser(), '.inesprg $0000'), {
|
t.deepEqual(mona.parse(directiveParser(), '.inesprg $0000\n'), {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
'address': '0000'
|
'address': '0000'
|
||||||
@ -28,7 +28,7 @@ tap.test('will parse a directive with direct address', (t) => {
|
|||||||
|
|
||||||
tap.test('will parse a directive with hex arg', (t) => {
|
tap.test('will parse a directive with hex arg', (t) => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(directiveParser(), '.inesprg #$FE'), {
|
t.deepEqual(mona.parse(directiveParser(), '.inesprg #$FE\n'), {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
'hex': 'FE'
|
'hex': 'FE'
|
||||||
@ -40,7 +40,7 @@ tap.test('will parse a directive with hex arg', (t) => {
|
|||||||
|
|
||||||
tap.test('will parse a directive with binary arg', (t) => {
|
tap.test('will parse a directive with binary arg', (t) => {
|
||||||
t.plan(2)
|
t.plan(2)
|
||||||
t.deepEqual(mona.parse(directiveParser(), '.db %00010001'), {
|
t.deepEqual(mona.parse(directiveParser(), '.db %00010001\n'), {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
'binary': '00010001'
|
'binary': '00010001'
|
||||||
@ -49,7 +49,7 @@ tap.test('will parse a directive with binary arg', (t) => {
|
|||||||
directive: '.db'
|
directive: '.db'
|
||||||
})
|
})
|
||||||
|
|
||||||
t.deepEqual(mona.parse(directiveParser(), '.db #%00010001'), {
|
t.deepEqual(mona.parse(directiveParser(), '.db #%00010001\n'), {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
'binary': '00010001'
|
'binary': '00010001'
|
||||||
@ -61,7 +61,7 @@ tap.test('will parse a directive with binary arg', (t) => {
|
|||||||
|
|
||||||
tap.test('will parse a directive with multiple args', (t) => {
|
tap.test('will parse a directive with multiple args', (t) => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(directiveParser(), '.db %00010001,%00010001,%00010001'), {
|
t.deepEqual(mona.parse(directiveParser(), '.db %00010001,%00010001,%00010001\n'), {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
'binary': '00010001'
|
'binary': '00010001'
|
||||||
@ -79,7 +79,7 @@ tap.test('will parse a directive with multiple args', (t) => {
|
|||||||
|
|
||||||
tap.test('will parse a directive with multiple args with spaces between them', (t) => {
|
tap.test('will parse a directive with multiple args with spaces between them', (t) => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(directiveParser(), '.db %00010001, %00010001, %00010001'), {
|
t.deepEqual(mona.parse(directiveParser(), '.db %00010001, %00010001, %00010001\n'), {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
'binary': '00010001'
|
'binary': '00010001'
|
||||||
@ -97,7 +97,7 @@ tap.test('will parse a directive with multiple args with spaces between them', (
|
|||||||
|
|
||||||
tap.test('will parse a directive with string arg', (t) => {
|
tap.test('will parse a directive with string arg', (t) => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(directiveParser(), '.incbin "mario.chr"'), {
|
t.deepEqual(mona.parse(directiveParser(), '.incbin "mario.chr"\n'), {
|
||||||
args: [
|
args: [
|
||||||
{
|
{
|
||||||
'string': 'mario.chr'
|
'string': 'mario.chr'
|
||||||
|
@ -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: null,
|
args: [],
|
||||||
instruction: 'sei'
|
instruction: 'sei'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -14,10 +14,9 @@ tap.test('will parse an instruction with args', (t) => {
|
|||||||
t.plan(1)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(instructionParser(), 'stx $2000\n'), {
|
t.deepEqual(mona.parse(instructionParser(), 'stx $2000\n'), {
|
||||||
args: [
|
args: [
|
||||||
[
|
{
|
||||||
'address',
|
'address': '2000'
|
||||||
'2000'
|
}
|
||||||
]
|
|
||||||
],
|
],
|
||||||
instruction: 'stx'
|
instruction: 'stx'
|
||||||
})
|
})
|
||||||
@ -26,7 +25,14 @@ tap.test('will parse an instruction with args', (t) => {
|
|||||||
tap.test('will parse an instruction with multiple args', (t) => {
|
tap.test('will parse an instruction with multiple args', (t) => {
|
||||||
t.plan(1)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(instructionParser(), 'lda background3, x\n'), {
|
t.deepEqual(mona.parse(instructionParser(), 'lda background3, x\n'), {
|
||||||
args: ['background3', 'x'],
|
args: [
|
||||||
|
{
|
||||||
|
'alphanum': 'background3'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'alphanum': 'x'
|
||||||
|
}
|
||||||
|
],
|
||||||
instruction: 'lda'
|
instruction: 'lda'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -3,8 +3,8 @@ const mona = require('mona')
|
|||||||
const labelParser = require('../parsers/label')
|
const labelParser = require('../parsers/label')
|
||||||
|
|
||||||
tap.test('should parse a label', (t) => {
|
tap.test('should parse a label', (t) => {
|
||||||
t.plan(2)
|
t.plan(1)
|
||||||
t.deepEqual(mona.parse(labelParser(), 'SOMETHING:'), {
|
t.deepEqual(mona.parse(labelParser(), 'SOMETHING:\n'), {
|
||||||
label: 'SOMETHING:'
|
label: 'SOMETHING'
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user