1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 06:11:49 +03:00

Define Markdown.Term at * -> *.

This commit is contained in:
Rob Rix 2019-10-18 15:34:42 -04:00
parent a960957a3b
commit 51b64388ea
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7
2 changed files with 26 additions and 26 deletions

View File

@ -46,16 +46,16 @@ type Syntax =
, []
]
type Term = Term.Term (Sum Syntax) Loc
type Term = Term.Term (Sum Syntax)
type Assignment = Assignment.Assignment (Term.TermF [] CMarkGFM.NodeType) Grammar
assignment :: Assignment Term
assignment :: Assignment (Term Loc)
assignment = Syntax.handleError $ makeTerm <$> symbol Document <*> children (Markup.Document <$> many blockElement)
-- Block elements
blockElement :: Assignment Term
blockElement :: Assignment (Term Loc)
blockElement = choice
[ paragraph
, list
@ -67,10 +67,10 @@ blockElement = choice
, table
]
paragraph :: Assignment Term
paragraph :: Assignment (Term Loc)
paragraph = makeTerm <$> symbol Paragraph <*> children (Markup.Paragraph <$> many inlineElement)
list :: Assignment Term
list :: Assignment (Term Loc)
list = Term.termIn <$> symbol List <*> (makeList . Term.termFAnnotation . Term.termFOut <$> currentNode <*> children (many item))
where
makeList (CMarkGFM.LIST CMarkGFM.ListAttributes{..}) = case listType of
@ -78,42 +78,42 @@ list = Term.termIn <$> symbol List <*> (makeList . Term.termFAnnotation . Term.t
CMarkGFM.ORDERED_LIST -> inject . Markup.OrderedList
makeList _ = inject . Markup.UnorderedList
item :: Assignment Term
item :: Assignment (Term Loc)
item = makeTerm <$> symbol Item <*> children (many blockElement)
heading :: Assignment Term
heading :: Assignment (Term Loc)
heading = makeTerm <$> symbol Heading <*> (makeHeading . Term.termFAnnotation . Term.termFOut <$> currentNode <*> children (many inlineElement) <*> manyTill blockElement (void (symbol Heading) <|> eof))
where
makeHeading (CMarkGFM.HEADING level) = Markup.Heading level
makeHeading _ = Markup.Heading 0
blockQuote :: Assignment Term
blockQuote :: Assignment (Term Loc)
blockQuote = makeTerm <$> symbol BlockQuote <*> children (Markup.BlockQuote <$> many blockElement)
codeBlock :: Assignment Term
codeBlock :: Assignment (Term Loc)
codeBlock = makeTerm <$> symbol CodeBlock <*> (makeCode . Term.termFAnnotation . Term.termFOut <$> currentNode <*> source)
where
makeCode (CMarkGFM.CODE_BLOCK language _) = Markup.Code (nullText language)
makeCode _ = Markup.Code Nothing
thematicBreak :: Assignment Term
thematicBreak :: Assignment (Term Loc)
thematicBreak = makeTerm <$> token ThematicBreak <*> pure Markup.ThematicBreak
htmlBlock :: Assignment Term
htmlBlock :: Assignment (Term Loc)
htmlBlock = makeTerm <$> symbol HTMLBlock <*> (Markup.HTMLBlock <$> source)
table :: Assignment Term
table :: Assignment (Term Loc)
table = makeTerm <$> symbol Table <*> children (Markup.Table <$> many tableRow)
tableRow :: Assignment Term
tableRow :: Assignment (Term Loc)
tableRow = makeTerm <$> symbol TableRow <*> children (Markup.TableRow <$> many tableCell)
tableCell :: Assignment Term
tableCell :: Assignment (Term Loc)
tableCell = makeTerm <$> symbol TableCell <*> children (Markup.TableCell <$> many inlineElement)
-- Inline elements
inlineElement :: Assignment Term
inlineElement :: Assignment (Term Loc)
inlineElement = choice
[ strong
, emphasis
@ -127,40 +127,40 @@ inlineElement = choice
, softBreak
]
strong :: Assignment Term
strong :: Assignment (Term Loc)
strong = makeTerm <$> symbol Strong <*> children (Markup.Strong <$> many inlineElement)
emphasis :: Assignment Term
emphasis :: Assignment (Term Loc)
emphasis = makeTerm <$> symbol Emphasis <*> children (Markup.Emphasis <$> many inlineElement)
strikethrough :: Assignment Term
strikethrough :: Assignment (Term Loc)
strikethrough = makeTerm <$> symbol Strikethrough <*> children (Markup.Strikethrough <$> many inlineElement)
text :: Assignment Term
text :: Assignment (Term Loc)
text = makeTerm <$> symbol Text <*> (Markup.Text <$> source)
htmlInline :: Assignment Term
htmlInline :: Assignment (Term Loc)
htmlInline = makeTerm <$> symbol HTMLInline <*> (Markup.HTMLBlock <$> source)
link :: Assignment Term
link :: Assignment (Term Loc)
link = makeTerm <$> symbol Link <*> (makeLink . Term.termFAnnotation . Term.termFOut <$> currentNode) <* advance
where
makeLink (CMarkGFM.LINK url title) = Markup.Link url (nullText title)
makeLink _ = Markup.Link mempty Nothing
image :: Assignment Term
image :: Assignment (Term Loc)
image = makeTerm <$> symbol Image <*> (makeImage . Term.termFAnnotation . Term.termFOut <$> currentNode) <* advance
where
makeImage (CMarkGFM.IMAGE url title) = Markup.Image url (nullText title)
makeImage _ = Markup.Image mempty Nothing
code :: Assignment Term
code :: Assignment (Term Loc)
code = makeTerm <$> symbol Code <*> (Markup.Code Nothing <$> source)
lineBreak :: Assignment Term
lineBreak :: Assignment (Term Loc)
lineBreak = makeTerm <$> token LineBreak <*> pure Markup.LineBreak
softBreak :: Assignment Term
softBreak :: Assignment (Term Loc)
softBreak = makeTerm <$> token SoftBreak <*> pure Markup.LineBreak

View File

@ -95,7 +95,7 @@ typescriptParser = AssignmentParser (ASTParser tree_sitter_typescript) TypeScrip
tsxParser :: Parser TSX.Term
tsxParser = AssignmentParser (ASTParser tree_sitter_tsx) TSX.assignment
markdownParser :: Parser Markdown.Term
markdownParser :: Parser (Markdown.Term Loc)
markdownParser = AssignmentParser MarkdownParser Markdown.assignment