@@ -184,6 +184,7 @@ local errorIfNotRunningMeta
184184local escapePattern
185185local F
186186local getFileContents , fileExists
187+ local getLineNumber
187188local getNextUsableToken
188189local insertTokenRepresentations
189190local isAny
@@ -365,6 +366,22 @@ function tokenize(s, path, allowBacktickStrings, allowMetaTokens)
365366 end
366367 end
367368
369+ if tok .long then
370+ -- Check for nesting of [[...]], which is depricated in Lua.
371+ local chunk , err = loadLuaString (" --" .. tok .representation )
372+ if not chunk then
373+ local lnInString , _err = err :match " ^%[string \" .-\" %]:(%d+): (.*)"
374+ if not _err then
375+ return nil , errorInFile (s , path , reprStart , " Tokenizer" , " Malformed long comment." )
376+ end
377+
378+ return nil , errorOnLine (
379+ path , getLineNumber (s , reprStart )+ tonumber (lnInString )- 1 ,
380+ " Tokenizer" , " Malformed long comment: %s" , _err
381+ )
382+ end
383+ end
384+
368385 tok .type = " comment"
369386 tok .representation = s :sub (reprStart , ptr - 1 )
370387
@@ -430,9 +447,18 @@ function tokenize(s, path, allowBacktickStrings, allowMetaTokens)
430447 end
431448 end
432449
433- local valueChunk = loadLuaString (" return" .. tok .representation )
450+ -- Check for nesting of [[...]], which is depricated in Lua.
451+ local valueChunk , err = loadLuaString (" return" .. tok .representation )
434452 if not valueChunk then
435- return nil , errorInFile (s , path , reprStart , " Tokenizer" , " Malformed long string." )
453+ local lnInString , _err = err :match " ^%[string \" .-\" %]:(%d+): (.*)"
454+ if not _err then
455+ return nil , errorInFile (s , path , reprStart , " Tokenizer" , " Malformed long string." )
456+ end
457+
458+ return nil , errorOnLine (
459+ path , getLineNumber (s , reprStart )+ tonumber (lnInString )- 1 ,
460+ " Tokenizer" , " Malformed long string: %s" , _err
461+ )
436462 end
437463
438464 local v = valueChunk ()
@@ -811,6 +837,11 @@ function isToken(tok, tokType, v)
811837 return tok .type == tokType and (v == nil or tok .value == v )
812838end
813839
840+ function getLineNumber (s , ptr )
841+ local _ , nlCount = s :sub (1 , ptr ):gsub (" \n " , " \n " )
842+ return 1 + nlCount
843+ end
844+
814845-- ==============================================================
815846-- = Preprocessor Functions =====================================
816847-- ==============================================================
0 commit comments