new line fixes

This commit is contained in:
Michael Matuzak 2016-10-11 17:01:15 -07:00
parent 353bab4dfd
commit 3a52f4399c
8 changed files with 48 additions and 32 deletions

View File

@ -19,13 +19,12 @@ function directiveName () {
])
}
// <directive> ::= <directive-name> [<spaces> <parameter>]*
function directive () {
return mona.sequence((s) => {
const d = s(directiveName())
const space = s(mona.spaces())
const args = s(parameters())
// const nl = s(mona.eol())
const nl = s(mona.eol())
return mona.value({
directive: d,

View File

@ -25,9 +25,15 @@ function instructionName () {
function instruction () {
return mona.sequence((s) => {
const i = s(instructionName())
const space = s(mona.maybe(mona.spaces()))
const args = s(mona.maybe(parameters()))
// const nl = s(mona.eol())
const args = s(
mona.maybe(
mona.and(
mona.spaces(),
parameters()
)
)
)
const nl = s(mona.eol())
return mona.value({
instruction: i,
args: args

View File

@ -2,12 +2,16 @@ const mona = require('mona')
function label () {
return mona.sequence((s) => {
const label = s(mona.text(mona.alphanum()))
const end = s(mona.string(':'))
// const nl = s(mona.eol())
const label = s(
mona.followedBy(
mona.text(mona.alphanum(), {min: 1}),
mona.string(':'),
mona.eol()
)
)
return mona.value({
label: `${label}${end}`
label
})
})
}

View File

@ -16,14 +16,14 @@ function string () {
return mona.between(
mona.string('"'),
mona.string('"'),
mona.text(quotedChar())
mona.text(quotedChar(), {min: 1})
)
}
function hex () {
return mona.and(
mona.string('#$'),
mona.text(mona.digit(16))
mona.text(mona.digit(16), {min: 1})
)
}
@ -31,14 +31,14 @@ function binary () {
return mona.and(
mona.maybe(mona.string('#')),
mona.string('%'),
mona.text(mona.digit(2))
mona.text(mona.digit(2), {min: 1})
)
}
function address () {
return mona.and(
mona.string('$'),
mona.text(mona.alphanum())
mona.text(mona.alphanum(), {min: 1})
)
}
@ -51,7 +51,8 @@ function alphanum () {
mona.not(hex()),
mona.not(string()),
mona.text(
mona.alphanum()
mona.alphanum(),
{min: 1}
)
)
}

View File

@ -15,7 +15,7 @@ tap.test('should parse the basics', (t) => {
]
},
{
label: 'RESET:'
label: 'RESET'
}
])
})

View File

@ -4,7 +4,7 @@ const directiveParser = require('../parsers/directive')
tap.test('will parse a directive', (t) => {
t.plan(1)
t.deepEqual(mona.parse(directiveParser(), '.inesprg 1'), {
t.deepEqual(mona.parse(directiveParser(), '.inesprg 1\n'), {
args: [
{
'bit': '1'
@ -16,7 +16,7 @@ tap.test('will parse a directive', (t) => {
tap.test('will parse a directive with direct address', (t) => {
t.plan(1)
t.deepEqual(mona.parse(directiveParser(), '.inesprg $0000'), {
t.deepEqual(mona.parse(directiveParser(), '.inesprg $0000\n'), {
args: [
{
'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) => {
t.plan(1)
t.deepEqual(mona.parse(directiveParser(), '.inesprg #$FE'), {
t.deepEqual(mona.parse(directiveParser(), '.inesprg #$FE\n'), {
args: [
{
'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) => {
t.plan(2)
t.deepEqual(mona.parse(directiveParser(), '.db %00010001'), {
t.deepEqual(mona.parse(directiveParser(), '.db %00010001\n'), {
args: [
{
'binary': '00010001'
@ -49,7 +49,7 @@ tap.test('will parse a directive with binary arg', (t) => {
directive: '.db'
})
t.deepEqual(mona.parse(directiveParser(), '.db #%00010001'), {
t.deepEqual(mona.parse(directiveParser(), '.db #%00010001\n'), {
args: [
{
'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) => {
t.plan(1)
t.deepEqual(mona.parse(directiveParser(), '.db %00010001,%00010001,%00010001'), {
t.deepEqual(mona.parse(directiveParser(), '.db %00010001,%00010001,%00010001\n'), {
args: [
{
'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) => {
t.plan(1)
t.deepEqual(mona.parse(directiveParser(), '.db %00010001, %00010001, %00010001'), {
t.deepEqual(mona.parse(directiveParser(), '.db %00010001, %00010001, %00010001\n'), {
args: [
{
'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) => {
t.plan(1)
t.deepEqual(mona.parse(directiveParser(), '.incbin "mario.chr"'), {
t.deepEqual(mona.parse(directiveParser(), '.incbin "mario.chr"\n'), {
args: [
{
'string': 'mario.chr'

View File

@ -5,7 +5,7 @@ const instructionParser = require('../parsers/instruction')
tap.test('will parse an instruction', (t) => {
t.plan(1)
t.deepEqual(mona.parse(instructionParser(), 'sei\n'), {
args: null,
args: [],
instruction: 'sei'
})
})
@ -14,10 +14,9 @@ tap.test('will parse an instruction with args', (t) => {
t.plan(1)
t.deepEqual(mona.parse(instructionParser(), 'stx $2000\n'), {
args: [
[
'address',
'2000'
]
{
'address': '2000'
}
],
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) => {
t.plan(1)
t.deepEqual(mona.parse(instructionParser(), 'lda background3, x\n'), {
args: ['background3', 'x'],
args: [
{
'alphanum': 'background3'
},
{
'alphanum': 'x'
}
],
instruction: 'lda'
})
})

View File

@ -3,8 +3,8 @@ const mona = require('mona')
const labelParser = require('../parsers/label')
tap.test('should parse a label', (t) => {
t.plan(2)
t.deepEqual(mona.parse(labelParser(), 'SOMETHING:'), {
label: 'SOMETHING:'
t.plan(1)
t.deepEqual(mona.parse(labelParser(), 'SOMETHING:\n'), {
label: 'SOMETHING'
})
})