Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support variable parameters and printf() sprintf() #15

Merged
merged 6 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions GScript.g4
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ FLOAT_LITERAL: (Digits '.' Digits? | '.' Digits) ExponentPart? [fFdD]?
| Digits (ExponentPart [fFdD]? | [fFdD])
;

ELLIPSIS: '...';

// Whitespace and comments

WS: [ \t\r\n\u000C]+ -> channel(HIDDEN);
Expand Down
18 changes: 18 additions & 0 deletions array_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,21 @@ println(args);
`
NewCompiler().Compiler(script)
}

func Test_array14(t *testing.T) {
script := `
int[] a={1,2,3};
println(a);
println();
append(a,4);
int b = a[3];
assertEqual(4, b);
println(a);
for(int i=0;i<len(a);i++){
println(a[i]);
int temp = a[i];
assertEqual(temp, i+1);
}
`
NewCompiler().Compiler(script)
}
2 changes: 1 addition & 1 deletion internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func internal_internal_go() ([]byte, error) {
)
}

var _internal_internal_gs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x56\x4d\x6f\x1c\x45\x10\xbd\xef\xaf\x28\x2c\x11\xcd\xca\xd6\x2e\xb9\xc0\xc1\x9a\x03\x84\x24\x56\xe4\x24\x60\x47\x5c\xac\x3d\x74\x76\x6a\x77\x3a\x3b\xdb\x33\xee\xee\x19\xbc\x5e\xad\x84\xe0\xc4\x29\x12\x88\x1f\x80\xc4\x01\x2e\x5c\xe0\xc2\x85\x7f\x63\x2b\xfc\x0b\x54\xd5\x3d\x3b\x3d\x1f\x96\x95\x5b\x7c\xb0\x76\xba\x5f\xbd\x7a\xfd\xfa\x75\xcf\x4c\xa7\xa0\xd1\x96\x5a\x81\xd0\x5a\x6c\x20\x43\xb5\xb4\xe9\x48\x2a\x4b\x3f\x23\xa1\x36\x17\x33\x10\xe3\xed\x6e\x34\x6a\xa0\xa9\x30\xe9\x3c\x4f\x90\x61\xf4\x40\x38\x30\x8c\x2a\xb4\x54\x36\x53\x11\x3d\x08\x63\x50\xdb\xc7\x97\xa5\xc8\xdc\x73\x51\xa0\x4a\xa2\x9a\xed\x4b\x61\x71\x64\xac\x96\x6a\x09\x4b\xb4\x8f\x4a\xad\x51\xd9\x57\x72\x8d\x91\x1f\xb5\xd7\x47\xe0\x7f\x66\x62\x93\x97\xb6\x2e\x7d\x8a\x16\x72\x03\x42\x2f\xcd\xc4\x53\x5c\xcc\x88\xe4\xe5\xf9\xe7\x7a\x69\xa2\x8e\xe0\x67\xe7\x2f\x5f\x78\xa2\xba\x21\x0d\xb1\x6c\x5e\xdc\x74\xea\x30\x97\x25\xea\x0d\x7c\x2b\x6d\x0a\x85\xb0\xe9\x88\x00\x34\xf1\x14\x6d\xad\xe9\x8d\xc9\xd5\x5e\x15\x81\xb8\x17\x31\xa4\xd6\x16\x90\xc9\xd7\xf4\xfb\x0c\x4d\x91\x2b\x83\x0c\x1f\x3d\x61\x57\x16\xdc\x93\x3c\x23\xf3\x5a\x1c\xfb\x07\x82\x7b\x41\x67\x68\x98\x21\xb5\xeb\xac\x66\x38\x79\xf5\xfc\xf4\x1e\x06\x82\xd7\xcb\xa7\x09\x88\x34\x66\xc2\xca\x0a\xf9\xd1\xc0\x5a\x6c\x20\x5f\x4b\xda\x60\x91\x50\x85\xc9\x84\x49\xc7\xb5\x31\x5f\x93\x05\x5f\x09\x9b\x46\xdd\x35\xfa\xe7\x27\xb9\x5e\x7f\x23\xb2\x12\xa3\xa1\xf6\x2b\xdc\x10\x78\x9e\x09\x63\xe0\xc4\xda\xe2\x51\xae\x2c\x5e\xd9\xed\x08\x00\x42\xc1\xc7\x3c\xd0\xb1\x84\xfc\xae\xc6\x0e\x1b\xe0\xc9\x15\x88\x1d\xb8\x1a\x1f\xef\xa7\x43\x5f\x1d\x81\xd3\xc2\x2e\x3a\xd8\x8e\xff\x77\x7c\x73\x6d\xa0\xd7\x87\xbc\x83\x18\xaa\x5e\x07\xae\x0f\x3b\xb0\xcb\x61\x07\xcf\x70\xb9\x77\x6f\x80\xbe\x80\x38\xb0\x97\x7d\x6d\x3a\xf9\xa8\x16\x35\x69\xc8\xba\xe8\x5a\xce\x2e\x77\xe9\x2b\x88\x83\xcd\x71\x3a\x09\xd8\xeb\x51\xd5\x3d\x38\x67\x5f\x48\x95\x80\xce\x4b\x8b\x23\x4a\xf0\x89\x50\x49\xb6\x6f\xb4\x46\x9b\xe6\x49\x27\x69\x8b\x52\xcd\x21\x0a\x36\x77\x0c\x29\x57\x79\x4d\x94\x3c\x7f\x0d\x1c\x50\x45\x7c\x70\x18\x2c\x36\xa8\x83\xb9\xbd\x82\x38\x1c\x89\x3c\xc8\xf1\x45\x73\x7b\x35\x3e\x76\x32\xcf\x4a\xe5\x4e\x98\x41\x5d\xa1\x9e\xb0\xd8\xb3\x52\xd5\x4a\x45\x92\x68\x8e\xa9\x8b\xde\x63\x65\xf5\xc6\xc9\xa1\xdd\x5e\xe1\xe6\xa8\x22\x5f\x1c\x3d\xcf\x82\xc2\x2b\x1b\x3c\xf3\x75\xb0\xf2\xe9\x38\xaa\x31\x81\xcf\x2b\xdc\xc4\xab\xc6\x4d\xe6\x8b\x83\xb0\x10\x5f\xac\x1a\x73\x9d\x92\xe7\xa2\xd8\x36\x4d\x2e\x66\x60\xc5\xeb\x0c\x21\x86\x8b\x87\x9f\xce\xb6\x3b\x07\xa7\x6c\x1a\x79\x8d\xf1\x27\xc7\x6e\xe7\x8b\xd2\x46\xb5\x70\xa7\x88\xba\x05\x62\xa6\x53\xb0\x79\x92\xc3\x5c\xe7\xc6\xe4\x15\xea\x67\x12\xe1\xf6\xc7\x3f\x6e\xfe\xfc\x67\x8f\x91\x8b\x88\x34\xc7\x07\x07\x41\x61\x13\x84\x46\xf9\xae\x29\xf1\x57\x3a\x85\x1d\x62\x77\xbb\xb7\x43\x44\x08\xe9\xa7\x18\xf5\x31\xbf\x2a\x78\x55\x63\x68\x70\xce\x3f\x22\xe1\xa9\x0b\x39\x0b\x38\x16\x10\x21\x7c\x14\x83\x92\x59\x47\x9a\x2b\xb3\xb8\x2e\xdc\xaf\x18\xf0\xb8\x05\x58\xe4\x1a\xa2\x66\xde\x93\x40\x9b\xa5\x16\x3a\x77\x2f\x95\x13\x61\xd2\x7a\x35\xfb\xd2\x49\x7b\x5d\xa1\xb6\x56\x59\xb0\xd4\x07\x0f\x68\x43\x68\xa8\xcd\xd2\x6f\x4e\x7f\x0d\xc6\x45\x05\x82\x04\x76\xff\xba\x3b\xd2\xdf\x99\x1e\x2b\x84\x2a\x9a\x2c\x0f\x57\xd6\x7b\x00\xb1\x0f\x3b\x07\x8b\x05\x1d\x01\x76\x6c\xa0\x24\x1e\x1e\xfa\x24\x32\x17\x60\x66\xb0\xe3\xf1\x74\x0a\x37\x6f\xbf\x7f\xf7\xdd\x0f\xf0\x26\x59\x3d\x9c\x7c\x06\xff\xfd\xfc\xef\xbb\x5f\x7f\xbf\xf9\xed\xef\xdb\xb7\x3f\xdd\xfe\xf5\xcb\xfd\xfd\x5d\x7b\xda\xbe\xe1\xfe\xcd\x52\xc2\x4b\x91\x4e\xc3\x12\xf7\xc7\x23\x30\xff\x83\xcd\x3b\x67\x16\x79\x93\x86\x53\x7f\x47\x56\x71\x20\xa3\x94\x4f\x1f\x42\x9e\xa6\x50\xde\x91\xd7\x81\x5c\xfa\x57\x00\x4e\x06\xb2\xd8\x4e\x0c\xad\x04\x3b\xb9\xda\xb5\x4e\x70\x20\xb1\x75\x4a\x82\x63\x82\x03\xc7\xe3\x2e\x09\xbb\x81\x8c\x79\xac\x92\x59\x57\x84\x0f\x03\x19\xb7\x44\x7b\x2e\xaf\x31\x0a\xfa\xf8\x3a\x0a\x52\x73\x1f\xf3\x37\xd1\xa9\x54\x2b\x4c\x4e\xa5\xb1\xfe\x7e\x76\x03\x2f\xf2\x04\x9b\xd7\x45\xa0\xac\x99\x0e\xde\x17\xcd\x60\xd4\xfd\x64\xe1\xd2\xf6\x47\x04\x6f\x7b\x0c\xbd\x37\x43\x23\x65\xdb\x6d\xb5\x90\xda\xd8\x23\xc8\x84\xb1\x77\xbc\x20\x44\x92\xf4\x7a\xd3\xa6\x54\x64\xfb\x7b\x1c\x80\xa0\x29\x7d\xfb\x04\x2b\x0b\xbf\xb4\x88\x99\x35\x11\x7b\x3f\xbe\x7e\x0a\xb2\x76\xa0\x48\x7e\x7b\xd4\x5d\x24\xdb\x1e\x6a\xe2\x3d\xba\x9f\xa0\x77\x51\xc0\xc0\x4d\x91\x94\xeb\x22\x8c\x43\xb0\x48\x63\x85\x26\x4e\x96\xdc\x39\xa1\x6e\x6e\xf0\x80\xd6\x1f\x34\x0c\x71\xc9\xed\x5e\x5a\x9e\xd8\x21\x86\xce\xcd\xfb\x47\xf6\xff\x00\x00\x00\xff\xff\x26\xfa\x98\xc4\x9f\x0d\x00\x00")
var _internal_internal_gs = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xcc\x56\xbf\x6f\x1b\x37\x14\xde\xf5\x57\xbc\x1a\x68\x70\x82\x05\xa9\x59\xda\xc1\xb8\xa1\x4d\x93\x18\x81\x93\xb4\x76\xd0\xc5\xf0\xc0\xe8\x9e\x74\x8c\x4e\xbc\x33\xc9\xbb\x5a\x16\x04\x14\xed\xd4\x29\x40\x8b\xfe\x01\x05\x3a\xb4\x4b\x97\x76\xe9\xd2\xff\xc6\x46\xfa\x5f\x14\xef\x91\xa7\xe3\xfd\x30\x8c\x6c\xd1\x20\xdc\x91\x1f\xbf\xf7\xf1\xe3\x47\xf2\x66\x33\xd0\x68\x4b\xad\x40\x68\x2d\x36\x90\xa1\x5a\xda\x74\x24\x95\xa5\xc7\x48\xa8\xcd\xf9\x05\x88\xf1\x76\x37\x1a\x35\xd0\x54\x98\x74\x9e\x27\xc8\x30\x7a\x21\x1c\x18\x46\x15\x5a\x2a\x9b\xa9\x88\x5e\xf8\x79\x11\x19\xab\xa5\x5a\xc2\x22\xd7\x6b\x61\x27\x40\xd8\xe9\x74\xca\xa4\xbe\xcb\xdc\x8f\x14\xc6\xa0\xb6\x8f\x2f\x4b\x91\x31\xb7\x28\x0a\x54\x49\x54\x2b\xfb\x52\x58\xac\xd9\x96\x68\x1f\x95\x5a\xa3\xb2\xaf\xe4\x1a\x6b\x52\x7b\x3d\x01\xff\x98\x89\x4d\x5e\xda\x7a\xe8\x53\xb4\x90\x1b\x10\x7a\x69\xa6\x9e\xe2\xfc\x82\x48\x5e\x9e\x7d\xae\x97\x26\xea\x4c\xfe\xd9\xd9\xcb\x17\x9e\xa8\x2e\x48\x4d\x6c\x01\x2b\x9d\xcd\x1c\xe6\xb2\x44\xbd\x81\x6f\xa5\x4d\xa1\x10\x36\x1d\x11\x80\x3a\x9e\xa2\xad\x35\xbd\x31\xb9\xda\xab\x22\x10\xd7\x22\x86\xd4\xda\x02\x32\xf9\x9a\x9e\x4f\xd1\x14\xb9\x32\xc8\xf0\xd1\x13\xe7\x15\xd7\x24\xff\x69\x21\x5a\x1c\xfb\x17\x82\x7b\x41\xa7\x68\x98\x21\xb5\xeb\xac\x66\x38\x7e\xf5\xfc\xe4\x1e\x06\x82\xd7\xd3\xa7\x0e\x88\x34\x66\xc2\xca\x0a\xf9\xd5\xc0\x5a\x6c\x20\x5f\x4b\x0a\x8b\x48\x78\x25\x33\x61\xd2\x71\x6d\xcc\xd7\x64\xc1\x57\xc2\xa6\x51\x77\x8e\xfe\xfd\x49\xae\xd7\xdf\x88\xac\xc4\x68\xa8\xfc\x0a\x37\x04\x9e\x67\xc2\x18\x38\xb6\xb6\x78\x94\x2b\x8b\x57\x76\x3b\x02\x80\x50\xf0\x11\x37\x74\x2c\x21\xbf\xab\xb1\xc3\x06\x78\x72\x05\x62\x07\xae\xc6\x47\xfb\xee\xd0\x57\x47\xe0\xb4\xb0\x8b\x0e\xb6\xe3\xff\x8e\x6f\xae\x0c\xf4\xea\x90\x77\x10\x43\xd5\xab\xc0\xe3\xc3\x0a\xec\x72\x58\xc1\x33\x5c\xee\xdd\x1b\xa0\x2f\x20\x0e\xec\x65\x5f\x9b\x4a\x3e\xaa\x45\x4d\x1a\xb2\x2e\xba\x96\xb3\xcb\x5d\xfa\x0a\xe2\x60\x71\x9c\x4e\x02\xf6\x6a\x54\x75\x0d\xce\xd9\x17\x52\x25\xa0\xf3\xd2\xe2\x88\x12\x7c\x2c\x54\x92\xed\x0b\xad\xd1\xa6\x79\xd2\x49\xda\xa2\x54\x73\x88\x82\xc5\x1d\x43\xca\xa3\xbc\x26\x4a\x9e\x3f\x52\x0e\x68\x44\x7c\x70\x18\x4c\x36\x18\x07\x73\x7b\x05\x71\xd8\x12\x79\x90\xe3\x8b\xe6\xf6\x6a\x7c\xe4\x64\x9e\x96\xca\xed\x30\x83\xba\x42\x3d\x65\xb1\xa7\xa5\xaa\x95\x8a\x24\xd1\x1c\x53\x17\xbd\xc7\xca\xea\x8d\x93\x43\xab\xbd\xc2\xcd\xa4\x22\x5f\x1c\x3d\xf7\x82\xc2\x2b\x1b\xbc\xf3\x71\xb0\xf2\xe9\x98\xd4\x98\xc0\xe7\x15\x6e\xe2\x55\xe3\x26\xf3\xc5\x41\x58\x88\x2f\x56\x8d\xb9\x4e\xc9\x73\x51\x6c\x9b\x22\xe7\x17\x60\xc5\xeb\x0c\x21\x86\xf3\x87\x9f\x5e\x6c\x77\x0e\x4e\xd9\x34\xf2\x1a\xe3\x4f\x8e\xdc\xca\x17\xa5\x8d\x6a\xe1\x4e\x11\x55\x0b\xc4\xcc\x66\x60\xf3\x24\x87\xb9\xce\x8d\xc9\x2b\xd4\xcf\x24\xc2\xed\x8f\x7f\xdc\xfc\xf9\xcf\x1e\x23\x17\x11\x69\x8e\x0f\x0e\x82\x81\x4d\x10\x1a\xe5\xbb\x66\x88\xbf\x1e\x28\xec\x10\xbb\x9b\xa2\x1d\x22\x42\x48\xdf\xc5\xa8\x8f\xf9\xda\xe1\x59\x8d\xa1\xc1\x39\xff\x88\x84\xbb\xce\xe5\x45\xc0\xb1\x80\x08\xe1\xa3\x18\x94\xcc\x3a\xd2\xdc\x30\x8b\xeb\xc2\x3d\xc5\x80\x47\x2d\xc0\x22\xd7\x10\x35\xfd\x9e\x04\xda\x2c\xb5\xd0\xb9\xbb\x54\x8e\x85\x49\xeb\xd9\xec\x87\x4e\xdb\xf3\x0a\xb5\xb5\x86\x05\x53\x7d\xf0\x80\x16\x84\x9a\xda\x2c\xfd\xe2\xf4\x6b\x30\x2e\x2a\x10\x24\xb0\xfb\xeb\xae\x48\x7f\x65\x7a\xac\x10\xaa\x68\xb2\x3c\x3c\xb2\x5e\x03\x88\x7d\xd8\x39\x58\x2c\x68\x02\xd8\xb1\x81\x92\x78\x78\xe8\x93\xc8\x5c\x80\x99\xc1\x8e\xc7\xb3\x19\xdc\xbc\xfd\xfe\xdd\x77\x3f\xc0\x9b\x64\xf5\x70\xfa\x19\xfc\xf7\xf3\xbf\xef\x7e\xfd\xfd\xe6\xb7\xbf\x6f\xdf\xfe\x74\xfb\xd7\x2f\xf7\xd7\x77\xe5\x69\xf9\x86\xeb\x37\x53\x09\x0f\x45\xda\x0d\x4b\xdc\x6f\x8f\xc0\xfc\x0f\x36\xef\x9c\x59\xe4\x45\x1a\x4e\xfd\x1d\x59\xc5\x81\x8c\x52\x3e\x7d\x08\xb9\x9b\x42\x79\x47\x5e\x07\x72\xe9\xaf\x00\x9c\x0e\x64\xb1\x9d\x18\x9a\x09\x76\x72\xb5\x6b\xed\xe0\x40\x62\x6b\x97\x04\xdb\x04\x07\xb6\xc7\x5d\x12\x76\x03\x19\xf3\x58\x25\xb3\xae\x08\x1f\x06\x32\x6e\x89\xf6\x4c\x5e\x63\x14\xd4\xf1\xe3\x28\x48\xcd\x79\xcc\xdf\x44\x27\x52\xad\x30\x39\x91\xc6\xfa\xf3\xd9\x35\xbc\xc8\x13\x6c\xae\x8b\x40\x59\xd3\x1d\xdc\x17\x4d\x63\xd4\xfd\x64\xe1\xa1\xed\x8f\x08\x5e\xf6\x18\x7a\x37\x43\x23\x65\xdb\x2d\xb5\x90\xda\xd8\x09\x64\xc2\xd8\x3b\x2e\x08\x91\x24\xbd\xda\xb4\x28\x15\xd9\xfe\x1e\x1b\x20\x28\x4a\xdf\x3e\xc1\xcc\xc2\x2f\x2d\x62\x66\x4d\xc4\xde\x8f\xaf\xef\x82\xac\x1d\x28\x92\xdf\x6e\x75\x07\xc9\xb6\x87\x9a\x7a\x8f\xee\x27\xe8\x1d\x14\x30\x70\x52\x24\xe5\xba\x08\xe3\x10\x4c\xd2\x58\xa1\x89\x93\x25\x77\x76\xa8\xeb\x1b\xdc\xa0\xf5\x07\x0d\x43\x5c\x72\xbb\x87\x96\x27\x76\x88\xa1\x7d\xf3\xfe\x91\xfd\x3f\x00\x00\xff\xff\x54\x20\x03\xdd\xeb\x0d\x00\x00")

func internal_internal_gs() ([]byte, error) {
return bindata_read(
Expand Down
6 changes: 6 additions & 0 deletions internal/internal.gs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ int len(any[] a){}
int hash(any s){}

println(){}

//formats according to a format specifier and writes to standard output.
printf(string format, any ...a){}

//formats according to a format specifier and returns the resulting string.
string sprintf(string format, any ...a){}
assertEqual(){}
append(){}

Expand Down
57 changes: 56 additions & 1 deletion internal_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (v *Visitor) assertEqual(ctx *parser.FunctionCallContext) {
}

func (v *Visitor) append(ctx *parser.FunctionCallContext) []interface{} {
paramValues := v.buildParamValues(ctx)
paramValues, left := v.buildParamValuesReturnLeft(ctx)
if len(paramValues) != 2 {
// todo crossoverJie 运行时报错
panic("")
Expand All @@ -85,6 +85,7 @@ func (v *Visitor) append(ctx *parser.FunctionCallContext) []interface{} {
case []interface{}:
array := paramValues[0].([]interface{})
array = append(array, paramValues[1])
left.SetValue(array)
return array
default:
// todo crossoverJie 运行时报错
Expand Down Expand Up @@ -285,3 +286,57 @@ func (v *Visitor) getCurrentTime(ctx *parser.FunctionCallContext) string {
func (v *Visitor) getOSArgs(ctx *parser.FunctionCallContext) []string {
return Args
}

func (v *Visitor) buildParamValuesReturnLeft(ctx *parser.FunctionCallContext) ([]interface{}, *LeftValue) {
ret := make([]interface{}, 0)
if ctx.ExpressionList() == nil {
return ret, nil
}
var left *LeftValue
for _, context := range ctx.ExpressionList().(*parser.ExpressionListContext).AllExpr() {
value := v.Visit(context)
switch value.(type) {
case *LeftValue:
leftValue := value.(*LeftValue)
left = leftValue
ret = append(ret, leftValue.GetValue())
default:
ret = append(ret, value)
}
}
return ret, left
}

func (v *Visitor) printf(ctx *parser.FunctionCallContext) {
format, variableParams := v.getPrintfParams(ctx)

fmt.Printf(format, variableParams...)
}

// 获取格式化字符串参数
func (v *Visitor) getPrintfParams(ctx *parser.FunctionCallContext) (string, []interface{}) {
paramValues := v.buildParamValues(ctx)
p0 := paramValues[0]
var format string
switch p0.(type) {
case string:
format = p0.(string)
case *LeftValue:
value := p0.(*LeftValue).GetValue()
switch value.(type) {
case string:
format = value.(string)
default:
// todo crossoverJie 运行时报错
panic("not string")
}
}

variableParams := paramValues[1:]
return format, variableParams
}

func (v *Visitor) sprintf(ctx *parser.FunctionCallContext) string {
format, variableParams := v.getPrintfParams(ctx)
return fmt.Sprintf(format, variableParams...)
}
25 changes: 25 additions & 0 deletions internal_function_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gscript

import (
"fmt"
"testing"
)

Expand All @@ -16,3 +17,27 @@ if (1<a()){
`
NewCompiler().Compiler(script)
}

