1
0
mirror of https://github.com/emkay/parser-6502.git synced 2024-06-02 07:41:46 +00:00
parser-6502/parsers/parameters.js

85 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-10-02 21:54:14 +00:00
const mona = require('mona')
function quotedChar () {
2016-10-07 22:54:31 +00:00
return mona.or(
mona.noneOf('"'),
mona.and(
mona.string('""'),
mona.value('"')))
2016-10-07 17:45:55 +00:00
}
function bit () {
2016-10-11 04:08:37 +00:00
return mona.digit(2)
2016-10-07 17:45:55 +00:00
}
function string () {
2016-10-11 04:08:37 +00:00
return mona.between(
mona.string('"'),
mona.string('"'),
mona.text(quotedChar())
2016-10-07 17:45:55 +00:00
)
}
function hex () {
2016-10-11 04:08:37 +00:00
return mona.and(
mona.string('#$'),
mona.text(mona.digit(16))
2016-10-07 17:45:55 +00:00
)
}
function binary () {
2016-10-11 04:08:37 +00:00
return mona.and(
mona.maybe(mona.string('#')),
mona.string('%'),
mona.text(mona.digit(2))
2016-10-07 17:45:55 +00:00
)
}
function address () {
2016-10-11 04:08:37 +00:00
return mona.and(
mona.string('$'),
mona.text(mona.alphanum())
2016-10-07 17:45:55 +00:00
)
}
2016-10-02 21:54:14 +00:00
2016-10-07 22:54:31 +00:00
// this is the fallthrough parser
function alphanum () {
2016-10-11 04:08:37 +00:00
return mona.and(
mona.not(bit()),
mona.not(address()),
mona.not(binary()),
mona.not(hex()),
mona.not(string()),
mona.text(
mona.alphanum()
2016-10-07 17:45:55 +00:00
)
)
2016-10-02 21:54:14 +00:00
}
2016-10-07 22:54:31 +00:00
function parameter () {
return mona.or(
2016-10-11 04:08:37 +00:00
mona.tag(address(), 'address'),
mona.tag(binary(), 'binary'),
mona.tag(hex(), 'hex'),
mona.tag(string(), 'string'),
mona.tag(bit(), 'bit'),
mona.tag(alphanum(), 'alphanum')
2016-10-07 22:54:31 +00:00
)
}
2016-10-02 21:54:14 +00:00
function parameters () {
2016-10-07 22:54:31 +00:00
return mona.split(
parameter(),
mona.or(
mona.and(mona.string(','), mona.spaces()),
mona.string(','),
mona.spaces()
2016-10-02 21:54:14 +00:00
)
)
}
2016-10-07 17:45:55 +00:00
module.exports = {
parameter,
2016-10-11 04:08:37 +00:00
parameters
2016-10-07 17:45:55 +00:00
}