mirror of
https://github.com/emkay/parser-6502.git
synced 2024-12-30 12:31:29 +00:00
working
This commit is contained in:
parent
e86204609b
commit
dfe822b086
5
example/index.js
Normal file
5
example/index.js
Normal file
@ -0,0 +1,5 @@
|
||||
const fs = require('fs')
|
||||
const parser = require('.')
|
||||
const input = fs.readFileSync('./example.s', 'utf-8')
|
||||
const r = parser(input)
|
||||
console.log(r)
|
@ -22,9 +22,17 @@ function directiveName () {
|
||||
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 args = s(
|
||||
mona.maybe(
|
||||
mona.and(
|
||||
mona.spaces(),
|
||||
mona.followedBy(
|
||||
parameters(),
|
||||
mona.eol()
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
return mona.value({
|
||||
directive: d,
|
||||
|
@ -8,8 +8,8 @@ function quotedChar () {
|
||||
mona.value('"')))
|
||||
}
|
||||
|
||||
function bit () {
|
||||
return mona.digit(2)
|
||||
function digit () {
|
||||
return mona.text(mona.digit(), {min: 1})
|
||||
}
|
||||
|
||||
function string () {
|
||||
@ -45,7 +45,7 @@ function address () {
|
||||
// this is the fallthrough parser
|
||||
function alphanum () {
|
||||
return mona.and(
|
||||
mona.not(bit()),
|
||||
mona.not(digit()),
|
||||
mona.not(address()),
|
||||
mona.not(binary()),
|
||||
mona.not(hex()),
|
||||
@ -63,7 +63,7 @@ function parameter () {
|
||||
mona.tag(binary(), 'binary'),
|
||||
mona.tag(hex(), 'hex'),
|
||||
mona.tag(string(), 'string'),
|
||||
mona.tag(bit(), 'bit'),
|
||||
mona.tag(digit(), 'digit'),
|
||||
mona.tag(alphanum(), 'alphanum')
|
||||
)
|
||||
}
|
||||
@ -71,11 +71,7 @@ function parameter () {
|
||||
function parameters () {
|
||||
return mona.split(
|
||||
parameter(),
|
||||
mona.or(
|
||||
mona.and(mona.string(','), mona.spaces()),
|
||||
mona.string(','),
|
||||
mona.spaces()
|
||||
)
|
||||
mona.trim(mona.string(','))
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ tap.test('will parse a directive', (t) => {
|
||||
t.deepEqual(mona.parse(directiveParser(), '.inesprg 1\n'), {
|
||||
args: [
|
||||
{
|
||||
'bit': '1'
|
||||
'digit': '1'
|
||||
}
|
||||
],
|
||||
directive: '.inesprg'
|
||||
|
@ -10,6 +10,14 @@ tap.test('should parse direct memory address param', (t) => {
|
||||
})
|
||||
})
|
||||
|
||||
tap.test('should parse decimal param', (t) => {
|
||||
t.plan(1)
|
||||
const input = '17'
|
||||
t.deepEqual(mona.parse(parsers.parameter(), input), {
|
||||
'digit': '17'
|
||||
})
|
||||
})
|
||||
|
||||
tap.test('should parse alphanum param', (t) => {
|
||||
t.plan(1)
|
||||
const input = 'background3'
|
||||
|
Loading…
Reference in New Issue
Block a user