Writing a parser - Printable Version +- LDraw.org Discussion Forums (https://forums.ldraw.org) +-- Forum: LDraw Programs (https://forums.ldraw.org/forum-7.html) +--- Forum: LDraw File Processing and Conversion (https://forums.ldraw.org/forum-22.html) +--- Thread: Writing a parser (/thread-23904.html) |
Writing a parser - Michael Horvath - 2020-02-20 I'm starting to write my own parser that will convert an MPD file to JSON format. Are the FILE, Name:, Author:, !LICENSE, ROTATION properties case-sensitive? Will they always be the same case as I typed them or should I ignore case? Thanks. RE: Writing a parser - Jarema - 2020-02-20 Is good manner for parser to ignore case sensitive. This simplify your coding and open your world on a whole new opportunities. RE: Writing a parser - Orion Pobursky - 2020-02-20 (2020-02-20, 22:36)Michael Horvath Wrote: I'm starting to write my own parser that will convert an MPD file to JSON format. For METAs, per the spec: "In a META command, a keyword follows the line type in the line. The keyword must be in all caps" So I'd say that, yes, these commands are case-sensitive. filenames, however, are not. RE: Writing a parser - Michael Horvath - 2020-02-20 (2020-02-20, 22:57)Orion Pobursky Wrote: For METAs, per the spec: Are "Name:" and "Author:" META commands or some other type of command? [edit] Never mind. I see them listed in the docs. But you might want to update the "The keyword must be in all caps" bit since it's not always true. RE: Writing a parser - Orion Pobursky - 2020-02-21 (2020-02-20, 23:07)Michael Horvath Wrote: you might want to update the "The keyword must be in all caps" bit since it's not always true. Name: and Author: are the only exceptions for backwards compatibility and to prevent recycling the entire library. You can consider them case-sensitive as well. RE: Writing a parser - Michael Horvath - 2020-02-21 Also, what is the correct title for the "Unofficial Model" line? I have been calling it "blurb" because I don't know what to call it. RE: Writing a parser - Orion Pobursky - 2020-02-21 (2020-02-21, 3:02)Michael Horvath Wrote: Also, what is the correct title for the "Unofficial Model" line? I have been calling it "blurb" because I don't know what to call it. That meta is documented here: https://www.ldraw.org/article/218.html#filetype This is another tricky one because the <type> is case-insensitive (except for library files which have a more restrictive guideline). I didnt know that until I just read it in the spec. RE: Writing a parser - Michael Horvath - 2020-02-21 (2020-02-21, 4:04)Orion Pobursky Wrote: That meta is documented here: Okay, thanks. Does this mean all MOCs should use "Unofficial Model"? RE: Writing a parser - Lasse Deleuran - 2020-02-21 (2020-02-20, 22:36)Michael Horvath Wrote: I'm starting to write my own parser that will convert an MPD file to JSON format. There are some old files, either distributed with the AIOI or in OMR (can't remember where) where "0 file " is in lower case. If you ignore the case while detecting file headers, then you will face trouble with headers, such as: Code: 0 FILE File_cabinet.ldr My proposed solution for handling this is to: 1) Detect if there is any "0 FILE" statement. If such a statement exist, then only accept proper UPPER CASE 0 FILE statements 2) Otherwise, accept all "0 fILE" case insensitive statements as if they were "0 FILE" statements. RE: Writing a parser - Michael Horvath - 2020-02-22 (2020-02-21, 11:07)Lasse Deleuran Wrote: My proposed solution for handling this is to: Since there is no "DESCRIPTION" meta tag, I am interpreting the first commented line without any recognized meta tag as the model description. This does not eliminate every possible issue however. RE: Writing a parser - Michael Horvath - 2021-04-21 I forgot to post a link after I wrote this tool: https://github.com/mjhorvath/Datsville/tree/main/scripts/mpd2json It parses an MPD model and outputs a JSON representation of it. I then input the JSON file into several other tools I created to do different stuff. RE: Writing a parser - Gerald Lasser - 2021-04-21 (2021-04-21, 3:18)Michael Horvath Wrote: I forgot to post a link after I wrote this tool: Link is not working RE: Writing a parser - Michael Horvath - 2021-04-21 (2021-04-21, 6:40)Gerald Lasser Wrote: Link is not working Thanks, I fixed the issue. |