func TestPrint(t *testing.T) {
args := []interface{}{
"1", "2",
}
fmt.Printf("hello %s %s\n", args...)
fmt.Println(fmt.Sprintf("abc %d", 123))
}

func TestPrintf(t *testing.T) {
script := `

printf("hello %s ","123");
printf("hello-%s-%s ","123","abc");
printf("hello-%s-%d ","123",123);
string format = "this is %s ";
printf(format, "gscript");

string s = sprintf("nice to meet %s", "you");
println(s);
assertEqual(s,"nice to meet you");
`
NewCompiler().compile(script)
}
6 changes: 3 additions & 3 deletions parser/GScript.interp

Large diffs are not rendered by default.

222 changes: 111 additions & 111 deletions parser/GScript.tokens
Original file line number Diff line number Diff line change
@@ -1,120 +1,120 @@
T__0=1
T__1=2
T__2=3
CLASS=4
EXTENDS=5
IMPLEMENTS=6
FINAL=7
THROWS=8
INT=9
STRING=10
FLOAT=11
BOOLEAN=12
SUPER=13
SWITCH=14
THIS=15
Nil=16
ANY=17
LPAREN=18
RPAREN=19
LBRACE=20
RBRACE=21
LBRACK=22
RBRACK=23
DOT=24
ASSIGN=25
GT=26
LT=27
BANG=28
TILDE=29
AND=30
OR=31
INC=32
DEC=33
MULT=34
DIV=35
PLUS=36
SUB=37
MOD=38
ADD_ASSIGN=39
SUB_ASSIGN=40
MUL_ASSIGN=41
DIV_ASSIGN=42
EQUAL=43
LE=44
GE=45
NOTEQUAL=46
FUNCTION=47
VOID=48
FOR=49
IF=50
ELSE=51
RETURN=52
BREAK=53
CONTINUE=54
BOOL_LITERAL=55
STRING_LITERAL=56
RAW_STRING_LIT=57
NULL_LITERAL=58
DECIMAL_LITERAL=59
FLOAT_LITERAL=60
CLASS=3
EXTENDS=4
IMPLEMENTS=5
FINAL=6
THROWS=7
INT=8
STRING=9
FLOAT=10
BOOLEAN=11
SUPER=12
SWITCH=13
THIS=14
Nil=15
ANY=16
LPAREN=17
RPAREN=18
LBRACE=19
RBRACE=20
LBRACK=21
RBRACK=22
DOT=23
ASSIGN=24
GT=25
LT=26
BANG=27
TILDE=28
AND=29
OR=30
INC=31
DEC=32
MULT=33
DIV=34
PLUS=35
SUB=36
MOD=37
ADD_ASSIGN=38
SUB_ASSIGN=39
MUL_ASSIGN=40
DIV_ASSIGN=41
EQUAL=42
LE=43
GE=44
NOTEQUAL=45
FUNCTION=46
VOID=47
FOR=48
IF=49
ELSE=50
RETURN=51
BREAK=52
CONTINUE=53
BOOL_LITERAL=54
STRING_LITERAL=55
RAW_STRING_LIT=56
NULL_LITERAL=57
DECIMAL_LITERAL=58
FLOAT_LITERAL=59
ELLIPSIS=60
WS=61
COMMENT=62
LINE_COMMENT=63
IDENTIFIER=64
SPACES=65
';'=1
','=2
'...'=3
'class'=4
'extends'=5
'implements'=6
'final'=7
'throws'=8
'int'=9
'string'=10
'float'=11
'bool'=12
'super'=13
'switch'=14
'this'=15
'nil'=16
'any'=17
'('=18
')'=19
'{'=20
'}'=21
'['=22
']'=23
'.'=24
'='=25
'>'=26
'<'=27
'!'=28
'~'=29
'&&'=30
'||'=31
'++'=32
'--'=33
'*'=34
'/'=35
'+'=36
'-'=37
'%'=38
'+='=39
'-='=40
'*='=41
'/='=42
'=='=43
'<='=44
'>='=45
'!='=46
'func'=47
'void'=48
'for'=49
'if'=50
'else'=51
'return'=52
'break'=53
'continue'=54
'null'=58
'class'=3
'extends'=4
'implements'=5
'final'=6
'throws'=7
'int'=8
'string'=9
'float'=10
'bool'=11
'super'=12
'switch'=13
'this'=14
'nil'=15
'any'=16
'('=17
')'=18
'{'=19
'}'=20
'['=21
']'=22
'.'=23
'='=24
'>'=25
'<'=26
'!'=27
'~'=28
'&&'=29
'||'=30
'++'=31
'--'=32
'*'=33
'/'=34
'+'=35
'-'=36
'%'=37
'+='=38
'-='=39
'*='=40
'/='=41
'=='=42
'<='=43
'>='=44
'!='=45
'func'=46
'void'=47
'for'=48
'if'=49
'else'=50
'return'=51
'break'=52
'continue'=53
'null'=57
'...'=60
Loading