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

Escape Sequence for Brackets #79

Merged
merged 1 commit into from
Nov 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ namespace AtlusScriptLibrary.MessageScriptLanguage.Compiler;
/// </summary>
public class MessageScriptCompiler
{
public static readonly Dictionary<string, string> ESCAPE_SEQUENCES = new Dictionary<string, string>(){
{ "\\[", "[" },
{ "\\]", "]" }
};

private readonly Logger mLogger;
private readonly FormatVersion mVersion;
private readonly HashSet<int> mImportedFileHashSet;
Expand Down Expand Up @@ -659,7 +664,13 @@ private bool TryCompileTokenText(MessageScriptParser.TokenTextContext context, o
if (textWithoutNewlines.Length == 0)
continue; // filter out standalone newlines

lineToken = new StringToken(textWithoutNewlines);
var textWithoutEscapeChars = textWithoutNewlines;
foreach(var sequence in ESCAPE_SEQUENCES)
{
textWithoutEscapeChars = textWithoutEscapeChars.Replace(sequence.Key, sequence.Value);
}

lineToken = new StringToken(textWithoutEscapeChars);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// ANTLR Version: 4.6.4
// ANTLR Version: 4.6.6
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

// Generated from ..\..\..\AtlusScriptLibrary\MessageScriptLanguage\Compiler\Parser\MessageScriptLexer.g4 by ANTLR 4.6.4
// Generated from Compiler/Parser/MessageScriptLexer.g4 by ANTLR 4.6.6

// Unreachable code detected
#pragma warning disable 0162
Expand All @@ -25,13 +25,13 @@ namespace AtlusScriptLibrary.FlowScriptLanguage.Compiler.Parser {
using Antlr4.Runtime.Misc;
using DFA = Antlr4.Runtime.Dfa.DFA;

[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.6.4")]
[System.CodeDom.Compiler.GeneratedCode("ANTLR", "4.6.6")]
[System.CLSCompliant(false)]
public partial class MessageScriptLexer : Lexer {
public const int
OpenCode=1, CloseText=2, Text=3, MessageDialogTagId=4, SelectionDialogTagId=5,
SelectionDialogPatternId=6, CloseCode=7, OpenText=8, IntLiteral=9, Identifier=10,
Whitespace=11, BlockComment=12;
Whitespace=11;
public const int MessageScriptCode = 1;
public static string[] modeNames = {
"DEFAULT_MODE", "MessageScriptCode"
Expand All @@ -41,7 +41,7 @@ public const int
"OpenCode", "CloseText", "Text", "MessageDialogTagId", "SelectionDialogTagId",
"SelectionDialogPatternId", "CloseCode", "OpenText", "IdentifierEscape",
"IntLiteral", "Identifier", "DecIntLiteral", "HexIntLiteral", "Letter",
"Digit", "HexDigit", "HexLiteralPrefix", "Sign", "Whitespace", "BlockComment"
"Digit", "HexDigit", "HexLiteralPrefix", "Sign", "Whitespace"
};


Expand All @@ -57,7 +57,7 @@ public MessageScriptLexer(ICharStream input)
private static readonly string[] _SymbolicNames = {
null, "OpenCode", "CloseText", "Text", "MessageDialogTagId", "SelectionDialogTagId",
"SelectionDialogPatternId", "CloseCode", "OpenText", "IntLiteral", "Identifier",
"Whitespace", "BlockComment"
"Whitespace"
};
public static readonly IVocabulary DefaultVocabulary = new Vocabulary(_LiteralNames, _SymbolicNames);

Expand Down Expand Up @@ -107,67 +107,62 @@ public override IVocabulary Vocabulary
public override string SerializedAtn { get { return _serializedATN; } }

public static readonly string _serializedATN =
"\x3\xAF6F\x8320\x479D\xB75C\x4880\x1605\x191C\xAB37\x2\xE\xA6\b\x1\b\x1"+
"\x3\xAF6F\x8320\x479D\xB75C\x4880\x1605\x191C\xAB37\x2\r\x9A\b\x1\b\x1"+
"\x4\x2\t\x2\x4\x3\t\x3\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x3\x2\x2\x2~|\x3\x2"+
"\x2\x2~\x7F\x3\x2\x2\x2\x7F\x1B\x3\x2\x2\x2\x80\x82\x5&\x13\x2\x81\x80"+
"\x3\x2\x2\x2\x81\x82\x3\x2\x2\x2\x82\x83\x3\x2\x2\x2\x83\x85\x5$\x12\x2"+
"\x84\x86\x5\"\x11\x2\x85\x84\x3\x2\x2\x2\x86\x87\x3\x2\x2\x2\x87\x85\x3"+
"\x2\x2\x2\x87\x88\x3\x2\x2\x2\x88\x1D\x3\x2\x2\x2\x89\x8A\t\x4\x2\x2\x8A"+
"\x1F\x3\x2\x2\x2\x8B\x8C\t\x5\x2\x2\x8C!\x3\x2\x2\x2\x8D\x90\x5 \x10\x2"+
"\x8E\x90\t\x6\x2\x2\x8F\x8D\x3\x2\x2\x2\x8F\x8E\x3\x2\x2\x2\x90#\x3\x2"+
"\x2\x2\x91\x92\a\x32\x2\x2\x92\x93\t\a\x2\x2\x93%\x3\x2\x2\x2\x94\x95"+
"\t\b\x2\x2\x95\'\x3\x2\x2\x2\x96\x97\t\t\x2\x2\x97\x98\x3\x2\x2\x2\x98"+
"\x99\b\x14\x4\x2\x99)\x3\x2\x2\x2\x13\x2\x3\x37\x39\x41P_\x63hjqvy~\x81"+
"\x87\x8F\x5\a\x3\x2\x6\x2\x2\b\x2\x2";
public static readonly ATN _ATN =
new ATNDeserializer().Deserialize(_serializedATN.ToCharArray());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CloseText

// match actual text
Text
: ~( '[' | ']' )+
: ( '\\[' | '\\]' | ~( '[' | ']' ))+
;

//
Expand Down Expand Up @@ -89,4 +89,4 @@ Sign
: '+' | '-';

Whitespace
: [ \t\r\n] -> skip;
: [ \t\r\n] -> skip;
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ OpenText=8
IntLiteral=9
Identifier=10
Whitespace=11
BlockComment=12
'sel'=5
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,12 @@ public void Decompile(FunctionToken token)

public void Decompile(StringToken token)
{
mWriter.Write(token.Value);
var textWithEscapeChars = token.Value;
foreach(var sequence in MessageScriptLanguage.Compiler.MessageScriptCompiler.ESCAPE_SEQUENCES)
{
textWithEscapeChars = textWithEscapeChars.Replace(sequence.Value, sequence.Key);
}
mWriter.Write(token.Value.Replace("[", "\\[").Replace("]", "\\]"));
}

public void Decompile(CodePointToken token)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;
using System.IO;
using AtlusScriptLibrary.Common.Libraries;
using AtlusScriptLibrary.MessageScriptLanguage.BinaryModel;
using AtlusScriptLibrary.MessageScriptLanguage.Compiler;
using AtlusScriptLibrary.MessageScriptLanguage.Decompiler;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AtlusScriptLibrary.MessageScriptLanguage.Tests
Expand Down Expand Up @@ -82,6 +85,30 @@ public void ToBinary_ShouldMatchSourceBinary_Version1BigEndian()
Compare(binary, newBinary);
}

[TestMethod]
public void EscapeChars_CanDecompileAndRecompileWithBrackets()
{
var library = LibraryLookup.GetLibrary("p3re");

var binary = MessageScriptBinary.FromFile("TestResources/EscapeChar.bmd");
var script = MessageScript.FromBinary(binary, FormatVersion.Version1Reload);

var writer = new StringWriter();
using (var decompiler = new MessageScriptDecompiler(writer))
{
decompiler.Library = library;
decompiler.Decompile(script);
}
string text = writer.ToString();

var compiler = new MessageScriptCompiler(FormatVersion.Version1Reload, System.Text.Encoding.UTF8);
compiler.Library = library;
compiler.TryCompile(text, out var recompiledScript);

var newBinary = recompiledScript.ToBinary();
Compare(binary, newBinary);
}

private void Compare(MessageScriptBinary binary, MessageScriptBinary newBinary)
{
// compare headers
Expand Down
Binary file not shown.