Writing a parser


Writing a parser
#1
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.
Reply
RE: Writing a parser
#2
Is good manner for parser to ignore case sensitive. This simplify your coding and open your world on a whole new opportunities.
Lego isn't just a brand of plastic bricks. It's a lifestyle; and artistic medium.
Reply
RE: Writing a parser
#3
(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.

Are the FILE, Name:, Author:, !LICENSE, ROTATION properties case-sensitive? Will they always be the same case or should I ignore case?

Thanks.

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.
Reply
RE: Writing a parser
#4
(2020-02-20, 22:57)Orion Pobursky Wrote: 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.

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.
Reply
RE: Writing a parser
#5
(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.
Reply
RE: Writing a parser
#6
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.
Reply
RE: Writing a parser
#7
(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.
Reply
RE: Writing a parser
#8
(2020-02-21, 4:04)Orion Pobursky Wrote: 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.

Okay, thanks. Does this mean all MOCs should use "Unofficial Model"?
Reply
RE: Writing a parser
#9
(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.

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.

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
0 File cabinet for Miniland Figures
0 Name: 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.
Reply
RE: Writing a parser
#10
(2020-02-21, 11:07)Lasse Deleuran Wrote: 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.

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.
Reply
« Next Oldest | Next Newest »



Forum Jump:


Users browsing this thread: 1 Guest(s)