cad formats: comments are specs only
This commit is contained in:
1 parent
0bd7b87d2b
commit
8bd1a9327c
4 files changed
+22
-91
No files matched your search
@@ -1,16 +1,13 @@
|
||||
--!strict
|
||||
--!native
|
||||
-- cad/step/Write: header + entity instances -> ISO 10303-21 text. Values as cad/step/Parse produces them; strings
|
||||
-- re-escaped (' -> '', \ -> \\, UTF-8 outside printable ASCII -> \X2\..\X0\ / \X4\..\X0\, control bytes and invalid
|
||||
-- UTF-8 -> \X\hh), reals printed with the fewest digits (15..17) that read back to the same double. Never throws:
|
||||
-- failures return nil, message.
|
||||
-- cad/step/Write: header + entity instances -> ISO 10303-21 text (escaped strings, shortest round-trip reals).
|
||||
local Write = {}
|
||||
|
||||
local sformat, sbyte, ssub, sfind, floor, huge = string.format, string.byte, string.sub, string.find, math.floor, math.huge
|
||||
|
||||
local MAX_DEPTH = 100
|
||||
|
||||
-- the shortest %g form that reads back exactly, in Part 21 syntax (a '.' always, upper-case E)
|
||||
-- Part 21 real: a '.' always, upper-case E
|
||||
function Write.real(v: number): string?
|
||||
if v ~= v or v == huge or v == -huge then
|
||||
return nil
|
||||
@@ -45,7 +42,6 @@ local function hex(v: number, k: number): string
|
||||
return table.concat(out)
|
||||
end
|
||||
|
||||
-- a string's Part 21 literal (with the quotes)
|
||||
function Write.str(s: string): string
|
||||
if not sfind(s, "[^ -&(-[%]^-~]") then -- printable ASCII without ' and \
|
||||
return "'" .. s .. "'"
|
||||
@@ -72,7 +68,6 @@ function Write.str(s: string): string
|
||||
end
|
||||
i += 1
|
||||
else
|
||||
-- a UTF-8 sequence -> code point
|
||||
local cp: number? = nil
|
||||
local len = 1
|
||||
if c >= 0xC2 and c < 0xE0 then
|
||||
@@ -235,7 +230,6 @@ value = function(ctx: Ctx, v: any, real: boolean, depth: number): boolean
|
||||
end
|
||||
Write.value = value
|
||||
|
||||
-- record(ctx, type, args) -> appends TYPE(args)
|
||||
function Write.record(ctx: Ctx, t: any, args: any): boolean
|
||||
if not isName(t) then
|
||||
ctx.err = "bad entity type " .. tostring(t)
|
||||
|
||||
Reference in new issue
Block a user