celcheck - a tool to check the syntax of .ssc, .stc, .dsc (and new: .cel) files (Update 1.1!)

Here you find pointers to utilities that help you create addons for Celestia.
Avatar
Topic author
EarthMoon
Posts: 180
Joined: 02.07.2022
Age: 13
With us: 1 year 5 months
Location: Germany

celcheck - a tool to check the syntax of .ssc, .stc, .dsc (and new: .cel) files (Update 1.1!)

Post #1by EarthMoon » 11.10.2023, 12:47

I have created a new useful program: celcheck

It can check .ssc, .stc, .dsc and .cel files for their syntax (but not the values of each parameter). This can be useful if you have an ssc file which is very long (e.g. a long timeline with many parameters each) and you are unsure if you have closed all opened braces.

To use it:

Open a command line, run the file from there and pass the name to the .ssc/.stc/.dsc/.cel file as an argument, like this:

Code: Select all

celcheck myfile.ssc


Note: the script allows you to put ssc, stc, dsc objects and cel scripts together into one file, so if you have a large addon with two or more types of objects and scripts, you don't have to check each file separately but all in once.
This script doesn't check the names and values of the parameters (for compatibility reasons, one Celestia version has other/new paramaters than an older one).

Examples for defintions celcheck will mark as valid:

Code: Select all

"My object" "Sol/Parent" {
   Class "moon"
}

Modify "My other object" "Sol/Parent" {}

"" "" {}

# This definition has wrong values but celcheck doesn't care about that:
"My fourth object" "Sol/Parent" {
   Class 123
   Radius "invalid radius, but valid file"
   Texture [1 2 3]
   EllipticalOrbit true
   SomeUnknownParameter [1 [1 2] {Key "value"} true 1 3 false]
}


Invalid definitions:

Code: Select all

# [] instead of {}
"My object" "Sol/Parent" [
   Class "moon"
]

# Forget to specify the parent object
Modify "My other object" {}

# Forget the {}
"" ""

