Skip to content

Commit

Permalink
fix: Parse bullet lists correctly.
Browse files Browse the repository at this point in the history
The AST is incorrect, but at least we accept the variations of bullet
lists that appear in toxcore now.
  • Loading branch information
iphydf committed Mar 5, 2022
1 parent 5bd4f1b commit 870aa58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
33 changes: 22 additions & 11 deletions src/Language/Cimple/CommentParser.y
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import Data.Text (Text)
import qualified Data.Text as Text

import Language.Cimple.Ast (AssignOp (..), BinaryOp (..),
Comment, CommentF (..), Node,
NodeF (..))
Comment, CommentF (..))
import Language.Cimple.DescribeAst (describeLexeme, sloc)
import Language.Cimple.Lexer (Lexeme (..))
import Language.Cimple.ParseResult (ParseResult)
Expand All @@ -19,6 +18,8 @@ import Language.Cimple.Tokens (LexemeClass (..))

%name parseComment Comment

%expect 1

%error {parseError}
%errorhandlertype explist
%monad {ParseResult}
Expand Down Expand Up @@ -106,12 +107,18 @@ Command(x)

BulletListI :: { [NonTerm] }
BulletListI
: BulletI { [$1] }
| BulletListI BulletI { $2 : $1 }
: ' ' '-' WordsWithoutNewlines '\n' BulletICont { [Fix $ DocBullet $3 $5] }

BulletICont :: { [NonTerm] }
BulletICont
: { [] }
| BulletListI { $1 }
| 'INDENT1' BulletIContCont { $2 }

BulletI :: { NonTerm }
BulletI
: ' ' '-' WordsWithoutNewlines '\n' BulletListII { Fix $ DocBullet $3 (reverse $5) }
BulletIContCont :: { [NonTerm] }
BulletIContCont
: WordsWithoutNewlines { $1 }
| BulletIICont BulletListII { $1 : reverse $2 }

BulletListII :: { [NonTerm] }
BulletListII
Expand All @@ -120,15 +127,19 @@ BulletListII

BulletII :: { NonTerm }
BulletII
: 'INDENT1' '-' WordsWithoutNewlines '\n' BulletIIConts { Fix $ DocBullet ($3 ++ $5) [] }
: 'INDENT1' BulletIICont { $2 }

BulletIICont :: { NonTerm }
BulletIICont
: '-' WordsWithoutNewlines '\n' BulletIIConts { Fix $ DocBullet ($2 ++ $4) [] }

BulletIIConts :: { [NonTerm] }
BulletIIConts
: { [] }
| BulletIIConts BulletIICont { $1 ++ $2 }
| BulletIIConts BulletIIContCont { $1 ++ $2 }

BulletIICont :: { [NonTerm] }
BulletIICont
BulletIIContCont :: { [NonTerm] }
BulletIIContCont
: 'INDENT2' WordsWithoutNewlines '\n' { $2 }

IndentedSentence :: { [NonTerm] }
Expand Down
3 changes: 2 additions & 1 deletion src/Language/Cimple/Lexer.x
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ tokens :-
<cmtSC> "SPDX-License-Identifier:" { mkL CmtSpdxLicense }
<cmtSC> "GPL-3.0-or-later" { mkL CmtWord }
<cmtSC> "TODO("[^\)]+"):" { mkL CmtWord }
<cmtSC> [A-Z][A-Za-z]+"::"[a-z_]+ { mkL CmtWord }
<cmtSC> "E.g." { mkL CmtWord }
<cmtSC> "e.g." { mkL CmtWord }
<cmtSC> "I.e." { mkL CmtWord }
Expand Down Expand Up @@ -271,7 +272,7 @@ tokens :-
-- <code></code> blocks in comments.
<codeSC> " @endcode" { mkL CmtCode `andBegin` cmtSC }
<codeSC> "</code>" { mkL CmtCode `andBegin` cmtSC }
<codeSC> \n { mkL PpNewline `andBegin` codeNewlineSC }
<codeSC> \n { mkL CmtCode `andBegin` codeNewlineSC }
<codeSC> [^@\<]+ { mkL CmtCode }

<codeNewlineSC> " "+"*" { begin codeSC }
Expand Down

0 comments on commit 870aa58

Please sign in to comment.