Skip to content

Commit 66d213b

Browse files
committed
Fixed newToken("string") sometimes making a comment instead of a string (oops). newToken("string") no longer forces long-form for strings with newlines.
1 parent 0327c63 commit 66d213b

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# LuaPreprocess
22

3-
![version 1.1](https://img.shields.io/badge/version-1.1-limegreen.svg)
3+
![version 1.1.1](https://img.shields.io/badge/version-1.1.1-limegreen.svg)
44

55
A small and straightforward Lua preprocessor featuring a simple syntax.
66
Write embedded metaprograms to generate code using normal Lua inside your Lua files.

preprocess.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
8888
--============================================================]]
8989

90-
local VERSION = "1.1.0"
90+
local VERSION = "1.1.1"
9191

9292
local KEYWORDS = {
9393
"and","break","do","else","elseif","end","false","for","function","if","in",
@@ -792,7 +792,7 @@ end
792792
-- keywordToken = newToken( "keyword", keyword )
793793
-- numberToken = newToken( "number", number [, numberFormat="auto" ] )
794794
-- punctuationToken = newToken( "punctuation", symbol )
795-
-- stringToken = newToken( "string", contents [, forceLongForm=false ] )
795+
-- stringToken = newToken( "string", contents [, longForm=false ] )
796796
-- whitespaceToken = newToken( "whitespace", contents )
797797
-- preprocessorToken = newToken( "pp_entry", isDouble )
798798
--
@@ -887,7 +887,7 @@ function metaFuncs.newToken(tokType, ...)
887887

888888
elseif tokType == "string" then
889889
local s, long = ...
890-
long = not not (long or s:find"[\r\n]")
890+
long = not not long
891891

892892
local repr
893893
if long then
@@ -897,7 +897,7 @@ function metaFuncs.newToken(tokType, ...)
897897
equalSigns = equalSigns.."="
898898
end
899899

900-
repr = F("--[%s[%s]%s]", equalSigns, s, equalSigns)
900+
repr = F("[%s[%s]%s]", equalSigns, s, equalSigns)
901901

902902
else
903903
repr = F("%q", s):gsub("\\\n", "\\n")

test.lua2p

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ print("The end.")
5959
!(
6060
--[==[ Test token stuff.
6161
for i, token in ipairs(assert(tokenize(getFileContents"testInclude.lua"))) do
62-
print(i, token.type, "", (token.representation:gsub("\n", "\\n")))
62+
print(i, token.type, "", (token.representation:gsub("\n", "<NEWLINE>")))
6363
end
6464

6565
for _, token in ipairs{
@@ -90,23 +90,23 @@ for _, token in ipairs{
9090
newToken("string", "Hello", true),
9191
newToken("string", "Hello\nworld"),
9292
newToken("string", "Hello\nworld", true),
93-
newToken("string", "Hello\n12]]34"),
94-
newToken("string", "Hello\n12]]=]34"),
93+
newToken("string", "Hello\n12]]34", true),
94+
newToken("string", "Hello\n12]]=]34", true),
9595
newToken("whitespace", " \t\n"),
9696
-- newToken("whitespace", "foo"), -- Error!
9797
newToken("pp_entry", false),
9898
newToken("pp_entry", true),
9999
-- newToken("nope", nil), -- Error!
100100
} do
101101
print("------------------------")
102-
print('type ', token.type)
103-
print('value ', (tostring(token.value):gsub("\n", "\\n")))
104-
print('repr ', (token.representation:gsub("\n", "\\n")))
102+
print("type ", token.type)
103+
print("value ", (tostring(token.value):gsub("\n", "<NEWLINE>")))
104+
print("repr ", (token.representation :gsub("\n", "<NEWLINE>")))
105105
if token.long ~= nil then
106-
print('long ', token.long)
106+
print("long ", token.long)
107107
end
108108
if token.double ~= nil then
109-
print('double', token.double)
109+
print("double", token.double)
110110
end
111111
end
112112
--]==]

0 commit comments

Comments
 (0)