# The 'UniformRotation' parameter doesn't have a value +
# there is an unclosed { in the SomeUnknownParameter (or if it is closed by the end }, the main body isn't closed)
"My fourth object" "Sol/Parent" {
   Class 123
   Radius "invalid radius, but valid file"
   UniformRotation
   Texture [1 2 3]
   EllipticalOrbit true
   SomeUnknownParameter [1 [1 2] {Key "value" true 1 3 false]
}


Note: there must be at least one object definition in the file to be valid.



The script has been written in Python and uses the Lark parser.

How the script works internally:

1. Try to read input file
If everything runs well:
_2. Build the parser
_3. Parse the file
_If there are no errors:
__4. Tell the user that the file is valid
_If there are errors:
__4. Print the errors
If none is specified or it could not be read:
_2. print an appropriate message
5. Exit

Files for download:

celcheck_1.1.exe - binary program (note on file size: the script was built with Pyinstaller so don't wonder about the 112.57 MB)
source_code_1.1.zip - contains "celcheck.py" and "grammar.txt" (for anyone who wants to modify/fix bugs/extend the script, but you have to credit me if you publish that modifed version)

Update 1.1: Added support for .cel scripts! If you need an older version, comment below or PM me.
Attachments
source_code_1.1.zip
(1.22 KiB) Downloaded 28 times
celcheck_1.1.exe
(112.57 MiB) Downloaded 37 times
Last edited by EarthMoon on 28.10.2023, 07:24, edited 1 time in total.
Crew: "We are orbiting a black hole."
Control Center: "Do not fly too close to the black hole!"
Crew: "OH OOPS..."

Celestia versions:
1.6.3, 1.7.0 sRGB, 1.6.1 ED (plain)

Current projects:
Celestial (a Celestia-like program written in Python)

Avatar
Topic author
EarthMoon
Posts: 180
Joined: 02.07.2022
Age: 13
With us: 1 year 5 months
Location: Germany

Update 1.1! Added support for .cel scripts

Post #2by EarthMoon » 22.10.2023, 17:31

See the first post.
Crew: "We are orbiting a black hole."
Control Center: "Do not fly too close to the black hole!"
Crew: "OH OOPS..."

Celestia versions:
1.6.3, 1.7.0 sRGB, 1.6.1 ED (plain)

Current projects:
Celestial (a Celestia-like program written in Python)

Avatar
gironde M
Posts: 806
Joined: 16.12.2016
Age: 71
With us: 6 years 11 months
Location: Montigny-Les-Metz, France

Post #3by gironde » 05.11.2023, 10:14

sorry but I can't get it to work.
Where should we put the downloaded files and the file to check?
should we launch the celcheck.py file or the celcheck_1.1.exe file?

Avatar
Topic author
EarthMoon
Posts: 180
Joined: 02.07.2022
Age: 13
With us: 1 year 5 months
Location: Germany

Post #4by EarthMoon » 09.11.2023, 14:31

The celcheck.py file is the source code (but you can also use it if you want). I recommend the .exe file. The location of the exe and check file does not matter, although you then need to specifiy the full relative or absolute to the check file (the ssc/stc/dsc/cel file). Or drop the file on the exe (but you will have to be able to read very quickly as the exe terminates right after the check).
Crew: "We are orbiting a black hole."
Control Center: "Do not fly too close to the black hole!"
Crew: "OH OOPS..."

Celestia versions:
1.6.3, 1.7.0 sRGB, 1.6.1 ED (plain)

Current projects:
Celestial (a Celestia-like program written in Python)

Avatar
gironde M
Posts: 806
Joined: 16.12.2016
Age: 71
With us: 6 years 11 months
Location: Montigny-Les-Metz, France

Post #5by gironde » 10.11.2023, 11:38

the program cannot read the ssc file that I provide it :cry:

Avatar
Topic author
EarthMoon
Posts: 180
Joined: 02.07.2022
Age: 13
With us: 1 year 5 months
Location: Germany

Post #6by EarthMoon » 10.11.2023, 16:45

What are the contents of the ssc?
And what encoding has your ssc file?
What error message do you get?
Did you make sure the file exists and you have permissions to at least read it?
What command did you use to run celcheck?
Where are the file and the program on your system?
What is the current working dir in your command line window?

(Sorry for so many questions but I need to know all that as I don't know your exact situation except that "it cannot read the file")
Crew: "We are orbiting a black hole."
Control Center: "Do not fly too close to the black hole!"
Crew: "OH OOPS..."

Celestia versions:
1.6.3, 1.7.0 sRGB, 1.6.1 ED (plain)

Current projects:
Celestial (a Celestia-like program written in Python)

Avatar
gironde M
Posts: 806
Joined: 16.12.2016
Age: 71
With us: 6 years 11 months
Location: Montigny-Les-Metz, France

Post #7by gironde » 19.11.2023, 12:03

in cmd, I write:
celcheck_1.1 asteroids.ssc

both are in the same folder
asteroids.ssc is an asteroid declaration file that works in celestia (281310 lines et 5350Ko)

the result is:
"Could not read file 'asteroids.ssc'!
Make sure the file exists and you have read permissions"

with a file of the first 79 lines of the original (4Ko), the program works and the response is:
Specified file is valid.

there is a limit on the size of the accepted ssc file. Can you define this limit?

:hi:

Avatar
Topic author
EarthMoon
Posts: 180
Joined: 02.07.2022
Age: 13
With us: 1 year 5 months
Location: Germany

Post #8by EarthMoon » 20.11.2023, 09:29

Hmmm, that is weird. I did not specifiy a file size limit in the program, meaning this is really a bug and not intended. Could you send me the file so I can test it?
I am currently trying to find out what causes this issue with a self-made file and then with yours if needed.
Until it is fixed I suggest you to split your ssc into multiple smaller files for check and then merging all again.

Added after 25 minutes 25 seconds:
So, I have tested it with a self-made file which has 12339 asteroids (a bit more than yours which should have 281310/23=12231 asteroids, each definition+extra line has 23 lines) and 285086 lines and I don't get any errors when running (it only takes very long but that's to be expected when dealing with big files). So, possible causes could be:

- The file isn't existing (e.g. a tiny typo in the name, e.g. the real name is astreoids.ssc and you specify asteroids.ssc). You could check that with this way: Open Python, paste the file names from the command and the real file as strings connected with == in the interpreter ("filename_on_filesystem.ssc" == "filename_in_command.ssc") and then check if it's True. Or paste both names in a text editor in two lines below each other and then look if there are differences.
- It has a bad encoding (mine has UTF-8 and the program has only been tested with UTF-8 .ssc's).
- The file has bad newline chars (mine uses CR LF (\r\n))

Added after 12 minutes 8 seconds:
Could you run the command again, but with this test version, and post everything from the cmd in your next post?
Attachments
celcheck_test1.exe
(113.5 MiB) Downloaded 19 times
Crew: "We are orbiting a black hole."
Control Center: "Do not fly too close to the black hole!"
Crew: "OH OOPS..."

Celestia versions:
1.6.3, 1.7.0 sRGB, 1.6.1 ED (plain)

Current projects:
Celestial (a Celestia-like program written in Python)

Avatar
gironde M
Posts: 806
Joined: 16.12.2016
Age: 71
With us: 6 years 11 months
Location: Montigny-Les-Metz, France

Post #9by gironde » 22.11.2023, 19:27

hello,

name of file is asteroids.ssc
encode UTF-8

---------------------- First run -----------------------
D:\Public\Celestia extra\Celestia add\tools\Outil celcheck>celcheck_test1.exe asteroids.ssc
Traceback (most recent call last):
File "celcheck_test1.py", line 67, in <module>
File "encodings\cp1252.py", line 23, in decode
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 819162: character maps to <undefined>
[10632] Failed to execute script 'celcheck_test1' due to unhandled exception!

correction : removed a comment written in Russian
---------------------- 2e run -----------------------
D:\Public\Celestia extra\Celestia add\tools\Outil celcheck>celcheck_test1.exe asteroids.ssc
Specified file is invalid:
UnexpectedCharacters: No terminal matches '-' in the current parser context, at line 562 col 12

Texture ""-- "darkasteroid.dds"
^
correction : Texture "darkasteroid.dds"
Expected one of:
* RBRACE
* __ANON_2

---------------------- 3e run -----------------------
D:\Public\Celestia extra\Celestia add\tools\Outil celcheck>celcheck_test1.exe asteroids.ssc
Specified file is invalid:
UnexpectedCharacters: No terminal matches '.' in the current parser context, at line 31197 col 16

Eccentricity .187453063150358 -- normally accepted by celestia
^
correction : Eccentricity 0.187453063150358
Expected one of:
* LBRACE
* TRUE
* __ANON_1
* ESCAPED_STRING
* LSQB
* FALSE
* __ANON_0

---------------------- 4e run -----------------------
D:\Public\Celestia extra\Celestia add\tools\Outil celcheck>celcheck_test1.exe asteroids.ssc
Specified file is invalid:
UnexpectedCharacters: No terminal matches '-' in the current parser context, at line 131286 col 73

1973 UF1:1976 GC7:1976 JH:1986 UK" "Sol" -- AdeonaFamily (MBA-MBA)
^
correction : "Walford:4629 Walford:1986 TD7:1973 UF1:1976 GC7:1976 JH:1986 UK" "Sol" # AdeonaFamily (MBA-MBA)
Expected one of:
* LBRACE

---------------------- 5e run -----------------------
D:\Public\Celestia extra\Celestia add\tools\Outil celcheck>celcheck_test1.exe asteroids.ssc
Specified file is invalid:
UnexpectedCharacters: No terminal matches '"' in the current parser context, at line 179785 col 31

"Beslan:6374 Beslan:1986 PY4" "Sol" # (MBA-MBA)
^
correction : added the missing lines added the missing lines found in the original (asteroid 6369 to 6373)
Expected one of:
* RBRACE
* __ANON_2

---------------------- 6e run -----------------------
D:\Public\Celestia extra\Celestia add\tools\Outil celcheck>celcheck_test1.exe asteroids.ssc
Specified file is invalid:
UnexpectedCharacters: No terminal matches 'C' in the current parser context, at line 194551 col 2

Class "asteroid" -- no find error ??????
^
correction : no find error ??????
Expected one of:
* LBRACE

-----------------------------------------------------------------------------------------------------


-- after, more error of type '6e run'

the main blockage was the commentary in Russian

:clap: :clap: :clap:

Avatar
Topic author
EarthMoon
Posts: 180
Joined: 02.07.2022
Age: 13
With us: 1 year 5 months
Location: Germany

Post #10by EarthMoon » 23.11.2023, 08:15

1st run: I won't allow comments with non-ASCII caracters to make SSC files' comments readable for everyone and to prevent issues with Celestia (e.g. the right-to-left direction of the Arabian language).
3rd run: I forgot about this format of numbers. I will add that in a new version soon!
6th run: As the error tells, Celcheck expects a LBRACE (left brace, {) in that place, maybe you forgot (to open/close) a parameters block in one of the preceeding asteroids? Or you forgot to open the parameters block on this asteroid, like:

Code: Select all

"Name of Asteroid" "Sol"
    Class "asteroid"


If you cannot fix the issue, as I told in the last post, could you send me the file (e.g. as attachment or PM) so I can inspect what's wrong?
Crew: "We are orbiting a black hole."
Control Center: "Do not fly too close to the black hole!"
Crew: "OH OOPS..."

Celestia versions:
1.6.3, 1.7.0 sRGB, 1.6.1 ED (plain)

Current projects:
Celestial (a Celestia-like program written in Python)


Return to “Utilities”

Who is online