mirror of
https://github.com/irmen/prog8.git
synced 2024-09-30 00:55:52 +00:00
removed old @"screencodes" string encoding syntax (use sc:"hello" instead)
This commit is contained in:
parent
0cd27d6129
commit
c8cd6e9460
@ -31,7 +31,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
val result = compileText(platform, false, """
|
||||
main {
|
||||
sub start() {
|
||||
ubyte[] cs = @'a' to 'z' ; values are computed at compile time
|
||||
ubyte[] cs = sc:'a' to 'z' ; values are computed at compile time
|
||||
cs[0] = 23 ; keep optimizer from removing it
|
||||
}
|
||||
}
|
||||
@ -133,7 +133,7 @@ class TestCompilerOnRanges: FunSpec({
|
||||
main {
|
||||
sub start() {
|
||||
ubyte i
|
||||
for i in @'a' to 'f' {
|
||||
for i in sc:'a' to 'f' {
|
||||
i += i ; keep optimizer from removing it
|
||||
}
|
||||
}
|
||||
|
@ -82,17 +82,6 @@ class TestAstToSourceText: AnnotationSpec() {
|
||||
txt shouldContain Regex("str +sAlt += +sc:\"fooBar\\\\n\"")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStringLiteral_withOldSc() {
|
||||
val orig = SourceCode.Text("""
|
||||
main {
|
||||
str sAlt = @"fooBar\n"
|
||||
}
|
||||
""")
|
||||
val (txt, _) = roundTrip(parseModule(orig))
|
||||
txt shouldContain Regex("str +sAlt += +sc:\"fooBar\\\\n\"")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testStringLiteral_withIso() {
|
||||
val orig = SourceCode.Text("""
|
||||
@ -115,17 +104,6 @@ class TestAstToSourceText: AnnotationSpec() {
|
||||
txt shouldContain Regex("ubyte +c += +petscii:'x'")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCharLiteral_OldSc() {
|
||||
val orig = SourceCode.Text("""
|
||||
main {
|
||||
ubyte cAlt = @'x'
|
||||
}
|
||||
""")
|
||||
val (txt, _) = roundTrip(parseModule(orig))
|
||||
txt shouldContain Regex("ubyte +cAlt += +sc:'x'")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCharLiteral_Sc() {
|
||||
val orig = SourceCode.Text("""
|
||||
|
@ -429,23 +429,7 @@ class TestProg8Parser: FunSpec( {
|
||||
rhs.value shouldBe 'x'
|
||||
}
|
||||
|
||||
test("on rhs of block-level const decl, with screencode enc (old syntax)") {
|
||||
val src = SourceCode.Text("""
|
||||
main {
|
||||
const ubyte c = @'x'
|
||||
}
|
||||
""")
|
||||
val module = parseModule(src)
|
||||
val decl = module
|
||||
.statements.filterIsInstance<Block>()[0]
|
||||
.statements.filterIsInstance<VarDecl>()[0]
|
||||
|
||||
val rhs = decl.value as CharLiteral
|
||||
rhs.encoding shouldBe Encoding.SCREENCODES
|
||||
rhs.value shouldBe 'x'
|
||||
}
|
||||
|
||||
test("on rhs of block-level const decl, with screencode enc (new syntax)") {
|
||||
test("on rhs of block-level const decl, with screencode enc") {
|
||||
val src = SourceCode.Text("""
|
||||
main {
|
||||
const ubyte c = sc:'x'
|
||||
@ -497,26 +481,7 @@ class TestProg8Parser: FunSpec( {
|
||||
rhs.encoding shouldBe Encoding.PETSCII
|
||||
}
|
||||
|
||||
test("on rhs of subroutine-level const decl, screencode (old syntax)") {
|
||||
val src = SourceCode.Text("""
|
||||
main {
|
||||
sub start() {
|
||||
const ubyte c = @'x'
|
||||
}
|
||||
}
|
||||
""")
|
||||
val module = parseModule(src)
|
||||
val decl = module
|
||||
.statements.filterIsInstance<Block>()[0]
|
||||
.statements.filterIsInstance<Subroutine>()[0]
|
||||
.statements.filterIsInstance<VarDecl>()[0]
|
||||
|
||||
val rhs = decl.value as CharLiteral
|
||||
rhs.encoding shouldBe Encoding.SCREENCODES
|
||||
rhs.value shouldBe 'x'
|
||||
}
|
||||
|
||||
test("on rhs of subroutine-level const decl, screencode (new syntax)") {
|
||||
test("on rhs of subroutine-level const decl, screencode encoded") {
|
||||
val src = SourceCode.Text("""
|
||||
main {
|
||||
sub start() {
|
||||
@ -571,21 +536,7 @@ class TestProg8Parser: FunSpec( {
|
||||
rhs.value shouldBe "name"
|
||||
}
|
||||
|
||||
test("old syntax alt encoding") {
|
||||
val source = """
|
||||
main {
|
||||
str name = @"name"
|
||||
}"""
|
||||
val module = parseModule(SourceCode.Text(source))
|
||||
val decl = module
|
||||
.statements.filterIsInstance<Block>()[0]
|
||||
.statements.filterIsInstance<VarDecl>()[0]
|
||||
val rhs = decl.value as StringLiteral
|
||||
rhs.encoding shouldBe Encoding.SCREENCODES
|
||||
rhs.value shouldBe "name"
|
||||
}
|
||||
|
||||
test("new syntax encodings") {
|
||||
test("string encodings") {
|
||||
val source = """
|
||||
main {
|
||||
str name1 = petscii:"Name"
|
||||
@ -619,7 +570,7 @@ class TestProg8Parser: FunSpec( {
|
||||
}
|
||||
for ub in "something" { ; #1
|
||||
}
|
||||
for ub in @'a' to 'f' { ; #2
|
||||
for ub in sc:'a' to 'f' { ; #2
|
||||
}
|
||||
for ub in false to true { ; #3
|
||||
}
|
||||
|
@ -321,10 +321,8 @@ internal fun Prog8ANTLRParser.DirectiveContext.toAst() : Directive =
|
||||
|
||||
private fun Prog8ANTLRParser.DirectiveargContext.toAst() : DirectiveArg {
|
||||
val str = stringliteral()
|
||||
val oldenc = str?.old_alt_encoding?.text
|
||||
val enc = str?.encoding?.text
|
||||
if(oldenc!=null || enc !=null)
|
||||
throw SyntaxError("can't use alternate string encoding for directive arguments", toPosition())
|
||||
if(str?.encoding?.text!=null)
|
||||
throw SyntaxError("don't use a string encoding for directive arguments", toPosition())
|
||||
return DirectiveArg(str?.text?.substring(1, text.length-1), identifier()?.text, integerliteral()?.toAst()?.number?.toUInt(), toPosition())
|
||||
}
|
||||
|
||||
@ -455,9 +453,7 @@ private fun Prog8ANTLRParser.CharliteralContext.toAst(): CharLiteral {
|
||||
val text = this.SINGLECHAR().text
|
||||
val enc = this.encoding?.text
|
||||
val encoding =
|
||||
if(old_alt_encoding!=null)
|
||||
Encoding.SCREENCODES
|
||||
else if(enc!=null)
|
||||
if(enc!=null)
|
||||
Encoding.values().singleOrNull { it.prefix == enc }
|
||||
?: throw SyntaxError("invalid encoding", toPosition())
|
||||
else
|
||||
@ -469,9 +465,7 @@ private fun Prog8ANTLRParser.StringliteralContext.toAst(): StringLiteral {
|
||||
val text=this.STRING().text
|
||||
val enc = encoding?.text
|
||||
val encoding =
|
||||
if(old_alt_encoding!=null)
|
||||
Encoding.SCREENCODES
|
||||
else if(enc!=null)
|
||||
if(enc!=null)
|
||||
Encoding.values().singleOrNull { it.prefix == enc }
|
||||
?: throw SyntaxError("invalid encoding", toPosition())
|
||||
else
|
||||
|
@ -193,8 +193,7 @@ Values will usually be part of an expression or assignment statement::
|
||||
-33.456e52 ; floating point number
|
||||
"Hi, I am a string" ; text string, encoded with compiler target default encoding
|
||||
'a' ; byte value (ubyte) for the letter a
|
||||
@"Alternate" ; text string, encoded with alternate encoding (old deprecated syntax)
|
||||
sc:"Alternate" ; text string, encoded with c64 screencode encoding (current syntax)
|
||||
sc:"Alternate" ; text string, encoded with c64 screencode encoding
|
||||
sc:'a' ; byte value of the letter a in c64 screencode encoding
|
||||
|
||||
byte counter = 42 ; variable of size 8 bits, with initial value 42
|
||||
@ -318,13 +317,6 @@ but they have some special properties because they are considered to be *text*.
|
||||
Strings (without encoding prefix) will be encoded (translated from ASCII/UTF-8) into bytes via the
|
||||
*default encoding* for the target platform. On the CBM machines, this is CBM PETSCII.
|
||||
|
||||
.. sidebar::
|
||||
Deprecated ``@`` prefix
|
||||
|
||||
In older versions of the language, the ``@`` prefix was used to specify the
|
||||
CBM screencode encoding. This syntax is still supported for now, but will be removed
|
||||
in a future language version.
|
||||
|
||||
Alternative encodings can be specified with a ``encodingname:`` prefix to the string or character literal.
|
||||
The following encodings are currently recognised:
|
||||
|
||||
|
@ -431,13 +431,6 @@ memory at the given index. See :ref:`pointervars`
|
||||
|
||||
String
|
||||
^^^^^^
|
||||
.. sidebar::
|
||||
Deprecated ``@`` prefix
|
||||
|
||||
In older versions of the language, the ``@`` prefix was used to specify the
|
||||
CBM screencode encoding. This syntax is still supported for now, but will be removed
|
||||
in a future language version.
|
||||
|
||||
A string literal can occur with or without an encoding prefix (encoding followed by ':' followed by the string itself).
|
||||
When this is omitted, the string is stored in the machine's default character encoding (which is PETSCII on the CBM machines).
|
||||
You can choose to store the string in other encodings such as ``sc`` (screencodes) or ``iso`` (iso-8859-15).
|
||||
|
@ -3,7 +3,6 @@ TODO
|
||||
|
||||
For next release
|
||||
^^^^^^^^^^^^^^^^
|
||||
- remove support for old @"screencodes" string encoding syntax, parser+code+docs
|
||||
- ...
|
||||
|
||||
|
||||
|
@ -19,8 +19,8 @@ main {
|
||||
window_workbench()
|
||||
window_system()
|
||||
window_shell()
|
||||
gfx2.text(280, 210, 1, @"640x480(240) 4 colors")
|
||||
gfx2.text(280, 220, 1, @"Mockup drawn using Prog8 gfx2 library")
|
||||
gfx2.text(280, 210, 1, sc:"640x480(240) 4 colors")
|
||||
gfx2.text(280, 220, 1, sc:"Mockup drawn using Prog8 gfx2 library")
|
||||
|
||||
repeat {
|
||||
}
|
||||
@ -28,7 +28,7 @@ main {
|
||||
|
||||
sub screen_titlebar() {
|
||||
gfx2.fillrect(0, 0, gfx2.width, 10, 2)
|
||||
gfx2.text(8,1, 1, @"AmigaOS 3.1 2,002,448 graphics mem 16,504,384 other mem")
|
||||
gfx2.text(8,1, 1, sc:"AmigaOS 3.1 2,002,448 graphics mem 16,504,384 other mem")
|
||||
gfx2.horizontal_line(0, 10, gfx2.width, 1)
|
||||
widget.window_order_icon(gfx2.width-widget.window_order_icon.width, 0, false)
|
||||
}
|
||||
@ -40,7 +40,7 @@ main {
|
||||
const uword width = 600
|
||||
const uword height = 220
|
||||
|
||||
widget.window_titlebar(win_x, win_y, width, @"Workbench", false)
|
||||
widget.window_titlebar(win_x, win_y, width, sc:"Workbench", false)
|
||||
; gfx2.fillrect(win_x+3, win_y+11, width-4, height-11-2,0) ; clear window pane
|
||||
widget.window_leftborder(win_x, win_y, height, false)
|
||||
widget.window_bottomborder(win_x, win_y, width, height)
|
||||
@ -49,8 +49,8 @@ main {
|
||||
vector_v(win_x+width - 390, win_y+height-20)
|
||||
vector_v(win_x+width - 390 -14, win_y+height-20)
|
||||
|
||||
widget.icon(45,40, @"Ram Disk")
|
||||
widget.icon(45,90, @"Workbench3.1")
|
||||
widget.icon(45,40, sc:"Ram Disk")
|
||||
widget.icon(45,90, sc:"Workbench3.1")
|
||||
}
|
||||
|
||||
sub vector_v(uword x, uword y) {
|
||||
@ -68,17 +68,17 @@ main {
|
||||
const uword win_x = 320
|
||||
const uword win_y = 40
|
||||
|
||||
widget.window_titlebar(win_x, win_y, width, @"System", false)
|
||||
widget.window_titlebar(win_x, win_y, width, sc:"System", false)
|
||||
gfx2.fillrect(win_x+3, win_y+11, width-4, height-11-2, 0) ; clear window pane
|
||||
widget.window_leftborder(win_x, win_y, height, false)
|
||||
widget.window_bottomborder(win_x, win_y, width, height)
|
||||
widget.window_rightborder(win_x, win_y, width, height, false)
|
||||
|
||||
widget.icon(win_x+16, win_y+14, @"FixFonts")
|
||||
widget.icon(win_x+16+80, win_y+14, @"NoFastMem")
|
||||
widget.icon(win_x+16, win_y+56, @"Format")
|
||||
widget.icon(win_x+16+80, win_y+56, @"RexxMast")
|
||||
widget.icon(win_x+16+160, win_y+56, @"Shell")
|
||||
widget.icon(win_x+16, win_y+14, sc:"FixFonts")
|
||||
widget.icon(win_x+16+80, win_y+14, sc:"NoFastMem")
|
||||
widget.icon(win_x+16, win_y+56, sc:"Format")
|
||||
widget.icon(win_x+16+80, win_y+56, sc:"RexxMast")
|
||||
widget.icon(win_x+16+160, win_y+56, sc:"Shell")
|
||||
}
|
||||
|
||||
sub window_shell() {
|
||||
@ -87,14 +87,14 @@ main {
|
||||
const uword width = 500
|
||||
const uword height = 65
|
||||
|
||||
widget.window_titlebar(win_x, win_y, width, @"AmigaShell", true)
|
||||
widget.window_titlebar(win_x, win_y, width, sc:"AmigaShell", true)
|
||||
gfx2.fillrect(win_x+3, win_y+11, width-4, height-11-2,0) ; clear window pane
|
||||
widget.window_leftborder(win_x, win_y, height, true)
|
||||
widget.window_bottomborder(win_x, win_y, width, height)
|
||||
widget.window_rightborder(win_x, win_y, width, height, true)
|
||||
|
||||
gfx2.text(win_x+5, win_y+12, 1, @"New Shell process 3")
|
||||
gfx2.text(win_x+5, win_y+12+8, 1, @"3.Workbench3.1:>")
|
||||
gfx2.text(win_x+5, win_y+12, 1, sc:"New Shell process 3")
|
||||
gfx2.text(win_x+5, win_y+12+8, 1, sc:"3.Workbench3.1:>")
|
||||
gfx2.fillrect(win_x+5+17*8, win_y+12+8, 8, 8, 1) ; cursor
|
||||
}
|
||||
}
|
||||
|
@ -30,14 +30,14 @@ main {
|
||||
gfx2.fillrect(xx+20, yy+20, 200, 30, 1)
|
||||
gfx2.rect(xx+21, yy+21, 200-2, 30-2, 0)
|
||||
|
||||
gfx2.text(xx+30, yy+32, 0, @"High Res Bitmap Example")
|
||||
gfx2.text(xx+30, yy+32, 0, sc:"High Res Bitmap Example")
|
||||
|
||||
; gfx2.monochrome_stipple(true)
|
||||
gfx2.horizontal_line(10, 240, 620, 1)
|
||||
gfx2.vertical_line(320, 10, 460, 1)
|
||||
gfx2.text(320, 242, 1, @"0,0")
|
||||
gfx2.text(322, 10, 1, @"Y-axis")
|
||||
gfx2.text(590, 242, 1, @"X-axis")
|
||||
gfx2.text(320, 242, 1, sc:"0,0")
|
||||
gfx2.text(322, 10, 1, sc:"Y-axis")
|
||||
gfx2.text(590, 242, 1, sc:"X-axis")
|
||||
for ww in -10 to 10 {
|
||||
xx = (ww*30) + 320 as uword
|
||||
gfx2.vertical_line(xx, 239, 3, 1)
|
||||
@ -53,13 +53,13 @@ main {
|
||||
y_f = sin(ww as float / 60.0)*150
|
||||
gfx2.plot(ww/2 + 320 as uword, (y_f + 240) as uword, 1)
|
||||
}
|
||||
gfx2.text(480, 100, 1, @"sin(x)")
|
||||
gfx2.text(480, 100, 1, sc:"sin(x)")
|
||||
|
||||
for ww in -300 to 300 {
|
||||
y_f = cos(ww as float/30.0)*60 - (ww as float)/1.7
|
||||
gfx2.plot(ww + 320 as uword, (y_f + 240) as uword, 1)
|
||||
}
|
||||
gfx2.text(80, 420, 1, @"cos(x)+x")
|
||||
gfx2.text(80, 420, 1, sc:"cos(x)+x")
|
||||
|
||||
sys.wait(3*60)
|
||||
|
||||
|
@ -190,7 +190,7 @@ main {
|
||||
|
||||
ubyte tp
|
||||
for tp in 0 to 15 {
|
||||
gfx2.text(19+tp,20+tp*11, 5, @"ScreenCODE text! 1234![]<>#$%&*()")
|
||||
gfx2.text(19+tp,20+tp*11, 5, sc:"ScreenCODE text! 1234![]<>#$%&*()")
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ main {
|
||||
vtui.gotoxy(10,10)
|
||||
vtui.border(1, 40, 6, $47)
|
||||
vtui.gotoxy(12,12)
|
||||
vtui.print_str2(@"Hello, world! vtui from Prog8!", $f2, false)
|
||||
vtui.print_str2(sc:"Hello, world! vtui from Prog8!", $f2, false)
|
||||
vtui.gotoxy(12,13)
|
||||
vtui.print_str2("Hello, world! vtui from Prog8!", $f2, true)
|
||||
|
||||
@ -30,11 +30,11 @@ main {
|
||||
; txt.chrout('\n')
|
||||
|
||||
vtui.gotoxy(5,20)
|
||||
vtui.print_str2(@"Enter your name: ", $e3, false)
|
||||
vtui.print_str2(sc:"Enter your name: ", $e3, false)
|
||||
ubyte length = vtui.input_str(inputbuffer, len(inputbuffer), $21)
|
||||
|
||||
vtui.gotoxy(8,22)
|
||||
vtui.print_str2(@"Your name is: ", $e3, false)
|
||||
vtui.print_str2(sc:"Your name is: ", $e3, false)
|
||||
;vtui.print_str2(inputbuffer, $67, $00)
|
||||
vtui.print_str(inputbuffer, length, $67, $00)
|
||||
|
||||
|
@ -10,7 +10,7 @@ main {
|
||||
txt.lowercase()
|
||||
|
||||
str s1 = "HELLO hello 1234 @[/]" ; regular strings have default encoding (petscii on c64)
|
||||
str s2 = @"HELLO hello 1234 @[/]" ; alternative encoding (screencodes on c64)
|
||||
str s2 = sc:"HELLO hello 1234 @[/]" ; alternative encoding (screencodes on c64)
|
||||
|
||||
txt.print("\n\n\n\nString output via print:\n")
|
||||
txt.print("petscii-str: ")
|
||||
@ -25,7 +25,7 @@ main {
|
||||
txt.setchr(i, 1, s2[i])
|
||||
|
||||
ubyte c1 = 'z'
|
||||
ubyte c2 = @'z'
|
||||
ubyte c2 = sc:'z'
|
||||
|
||||
txt.print("\npetscii z=")
|
||||
txt.print_ub(c1)
|
||||
|
@ -205,7 +205,7 @@ waitkey:
|
||||
num_lines++
|
||||
ubyte x
|
||||
for x in boardOffsetX to boardOffsetX+boardWidth-1
|
||||
txt.setcc(x, linepos, @'▒', 1)
|
||||
txt.setcc(x, linepos, sc:'▒', 1)
|
||||
}
|
||||
}
|
||||
if num_lines {
|
||||
@ -337,7 +337,7 @@ waitkey:
|
||||
for i in len(colors)-1 downto 0 {
|
||||
ubyte x
|
||||
for x in 5 downto 0 {
|
||||
txt.setcc(6+x-i, 11+2*i, @'▒', colors[i])
|
||||
txt.setcc(6+x-i, 11+2*i, sc:'▒', colors[i])
|
||||
}
|
||||
}
|
||||
drawScore()
|
||||
|
@ -1,10 +1,9 @@
|
||||
%zeropage basicsafe
|
||||
|
||||
main {
|
||||
ubyte @requirezp foobar2 = 255
|
||||
sub start() {
|
||||
ubyte @requirezp foobar = 255
|
||||
foobar++
|
||||
foobar2++
|
||||
uword zzz = memory("sdfasdf", 100, 0)
|
||||
str @shared foobar = "zsdfzsdf"
|
||||
str @shared foobar2 = sc:"zsdfzsdf"
|
||||
}
|
||||
}
|
||||
|
@ -220,9 +220,9 @@ booleanliteral : 'true' | 'false' ;
|
||||
|
||||
arrayliteral : '[' EOL? expression (',' EOL? expression)* EOL? ']' ; // you can split the values over several lines
|
||||
|
||||
stringliteral : (old_alt_encoding='@' | encoding=NAME ':')? STRING ;
|
||||
stringliteral : (encoding=NAME ':')? STRING ;
|
||||
|
||||
charliteral : (old_alt_encoding='@' | encoding=NAME ':')? SINGLECHAR ;
|
||||
charliteral : (encoding=NAME ':')? SINGLECHAR ;
|
||||
|
||||
floatliteral : FLOAT_NUMBER ;
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
<option name="HAS_STRING_ESCAPES" value="true" />
|
||||
</options>
|
||||
<keywords keywords="&;->;@;\$;and;as;asmsub;break;clobbers;do;downto;else;false;for;goto;if;if_cc;if_cs;if_eq;if_mi;if_ne;if_neg;if_nz;if_pl;if_pos;if_vc;if_vs;if_z;in;inline;not;or;repeat;return;romsub;step;sub;to;true;until;when;while;xor;~" ignore_case="false" />
|
||||
<keywords2 keywords="%address;%asm;%asmbinary;%asminclude;%breakpoint;%import;%launcher;%option;%output;%zeropage;%zpreserved" />
|
||||
<keywords2 keywords="%address;%asm;%asmbinary;%asminclude;%breakpoint;%import;%launcher;%option;%output;%zeropage;%zpreserved;iso:;petscii:;sc:" />
|
||||
<keywords3 keywords="@requirezp;@shared;@zp;byte;const;float;str;ubyte;uword;void;word" />
|
||||
<keywords4 keywords="abs;acos;all;any;asin;atan;avg;callfar;callrom;ceil;cmp;cos;cos16;cos16u;cos8;cos8u;cosr16;cosr16u;cosr8;cosr8u;deg;floor;len;ln;log2;lsb;lsl;lsr;max;memory;min;mkword;msb;peek;peekw;poke;pokew;pop;popw;push;pushw;rad;reverse;rnd;rndf;rndw;rol;rol2;ror;ror2;round;rrestore;rrestorex;rsave;rsavex;sgn;sin;sin16;sin16u;sin8;sin8u;sinr16;sinr16u;sinr8;sinr8u;sizeof;sort;sqrt;sqrt16;sum;swap;tan;|>" />
|
||||
</highlighting>
|
||||
|
Loading…
Reference in New Issue
Block a user