parser-6502/parsers/parameters.js

82 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
}
2016-10-12 23:41:28 +00:00
function digit () {
return mona.text(mona.digit(), {min: 1})
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('"'),
2016-10-12 00:01:15 +00:00
mona.text(quotedChar(), {min: 1})
2016-10-07 17:45:55 +00:00
)
}
function hex () {
2016-10-11 04:08:37 +00:00
return mona.and(
mona.string('#$'),
2016-10-12 00:01:15 +00:00
mona.text(mona.digit(16), {min: 1})
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('%'),
2016-10-12 00:01:15 +00:00
mona.text(mona.digit(2), {min: 1})
2016-10-07 17:45:55 +00:00
)
}
function address () {
2016-10-11 04:08:37 +00:00
return mona.and(
mona.string('$'),
2016-10-12 00:01:15 +00:00
mona.text(mona.alphanum(), {min: 1})
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(
2016-10-12 23:41:28 +00:00
mona.not(digit()),
2016-10-11 04:08:37 +00:00
mona.not(address()),
mona.not(binary()),
mona.not(hex()),
mona.not(string()),
mona.text(
2016-10-12 00:01:15 +00:00
mona.alphanum(),
{min: 1}
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'),
2016-10-12 23:41:28 +00:00
mona.tag(digit(), 'digit'),
2016-10-11 04:08:37 +00:00
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(),
2016-10-12 23:41:28 +00:00
mona.trim(mona.string(','))
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
}