hold for now
This commit is contained in:
parent
da9d6680f8
commit
a8219ce686
6 changed files with 99 additions and 27 deletions
6
package-lock.json
generated
6
package-lock.json
generated
|
@ -458,13 +458,13 @@
|
|||
},
|
||||
"node_modules/folktest": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "git+https://git.kitsu.cafe/rowan/folktest.git#708d44f1215be33fcceba426029f44b4f963dbe5",
|
||||
"resolved": "git+https://git.kitsu.cafe/rowan/folktest.git#cbf48ff3b1334eb883f202a77a5bc89d24534520",
|
||||
"dev": true,
|
||||
"license": "GPL-3.0-or-later"
|
||||
},
|
||||
"node_modules/izuna": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "git+https://git.kitsu.cafe/rowan/izuna.git#e11a0870c27eeb5ea1a4ae3fedccca008eda15c2",
|
||||
"resolved": "git+https://git.kitsu.cafe/rowan/izuna.git#4ab7c265d83856f2dc527780a3ac87b3d54676f1",
|
||||
"license": "GPL-3.0-or-later"
|
||||
},
|
||||
"node_modules/kojima": {
|
||||
|
@ -479,7 +479,7 @@
|
|||
},
|
||||
"node_modules/kuebiko": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "git+https://git.kitsu.cafe/rowan/kuebiko.git#81a33e4a98bf766dc08eb31adc04c35cec9685ab",
|
||||
"resolved": "git+https://git.kitsu.cafe/rowan/kuebiko.git#0ae5676c63df960dd6089a054a29212467aec397",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"izuna": "git+https://git.kitsu.cafe/rowan/izuna.git",
|
||||
|
|
30
src/parser/attributes.js
Normal file
30
src/parser/attributes.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import { any, manymn } from 'kuebiko'
|
||||
import { integerLiteral } from './literal'
|
||||
|
||||
const powOf = curry((y, x) => {
|
||||
const result = Math.log(y) / Math.log(x)
|
||||
return result === Math.floor(result)
|
||||
})
|
||||
|
||||
const decorator = name => seq(char('@'), name)
|
||||
|
||||
const align = tag('align')
|
||||
|
||||
const binding = tag('binding')
|
||||
const builtin = tag('builtin')
|
||||
const compute = tag('compute')
|
||||
const constant = tag('const')
|
||||
const diagnostic = tag('diagnostic')
|
||||
const fragment = tag('fragment')
|
||||
const group = tag('group')
|
||||
const id = tag('id')
|
||||
const interpolate = tag('interpolate')
|
||||
const invariant = tag('invariant')
|
||||
const location = tag('location')
|
||||
const blend_src = tag('blend_src')
|
||||
const must_use = tag('must_use')
|
||||
const size = tag('size')
|
||||
const vertex = tag('vertex')
|
||||
const workgroup_size = tag('workgroup_size')
|
||||
|
||||
|
|
@ -4,12 +4,12 @@ import { char, until } from 'kuebiko'
|
|||
const slash = char('\u002f')
|
||||
const asterisk = char('\u002a')
|
||||
|
||||
const comment = seq(slash, slash)
|
||||
export const lineComment = seq(slash, slash)
|
||||
|
||||
const blockCommentStart = seq(slash, asterisk)
|
||||
const blockCommentEnd = seq(asterisk, slash)
|
||||
|
||||
const blockComment = seq(
|
||||
export const blockComment = seq(
|
||||
blockCommentStart,
|
||||
until(blockCommentEnd)
|
||||
)
|
||||
|
|
|
@ -1,29 +1,68 @@
|
|||
import { any, anyOf, digit, many, maybe, seq, str } from 'kuebiko'
|
||||
import { any, char, oneOf, digit, many, map, maybe, not, seq, tag } from 'kuebiko'
|
||||
import { Token } from './token.js'
|
||||
|
||||
export class Literal extends Token {
|
||||
constructor(value) {
|
||||
super(value)
|
||||
}
|
||||
}
|
||||
|
||||
export class BooleanLiteral extends Token {
|
||||
static from(value) {
|
||||
return new BooleanLiteral(value)
|
||||
}
|
||||
}
|
||||
|
||||
export class IntegerLiteral extends Token {
|
||||
_dataType
|
||||
_system
|
||||
|
||||
constructor(value, type, system) {
|
||||
super(value)
|
||||
this._dataType = type
|
||||
this._system = system
|
||||
}
|
||||
}
|
||||
|
||||
class Signed {
|
||||
static Signed = new Signed(true)
|
||||
static Unsigned = new Signed(false)
|
||||
_value
|
||||
|
||||
constructor(value) {
|
||||
this._value = value
|
||||
}
|
||||
}
|
||||
|
||||
export const iu = any(
|
||||
map(() => Signed.Signed, char('i')),
|
||||
map(() => Signed.Unsigned, char('u'))
|
||||
)
|
||||
|
||||
const iu = anyOf('iu')
|
||||
const decimal = char('.')
|
||||
const sign = anyOf('+-')
|
||||
const e = anyOf('eE')
|
||||
const p = anyOf('pP')
|
||||
const fh = anyOf('fh')
|
||||
const sign = oneOf('+-')
|
||||
const e = oneOf('eE')
|
||||
const p = oneOf('pP')
|
||||
const fh = oneOf('fh')
|
||||
|
||||
export const zero = char('0')
|
||||
export const digits = many(digit)
|
||||
|
||||
export const booleanLiteral = any(str('true'), str('false'))
|
||||
export const booleanLiteral = any(
|
||||
map(BooleanLiteral.from, tag('true')),
|
||||
map(BooleanLiteral.from, tag('false')),
|
||||
)
|
||||
|
||||
export const decimalIntLiteral = any(
|
||||
zero,
|
||||
seq(
|
||||
not(zero),
|
||||
digits,
|
||||
maybe(iu)
|
||||
)
|
||||
)
|
||||
|
||||
const hexDigit = any(digit, anyOf('abcdef'), anyOf('ABCDEF'))
|
||||
const hexDigit = any(digit, oneOf('abcdef'), oneOf('ABCDEF'))
|
||||
|
||||
const hexPrefix = seq(zero, anyOf('xX'))
|
||||
const hexPrefix = seq(zero, oneOf('xX'))
|
||||
|
||||
const hexIntLiteral = seq(
|
||||
hexPrefix,
|
||||
|
@ -32,12 +71,13 @@ const hexIntLiteral = seq(
|
|||
)
|
||||
|
||||
export const integerLiteral = any(
|
||||
zero,
|
||||
decimalIntLiteral,
|
||||
hexIntLiteral
|
||||
)
|
||||
|
||||
|
||||
const nonzeroDigit = anyOf('123456789')
|
||||
const nonzeroDigit = oneOf('123456789')
|
||||
|
||||
const many1 = parser => seq(parser, many(parser))
|
||||
|
||||
|
|
8
src/parser/token.js
Normal file
8
src/parser/token.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
export class Token {
|
||||
_value
|
||||
|
||||
constructor(value) {
|
||||
this._value = value
|
||||
}
|
||||
}
|
||||
|
|
@ -1,17 +1,11 @@
|
|||
import { it, assert } from 'folktest'
|
||||
import { ident } from '../../src/parser/keyword.js'
|
||||
import { booleanLiteral, iu } from '../../src/parser/literal.js'
|
||||
import { parse } from 'kuebiko'
|
||||
|
||||
export const Tests = [
|
||||
it('whatever', () => {
|
||||
const pass1 = 'test1'
|
||||
const pass2 = '_Test2'
|
||||
const fail1 = '_'
|
||||
const fail2 = '__test'
|
||||
const fail3 = 'default'
|
||||
|
||||
console.log(
|
||||
ident
|
||||
)
|
||||
console.log(parse(iu, 'i').chain(x => x))
|
||||
console.log(parse(booleanLiteral, 'false').chain(x => x))
|
||||
})
|
||||
]
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue