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
Iridar authored Oct 22, 2023
2 parents 339a38c + bf206d7 commit 7858d92
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 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)
18 changes: 15 additions & 3 deletions test/docs/test_output/stdout.log
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,19 @@ error: ./test_src/UnrealScriptFile2.uc:73: event block has error: expected _Toke
error: ./test_src/UnrealScriptFile2.uc:79: event block has error: expected _TokenType.KW (inoutness) while parsing tuple param, found _TokenType.IDENT (bool)
error: ./test_src/UnrealScriptFile2.uc:85: event block has error: expected _TokenType.IDENT (local name) while parsing EventData, found _TokenType.LBRACE
error: ./test_src/UnrealScriptFile2.uc:91: event block has error: expected _TokenType.COMMA (,) while parsing event specification after parsing EventData, found _TokenType.LBRACK
error: ./test_src/UnrealScriptFile2.uc:104: bad indentation for HL-Include:
error: ./test_src/UnrealScriptFile2.uc:107: bad indentation for HL-Include:
error: ./test_src/UnrealScriptFile2.uc:100: unclosed HL-Include:
error: ./test_src/UnrealScriptFile2.uc:98: missing key `issue`
error: ./test_src/UnrealScriptFile2.uc:98: missing key `tags`
note: use `tags:` to specify an empty tag list
error: ./test_src/UnrealScriptFile2.uc:101: not a key-value pair in HL-Docs: line (expected key:value, got feature)
error: ./test_src/UnrealScriptFile2.uc:101: not a key-value pair in HL-Docs: line (expected key:value, got NotAKVP)
error: ./test_src/UnrealScriptFile2.uc:101: missing key `feature` or `ref`
error: ./test_src/UnrealScriptFile2.uc:104: too many semicolons in HL-Docs: line
error: ./test_src/UnrealScriptFile2.uc:104: too many semicolons in HL-Docs: line
error: ./test_src/UnrealScriptFile2.uc:104: missing key `tags`
note: use `tags:` to specify an empty tag list
error: ./test_src/UnrealScriptFile2.uc:113: bad indentation for HL-Include:
error: ./test_src/UnrealScriptFile2.uc:116: bad indentation for HL-Include:
error: ./test_src/UnrealScriptFile2.uc:109: unclosed HL-Include:
error: duplicate feature definition `Bugfixes`
note: first definition due to builtin feature
note: this definition at ./test_src/UnrealScriptFile2.uc:35
Expand All @@ -34,8 +44,10 @@ ok: ./test_output/docs/misc/DupeFeature.md
ok: ./test_output/docs/misc/FeatWithBadTag.md
ok: ./test_output/docs/misc/FeatWithoutRest.md
ok: ./test_output/docs/strategy/FeatureFile1.md
ok: ./test_output/docs/misc/ILikeSemicolons.md
ok: ./test_output/docs/tactical/IncorrectIndentation.md
ok: ./test_output/docs/misc/TestEvent.md
ok: ./test_output/docs/misc/TrailingSemi.md
ok: ./test_output/docs/events.md
error: file ./test_output/docs/noncooltag.md not found (`noncooltag` is an unknown tag)
note: referred to by `FeatWithBadTag`
Expand Down
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 7858d92

Please sign in to comment.