1
0
mirror of https://github.com/emkay/parser-6502.git synced 2025-01-17 10:30:18 +00:00
parser-6502/parsers/parameters.js

82 lines
1.3 KiB
JavaScript
Raw Normal View History

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