mirror of
https://github.com/KarolS/millfork.git
synced 2025-04-06 20:37:12 +00:00
String literal improvements
This commit is contained in:
parent
138ff8b82d
commit
9193a4f035
23
examples/c64/text_encodings.mfk
Normal file
23
examples/c64/text_encodings.mfk
Normal file
@ -0,0 +1,23 @@
|
||||
import stdio
|
||||
|
||||
array p = [
|
||||
"this is an example" petscii, 13,
|
||||
"of multiline petscii text" petscii
|
||||
]
|
||||
|
||||
array s = [
|
||||
"and this is an example " scr,
|
||||
"of text done in screencodes" scr
|
||||
]
|
||||
|
||||
array screen [1000] @$400
|
||||
|
||||
void main(){
|
||||
byte i
|
||||
putstr(p, p.length)
|
||||
for i,0,paralleluntil,s.length {
|
||||
screen[20 * 40 + i] = s[i]
|
||||
c64_color_ram[20 * 40 + i] = light_blue
|
||||
}
|
||||
while(true){}
|
||||
}
|
@ -167,8 +167,9 @@ case class MfParser(filename: String, input: String, currentDirectory: String, o
|
||||
appc <- appcSimple | appcComplex
|
||||
} yield ParameterDeclaration(typ, appc).pos(p)
|
||||
|
||||
def arrayListElement: P[List[Expression]] = arrayStringContents | mlExpression(nonStatementLevel).map(List(_))
|
||||
|
||||
val arrayListContents: P[List[Expression]] = ("[" ~/ AWS ~/ mlExpression(nonStatementLevel).rep(sep = AWS ~ "," ~/ AWS) ~ AWS ~ "]" ~/ Pass).map(_.toList)
|
||||
def arrayListContents: P[List[Expression]] = ("[" ~/ AWS ~/ arrayListElement.rep(sep = AWS ~ "," ~/ AWS) ~ AWS ~ "]" ~/ Pass).map(_.flatten.toList)
|
||||
|
||||
val doubleQuotedString: P[List[Char]] = P("\"" ~/ CharsWhile(c => c != '\"' && c != '\n' && c != '\r').! ~ "\"").map(_.toList)
|
||||
|
||||
@ -176,6 +177,7 @@ case class MfParser(filename: String, input: String, currentDirectory: String, o
|
||||
case (_, "ascii") => TextCodec.Ascii
|
||||
case (_, "petscii") => TextCodec.Petscii
|
||||
case (_, "pet") => TextCodec.Petscii
|
||||
case (_, "scr") => TextCodec.CbmScreencodes
|
||||
case (p, x) =>
|
||||
ErrorReporting.error(s"Unknown string encoding: `$x`", Some(p))
|
||||
TextCodec.Ascii
|
||||
|
@ -1,11 +1,12 @@
|
||||
package millfork.parser
|
||||
|
||||
import millfork.error.ErrorReporting
|
||||
import millfork.node.Position
|
||||
|
||||
/**
|
||||
* @author Karol Stasiak
|
||||
*/
|
||||
class TextCodec(val name:String, private val map: String, private val extra: Map[Char,Int]) {
|
||||
class TextCodec(val name: String, private val map: String, private val extra: Map[Char, Int]) {
|
||||
def decode(position: Option[Position], c: Char): Int = {
|
||||
if (extra.contains(c)) extra(c) else {
|
||||
val index = map.indexOf(c)
|
||||
@ -21,10 +22,19 @@ class TextCodec(val name:String, private val map: String, private val extra: Map
|
||||
object TextCodec {
|
||||
val NotAChar = '\ufffd'
|
||||
|
||||
val Ascii = new TextCodec("ASCII", 0.until(127).map{i => if (i<32) NotAChar else i.toChar}.mkString, Map.empty)
|
||||
val Ascii = new TextCodec("ASCII", 0.until(127).map { i => if (i < 32) NotAChar else i.toChar }.mkString, Map.empty)
|
||||
|
||||
val CbmScreencodes = new TextCodec("CBM-Screen",
|
||||
"@abcdefghijklmnopqrstuvwxyz[£]↑←" +
|
||||
0x20.to(0x3f).map(_.toChar).mkString +
|
||||
"–ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
Map('^' -> 0x3E, 'π' -> 0x5E))
|
||||
|
||||
val Petscii = new TextCodec("PETSCII",
|
||||
"\ufffd" * 32 + 0x20.to(0x3f).map(_.toChar).mkString + "@abcdefghijklmnopqrstuvwxyz[£]↑←–ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
"\ufffd" * 32 +
|
||||
0x20.to(0x3f).map(_.toChar).mkString +
|
||||
"@abcdefghijklmnopqrstuvwxyz[£]↑←" +
|
||||
"–ABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
Map('^' -> 0x5E, 'π' -> 0x7E)
|
||||
)
|
||||
|
||||
|
@ -155,4 +155,16 @@ class ArraySuite extends FunSuite with Matchers {
|
||||
""".stripMargin)(_.readByte(0xc000) should equal(0))
|
||||
|
||||
}
|
||||
|
||||
test("Syntax") {
|
||||
EmuUnoptimizedRun(
|
||||
"""
|
||||
| array a = [1, 2, 3]
|
||||
| array b = "text" ascii
|
||||
| array c = ["text" ascii, 5]
|
||||
| void main () {
|
||||
| }
|
||||
""".stripMargin)
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user