mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +00:00
Allow any character to be escaped
This commit is contained in:
parent
d1f49d1894
commit
4284b06f10
6 changed files with 103 additions and 95 deletions
28
LANGUAGE.md
28
LANGUAGE.md
|
|
@ -100,7 +100,7 @@ If an unescaped `~`, `~?` or `#` appears in the line, the associated operator is
|
||||||
not tagged
|
not tagged
|
||||||
```
|
```
|
||||||
|
|
||||||
* regular text, i.e. any line that doesn't start with a special line type caracter: write some text into the [event buffer](#event-buffer). Support [text interpolation](#text-interpolation). Support [escape codes](#escape-codes). Don't accept children lines.
|
* regular text, i.e. any line that doesn't start with a special line type character: write some text into the [event buffer](#event-buffer). Support [text interpolation](#text-interpolation). Support [escape codes](#escape-codes). Don't accept children lines.
|
||||||
|
|
||||||
```
|
```
|
||||||
Hello,
|
Hello,
|
||||||
|
|
@ -522,14 +522,14 @@ Text
|
||||||
|
|
||||||
By default, some processing is done on the event buffer before sending it to your game. You can disable these by disabling the associated features flages using `vm:disable` (see #api-reference).
|
By default, some processing is done on the event buffer before sending it to your game. You can disable these by disabling the associated features flages using `vm:disable` (see #api-reference).
|
||||||
|
|
||||||
* strip trailing spaces: will remove any space caracters at the end of the text (for text event), or at the end of each choice (for choice event).
|
* strip trailing spaces: will remove any space characters at the end of the text (for text event), or at the end of each choice (for choice event).
|
||||||
|
|
||||||
```
|
```
|
||||||
(There is a space between the text and the tag expression that would be included in the text event otherwise.)
|
(There is a space between the text and the tag expression that would be included in the text event otherwise.)
|
||||||
Some text # tag
|
Some text # tag
|
||||||
```
|
```
|
||||||
|
|
||||||
* strip duplicate spaces: will remove any duplicated space caracters between each element that constitute the text (for text event), or for each choice (for choice event).
|
* strip duplicate spaces: will remove any duplicated space characters between each element that constitute the text (for text event), or for each choice (for choice event).
|
||||||
|
|
||||||
```
|
```
|
||||||
(There is a space between the text and the tag expression; but there is a space as well after the text interpolation in the last line. The two spaces are converted into a single space (the space will belong to the first text element, i.e. the "text " element).)
|
(There is a space between the text and the tag expression; but there is a space as well after the text interpolation in the last line. The two spaces are converted into a single space (the space will belong to the first text element, i.e. the "text " element).)
|
||||||
|
|
@ -543,7 +543,7 @@ TODO: check if spacing rules are language-specific and move this to language fil
|
||||||
|
|
||||||
### Identifiers
|
### Identifiers
|
||||||
|
|
||||||
Valid identifiers must be at least 1 caracters long and can contain anything except the caracters ``~`^+-=<>/[]*{}|\_!?,;:()"@&$#%`` (that is, every special caracter on a US keyboard except '). They can contain spaces. They can not start with a number.
|
Valid identifiers must be at least 1 characters long and can contain anything except the characters ``~`^+-=<>/[]*{}|\_!?,;:()"@&$#%`` (that is, every special character on a US keyboard except '). They can contain spaces. They can not start with a number.
|
||||||
|
|
||||||
When defining an identifier (using a function, checkpoint or variable delcaration line), it will be defined into the current namespace (defined by the parent function/checkpoint). When evaluating an expression, Anselme will look for variables into the current line's namespace, then go up a level if it isn't found, and so on. Note that the namespace of functions with arguments are not accessible from outside the function.
|
When defining an identifier (using a function, checkpoint or variable delcaration line), it will be defined into the current namespace (defined by the parent function/checkpoint). When evaluating an expression, Anselme will look for variables into the current line's namespace, then go up a level if it isn't found, and so on. Note that the namespace of functions with arguments are not accessible from outside the function.
|
||||||
|
|
||||||
|
|
@ -665,23 +665,15 @@ How conservions are handled from Lua to Anselme:
|
||||||
|
|
||||||
#### Escape codes
|
#### Escape codes
|
||||||
|
|
||||||
These can be used to represent some caracters in string and other text elements that would otherwise be difficult to express due to conflicts with Anselme syntax.
|
These can be used to represent some character in string and other text elements that would otherwise be difficult to express due to conflicts with Anselme syntax; for example to avoid a character at the start of a text line to be interpreted as another line type.
|
||||||
|
|
||||||
* `\\` for `\`
|
|
||||||
* `\"` for `"`
|
|
||||||
* `\n` for a newline
|
* `\n` for a newline
|
||||||
* `\t` for a tabulation
|
* `\t` for a tabulation
|
||||||
* `\{` and `\}` for `{` and `}`
|
* `\\` for `\`
|
||||||
* `\[` and `\]` for `[` and `]`
|
* `\"` for `"` to escape string delimiters
|
||||||
* `\~` for `~`
|
* `\{` and `\}` for `{` and `}` to escape text interpolation
|
||||||
* `\#` for `#`
|
* `\[` and `\]` for `[` and `]` to escape subtexts
|
||||||
* `\$` for `$`
|
* and, in general, for any character X we can get it by prefixing it with an `\`: `\X` for `X`
|
||||||
* `\(` for `(`
|
|
||||||
* `\>` for `>`
|
|
||||||
* `\%` for `%`
|
|
||||||
* `\§` for `§`
|
|
||||||
* `\@` for `@`
|
|
||||||
* `\:` for `:`
|
|
||||||
|
|
||||||
#### Truethness
|
#### Truethness
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,31 +53,12 @@ common = {
|
||||||
"{}"
|
"{}"
|
||||||
},
|
},
|
||||||
-- escapement code and their value in strings
|
-- escapement code and their value in strings
|
||||||
|
-- only includes the "special" escape codes, as the generic \. -> . is handled by default in parse_text
|
||||||
-- I don't think there's a point in supporting form feed, carriage return, and other printer and terminal related codes
|
-- I don't think there's a point in supporting form feed, carriage return, and other printer and terminal related codes
|
||||||
string_escapes = {
|
string_escapes = {
|
||||||
-- usual escape codes
|
|
||||||
["\\\\"] = "\\",
|
["\\\\"] = "\\",
|
||||||
["\\\""] = "\"",
|
|
||||||
["\\n"] = "\n",
|
["\\n"] = "\n",
|
||||||
["\\t"] = "\t",
|
["\\t"] = "\t",
|
||||||
-- string interpolation
|
|
||||||
["\\{"] = "{",
|
|
||||||
["\\}"] = "}",
|
|
||||||
-- subtext
|
|
||||||
["\\["] = "[",
|
|
||||||
["\\]"] = "]",
|
|
||||||
-- end of text line expressions
|
|
||||||
["\\~"] = "~",
|
|
||||||
["\\#"] = "#",
|
|
||||||
-- decorators
|
|
||||||
["\\$"] = "$",
|
|
||||||
-- line types
|
|
||||||
["\\("] = "(",
|
|
||||||
["\\>"] = ">",
|
|
||||||
["\\%"] = "%",
|
|
||||||
["\\§"] = "§",
|
|
||||||
["\\@"] = "@",
|
|
||||||
["\\:"] = ":",
|
|
||||||
},
|
},
|
||||||
-- list of possible injections and their associated name in vm.state.inject
|
-- list of possible injections and their associated name in vm.state.inject
|
||||||
injections = {
|
injections = {
|
||||||
|
|
@ -192,7 +173,9 @@ common = {
|
||||||
r = r2
|
r = r2
|
||||||
end
|
end
|
||||||
-- replace escape codes
|
-- replace escape codes
|
||||||
local escaped = t:gsub("\\.", common.string_escapes)
|
local escaped = t:gsub("\\.", function(escape)
|
||||||
|
return common.string_escapes[escape] or escape:match("^\\(.)$")
|
||||||
|
end)
|
||||||
table.insert(l, escaped)
|
table.insert(l, escaped)
|
||||||
end
|
end
|
||||||
-- expr
|
-- expr
|
||||||
|
|
|
||||||
|
|
@ -5,3 +5,5 @@ quote {"\""}
|
||||||
other codes {"\n"} {"\\"} {"\t"} \{braces}
|
other codes {"\n"} {"\\"} {"\t"} \{braces}
|
||||||
|
|
||||||
{"escaping expressions {"a"+"bc"} and \{stuff} \\ and quotes \""}
|
{"escaping expressions {"a"+"bc"} and \{stuff} \\ and quotes \""}
|
||||||
|
|
||||||
|
generic symbol {"\£"}
|
||||||
|
|
|
||||||
|
|
@ -1,70 +1,91 @@
|
||||||
local _={}
|
local _={}
|
||||||
_[25]={}
|
_[39]={}
|
||||||
_[24]={}
|
_[38]={}
|
||||||
_[23]={}
|
_[37]={}
|
||||||
_[22]={}
|
_[36]={}
|
||||||
_[21]={text="escaping expressions abc and {stuff} \\ and quotes \"",tags=_[25]}
|
_[35]={}
|
||||||
_[20]={text=" {braces}",tags=_[24]}
|
_[34]={}
|
||||||
_[19]={text="\9",tags=_[24]}
|
_[33]={}
|
||||||
_[18]={text=" ",tags=_[24]}
|
_[32]={}
|
||||||
_[17]={text="\\",tags=_[24]}
|
_[31]={}
|
||||||
_[16]={text=" ",tags=_[24]}
|
_[30]={}
|
||||||
_[15]={text="\n",tags=_[24]}
|
_[29]={}
|
||||||
_[14]={text="other codes ",tags=_[24]}
|
_[28]={}
|
||||||
_[13]={text="\"",tags=_[23]}
|
_[27]={}
|
||||||
_[12]={text="quote ",tags=_[23]}
|
_[26]={}
|
||||||
_[11]={text="a",tags=_[22]}
|
_[25]={tags=_[39],text="\194\163"}
|
||||||
_[10]={text="expression ",tags=_[22]}
|
_[24]={tags=_[38],text="generic symbol "}
|
||||||
_[9]={_[21]}
|
_[23]={tags=_[37],text="escaping expressions abc and {stuff} \\ and quotes \""}
|
||||||
_[8]={_[14],_[15],_[16],_[17],_[18],_[19],_[20]}
|
_[22]={tags=_[36],text=" {braces}"}
|
||||||
|
_[21]={tags=_[35],text="\9"}
|
||||||
|
_[20]={tags=_[34],text=" "}
|
||||||
|
_[19]={tags=_[33],text="\\"}
|
||||||
|
_[18]={tags=_[32],text=" "}
|
||||||
|
_[17]={tags=_[31],text="\n"}
|
||||||
|
_[16]={tags=_[30],text="other codes "}
|
||||||
|
_[15]={tags=_[29],text="\""}
|
||||||
|
_[14]={tags=_[28],text="quote "}
|
||||||
|
_[13]={tags=_[27],text="a"}
|
||||||
|
_[12]={tags=_[26],text="expression "}
|
||||||
|
_[11]={_[24],_[25]}
|
||||||
|
_[10]={_[23]}
|
||||||
|
_[9]={_[16],_[17],_[18],_[19],_[20],_[21],_[22]}
|
||||||
|
_[8]={_[14],_[15]}
|
||||||
_[7]={_[12],_[13]}
|
_[7]={_[12],_[13]}
|
||||||
_[6]={_[10],_[11]}
|
_[6]={"return"}
|
||||||
_[5]={"return"}
|
_[5]={"text",_[11]}
|
||||||
_[4]={"text",_[9]}
|
_[4]={"text",_[10]}
|
||||||
_[3]={"text",_[8]}
|
_[3]={"text",_[9]}
|
||||||
_[2]={"text",_[7]}
|
_[2]={"text",_[8]}
|
||||||
_[1]={"text",_[6]}
|
_[1]={"text",_[7]}
|
||||||
return {_[1],_[2],_[3],_[4],_[5]}
|
return {_[1],_[2],_[3],_[4],_[5],_[6]}
|
||||||
--[[
|
--[[
|
||||||
{ "text", { {
|
{ "text", { {
|
||||||
tags = <1>{},
|
tags = {},
|
||||||
text = "expression "
|
text = "expression "
|
||||||
}, {
|
}, {
|
||||||
tags = <table 1>,
|
tags = {},
|
||||||
text = "a"
|
text = "a"
|
||||||
} } }
|
} } }
|
||||||
{ "text", { {
|
{ "text", { {
|
||||||
tags = <1>{},
|
tags = {},
|
||||||
text = "quote "
|
text = "quote "
|
||||||
}, {
|
}, {
|
||||||
tags = <table 1>,
|
tags = {},
|
||||||
text = '"'
|
text = '"'
|
||||||
} } }
|
} } }
|
||||||
{ "text", { {
|
{ "text", { {
|
||||||
tags = <1>{},
|
tags = {},
|
||||||
text = "other codes "
|
text = "other codes "
|
||||||
}, {
|
}, {
|
||||||
tags = <table 1>,
|
tags = {},
|
||||||
text = "\n"
|
text = "\n"
|
||||||
}, {
|
}, {
|
||||||
tags = <table 1>,
|
tags = {},
|
||||||
text = " "
|
text = " "
|
||||||
}, {
|
}, {
|
||||||
tags = <table 1>,
|
tags = {},
|
||||||
text = "\\"
|
text = "\\"
|
||||||
}, {
|
}, {
|
||||||
tags = <table 1>,
|
tags = {},
|
||||||
text = " "
|
text = " "
|
||||||
}, {
|
}, {
|
||||||
tags = <table 1>,
|
tags = {},
|
||||||
text = "\t"
|
text = "\t"
|
||||||
}, {
|
}, {
|
||||||
tags = <table 1>,
|
tags = {},
|
||||||
text = " {braces}"
|
text = " {braces}"
|
||||||
} } }
|
} } }
|
||||||
{ "text", { {
|
{ "text", { {
|
||||||
tags = {},
|
tags = {},
|
||||||
text = 'escaping expressions abc and {stuff} \\ and quotes "'
|
text = 'escaping expressions abc and {stuff} \\ and quotes "'
|
||||||
} } }
|
} } }
|
||||||
|
{ "text", { {
|
||||||
|
tags = {},
|
||||||
|
text = "generic symbol "
|
||||||
|
}, {
|
||||||
|
tags = {},
|
||||||
|
text = "£"
|
||||||
|
} } }
|
||||||
{ "return" }
|
{ "return" }
|
||||||
]]--
|
]]--
|
||||||
|
|
@ -7,3 +7,5 @@ other codes \n \\ \t
|
||||||
decorators \# tag \~ condition \$ fn
|
decorators \# tag \~ condition \$ fn
|
||||||
|
|
||||||
sub \[text]
|
sub \[text]
|
||||||
|
|
||||||
|
generic symbol \£
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,30 @@
|
||||||
local _={}
|
local _={}
|
||||||
|
_[25]={}
|
||||||
|
_[24]={}
|
||||||
|
_[23]={}
|
||||||
|
_[22]={}
|
||||||
_[21]={}
|
_[21]={}
|
||||||
_[20]={}
|
_[20]={}
|
||||||
_[19]={}
|
_[19]={tags=_[25],text="generic symbol \194\163"}
|
||||||
_[18]={}
|
_[18]={tags=_[24],text="sub [text]"}
|
||||||
_[17]={}
|
_[17]={tags=_[23],text="decorators # tag ~ condition $ fn"}
|
||||||
_[16]={text="sub [text]",tags=_[21]}
|
_[16]={tags=_[22],text="other codes \n \\ \9"}
|
||||||
_[15]={text="decorators # tag ~ condition $ fn",tags=_[20]}
|
_[15]={tags=_[21],text="quote \""}
|
||||||
_[14]={text="other codes \n \\ \9",tags=_[19]}
|
_[14]={tags=_[20],text="expression {a}"}
|
||||||
_[13]={text="quote \"",tags=_[18]}
|
_[13]={_[19]}
|
||||||
_[12]={text="expression {a}",tags=_[17]}
|
_[12]={_[18]}
|
||||||
_[11]={_[16]}
|
_[11]={_[17]}
|
||||||
_[10]={_[15]}
|
_[10]={_[16]}
|
||||||
_[9]={_[14]}
|
_[9]={_[15]}
|
||||||
_[8]={_[13]}
|
_[8]={_[14]}
|
||||||
_[7]={_[12]}
|
_[7]={"return"}
|
||||||
_[6]={"return"}
|
_[6]={"text",_[13]}
|
||||||
_[5]={"text",_[11]}
|
_[5]={"text",_[12]}
|
||||||
_[4]={"text",_[10]}
|
_[4]={"text",_[11]}
|
||||||
_[3]={"text",_[9]}
|
_[3]={"text",_[10]}
|
||||||
_[2]={"text",_[8]}
|
_[2]={"text",_[9]}
|
||||||
_[1]={"text",_[7]}
|
_[1]={"text",_[8]}
|
||||||
return {_[1],_[2],_[3],_[4],_[5],_[6]}
|
return {_[1],_[2],_[3],_[4],_[5],_[6],_[7]}
|
||||||
--[[
|
--[[
|
||||||
{ "text", { {
|
{ "text", { {
|
||||||
tags = {},
|
tags = {},
|
||||||
|
|
@ -42,5 +46,9 @@ return {_[1],_[2],_[3],_[4],_[5],_[6]}
|
||||||
tags = {},
|
tags = {},
|
||||||
text = "sub [text]"
|
text = "sub [text]"
|
||||||
} } }
|
} } }
|
||||||
|
{ "text", { {
|
||||||
|
tags = {},
|
||||||
|
text = "generic symbol £"
|
||||||
|
} } }
|
||||||
{ "return" }
|
{ "return" }
|
||||||
]]--
|
]]--
|
||||||
Loading…
Add table
Add a link
Reference in a new issue