From a8219ce68637183e4270cff9de0b7085577b8627 Mon Sep 17 00:00:00 2001 From: rowan Date: Fri, 18 Apr 2025 18:17:15 -0500 Subject: [PATCH] hold for now --- package-lock.json | 6 ++-- src/parser/attributes.js | 30 +++++++++++++++++++ src/parser/comments.js | 4 +-- src/parser/literal.js | 64 ++++++++++++++++++++++++++++++++-------- src/parser/token.js | 8 +++++ tests/units/index.js | 14 +++------ 6 files changed, 99 insertions(+), 27 deletions(-) create mode 100644 src/parser/attributes.js create mode 100644 src/parser/token.js diff --git a/package-lock.json b/package-lock.json index 95970d6..c85c79e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/src/parser/attributes.js b/src/parser/attributes.js new file mode 100644 index 0000000..62b56db --- /dev/null +++ b/src/parser/attributes.js @@ -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') + + diff --git a/src/parser/comments.js b/src/parser/comments.js index 9ff41c2..41c843b 100644 --- a/src/parser/comments.js +++ b/src/parser/comments.js @@ -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) ) diff --git a/src/parser/literal.js b/src/parser/literal.js index 847cf61..10d8fe7 100644 --- a/src/parser/literal.js +++ b/src/parser/literal.js @@ -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)) diff --git a/src/parser/token.js b/src/parser/token.js new file mode 100644 index 0000000..bacdbaf --- /dev/null +++ b/src/parser/token.js @@ -0,0 +1,8 @@ +export class Token { + _value + + constructor(value) { + this._value = value + } +} + diff --git a/tests/units/index.js b/tests/units/index.js index ea6a69a..46c1f40 100644 --- a/tests/units/index.js +++ b/tests/units/index.js @@ -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)) }) ]