Skip to content

Commit

Permalink
More helpful errors instead of crash on invalid docs syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
robojumper committed Oct 22, 2023
1 parent 339a38c commit 6ab1859
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
14 changes: 12 additions & 2 deletions .scripts/make_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,18 @@ def make_doc_item(sess, lines: List[str], file: str, span: Tuple[int, int],
"""
item = {}
# first line: meta info
for pair in lines[0].split(';'):
k, v = pair.strip().split(':')
first_line = lines[0].strip()
if first_line.endswith(';'):
first_line = first_line[:-1]
for pair in first_line.split(';'):
if pair == "":
sess.err(f"{file}:{span[0]+1}: too many semicolons in {HL_DOCS_KEYWORD} line")
continue
kvs = pair.strip().split(':')
if len(kvs) != 2:
sess.err(f"{file}:{span[0]+1}: not a key-value pair in {HL_DOCS_KEYWORD} line (expected key:value, got {pair})")
continue
k, v = kvs
if k in item:
sess.err(f"{file}:{span[0]+1}: duplicate key `{k}`")
if k == "feature" or k == "ref":
Expand Down
11 changes: 11 additions & 0 deletions test/docs/test_output/docs/misc/ILikeSemicolons.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Title: ILikeSemicolons

# ILikeSemicolons

Tracking Issue: [#53](https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/issues/53)

Deny this for aesthetic reasons

## Source code references

* [UnrealScriptFile2.uc:104-105](https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/blob/master/test_src/UnrealScriptFile2.uc#L104-L105)
11 changes: 11 additions & 0 deletions test/docs/test_output/docs/misc/TrailingSemi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Title: TrailingSemi

# TrailingSemi

Tracking Issue: [#99999](https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/issues/99999)

Trailing semicolons are allowed

## Source code references

* [UnrealScriptFile2.uc:98-99](https://github.com/X2CommunityCore/X2WOTCCommunityHighlander/blob/master/test_src/UnrealScriptFile2.uc#L98-L99)
Binary file modified test/docs/test_output/stdout.log
Binary file not shown.
9 changes: 9 additions & 0 deletions test/docs/test_src/UnrealScriptFile2.uc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ class UnrealScriptFile2 extends Object;
/// NewGameState: none,
/// ```

/// HL-Docs: feature:TrailingSemi;
/// Trailing semicolons are allowed

/// HL-Docs: feature;NotAKVP; issue:777
/// Semicolon instead of colon...

/// HL-Docs: feature:ILikeSemicolons;;; issue:53
/// Deny this for aesthetic reasons

function Abc()
{
/// HL-Docs: feature:IffyInclude; issue:9; tags:
Expand Down

0 comments on commit 6ab1859

Please sign in to comment.