mirror of
https://gitlab.gnome.org/jwestman/blueprint-compiler.git
synced 2025-05-04 15:59:08 -04:00
tokenizer: Allow escaped newlines
The docs said multi-line strings were possible by escaping the newline character, but this was not actually implemented. Fixes #132.
This commit is contained in:
parent
9543b78138
commit
2faa9207de
4 changed files with 22 additions and 2 deletions
|
@ -39,8 +39,8 @@ class TokenType(Enum):
|
||||||
|
|
||||||
_tokens = [
|
_tokens = [
|
||||||
(TokenType.IDENT, r"[A-Za-z_][\d\w\-_]*"),
|
(TokenType.IDENT, r"[A-Za-z_][\d\w\-_]*"),
|
||||||
(TokenType.QUOTED, r'"(\\.|[^\\"\n])*"'),
|
(TokenType.QUOTED, r'"(\\(.|\n)|[^\\"\n])*"'),
|
||||||
(TokenType.QUOTED, r"'(\\.|[^\\'\n])*'"),
|
(TokenType.QUOTED, r"'(\\(.|\n)|[^\\'\n])*'"),
|
||||||
(TokenType.NUMBER, r"0x[A-Za-z0-9_]+"),
|
(TokenType.NUMBER, r"0x[A-Za-z0-9_]+"),
|
||||||
(TokenType.NUMBER, r"[\d_]+(\.[\d_]+)?"),
|
(TokenType.NUMBER, r"[\d_]+(\.[\d_]+)?"),
|
||||||
(TokenType.NUMBER, r"\.[\d_]+"),
|
(TokenType.NUMBER, r"\.[\d_]+"),
|
||||||
|
|
|
@ -124,6 +124,7 @@ def unescape_quote(string: str) -> str:
|
||||||
string = string[1:-1]
|
string = string[1:-1]
|
||||||
|
|
||||||
REPLACEMENTS = {
|
REPLACEMENTS = {
|
||||||
|
"\n": "\n",
|
||||||
"\\": "\\",
|
"\\": "\\",
|
||||||
"n": "\n",
|
"n": "\n",
|
||||||
"t": "\t",
|
"t": "\t",
|
||||||
|
|
6
tests/samples/multiline_string.blp
Normal file
6
tests/samples/multiline_string.blp
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
using Gtk 4.0;
|
||||||
|
|
||||||
|
Label {
|
||||||
|
label: "Hello,\
|
||||||
|
world!";
|
||||||
|
}
|
13
tests/samples/multiline_string.ui
Normal file
13
tests/samples/multiline_string.ui
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
DO NOT EDIT!
|
||||||
|
This file was @generated by blueprint-compiler. Instead, edit the
|
||||||
|
corresponding .blp file and regenerate this file with blueprint-compiler.
|
||||||
|
-->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk" version="4.0"/>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="label">Hello,
|
||||||
|
world!</property>
|
||||||
|
</object>
|
||||||
|
</interface>
|
Loading…
Add table
Add a link
Reference in a new issue