Skip to content

Commit

Permalink
Fixed js.tree -> text
Browse files Browse the repository at this point in the history
  • Loading branch information
jin committed Jan 5, 2025
1 parent 037c7c3 commit 4917f91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 11 additions & 8 deletions tree2/js/to/text/text.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
namespace $ {

function is_identifier( tree: $mol_tree2 ) {
if( tree.type ) return false
return /^[a-z_$][a-z_$0-9]*$/i.test( tree.text() )
}

export function $mol_tree2_js_to_text( this: $, js: $mol_tree2 ) {

function sequence( open?: string, separator?: string, close?: string ) {
Expand Down Expand Up @@ -123,21 +128,19 @@ namespace $ {

'[]': ( input, belt )=> {
const first = input.kids[0]
if( first.type ) return sequence( '[', '', ']' )( input, belt )
if( !is_identifier( first ) ) return sequence( '[', '', ']' )( input, belt )
else return [ input.data( '.' + first.text() ) ]
},

'?.[]': ( input, belt )=> {
const first = input.kids[0]
if( first.type ) return sequence( '?.[', '', ']' )( input, belt )
if( !is_identifier( first ) ) return sequence( '?.[', '', ']' )( input, belt )
else return [ input.data( '?.' + first.text() ) ]
},

':': ( input, belt )=> {
const first = input.kids[0]
if( first.type ) return duplet( '[', ']: ' )( input, belt )
else return duplet( '', ': ' )( input, belt )
},
':': ( input, belt )=> input.kids[0].type
? duplet( '[', ']: ' )( input, belt )
: duplet( '', ': ' )( input, belt ),

'let': duplet( 'let ', ' = ' ),
'const': duplet( 'const ', ' = ' ),
Expand Down Expand Up @@ -174,7 +177,7 @@ namespace $ {

'.': ( input, belt )=> {
const first = input.kids[0]
if( first.type ) return triplet( '[', ']' )( input, belt )
if( !is_identifier( first ) ) return triplet( '[', ']' )( input, belt )
else return [
input.data( first.text() ),
... input.list( input.kids.slice(1) ).hack( belt ),
Expand Down
2 changes: 1 addition & 1 deletion wasm/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace $ {
native : WebAssembly.Module

constructor(
readonly buffer : ArrayBuffer
readonly buffer : Uint8Array
) {
super()
this.native = new WebAssembly.Module( buffer )
Expand Down

0 comments on commit 4917f91

Please sign in to comment.