Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser development, added support for multiple elements #106

Merged
merged 2 commits into from
Jun 29, 2024

Conversation

xyz65535
Copy link
Contributor

@xyz65535 xyz65535 commented Jun 22, 2024

Details:

  • moved some code from lib/coradoc/parser/asciidoc/content.rb info appropriate files like block.rb, list.rb, paragraph.rb, table.rb
  • created parser rules for comments, include + Coradoc::Element classes
  • created parser rules for attribute list, comments, admonition
  • created rspec for attribute list
  • created parser rules for definition list, with the goal of it replacing glossaries rules
  • created parser rules for bold / highlight / italic, cross_reference
  • created transformer rules for attribute list, comments, include, text elements, inlines
  • fixed some things required for round-trip, for example to_adoc method in Coradoc::Element::TextElement now outputs all the information
  • created parslet rule called text_formatted, it's purpose will be to handle parsing inline elements within the text, that's still WIP
  • fixed some minor bugs that popped out during development of other things, for example olist_item parsing collided with sidebar block delimiter (****)
  • changed maybe to repeat(0) in multiple methods in Parser::Asciidoc::Section, this way instead of sometimes returning an empty string they always return an array even if it has 0 elements, this should allow to decrease number of transformer rules

Metanorma PR checklist

Copy link

codecov bot commented Jun 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.34%. Comparing base (defb04a) to head (a32cdeb).
Report is 82 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #106      +/-   ##
==========================================
+ Coverage   96.67%   98.34%   +1.66%     
==========================================
  Files          42       46       +4     
  Lines        1054     1327     +273     
==========================================
+ Hits         1019     1305     +286     
+ Misses         35       22      -13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

module Asciidoc
module Admonition
def admonition_type
str('NOTE') | str('TIP') | str('EDITOR') |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we want to allow defining "profiles" or "dialects" because Metanorma uses a special set that is not supported by the base language.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be cleanly overriden by subclassing and:

def admonition_type
  super | str("SOMETHING") | str("SOMETHING2")
end

).as(:positional)
end

def attribute_list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks arbitrarily limiting. Worse to worse please split those cases into separate methods with documentation.

(ulist_item >> newline.maybe).repeat(1)
end

def definition_list(delimiter = "::")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI the delimiter can be any number of colon signs.

@line_break = options.fetch(:line_break, "\n")
end

def to_adoc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use multiline string.

adoc = "#{@first_name}"
adoc << " #{@middle_name}" if @middle_name
adoc << " #{@last_name.to_s}"
adoc << " <#{@email}>\n" if @email
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use multiline string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would make the code much more unreadable; this code returns a single line.

to_hash.each do |key, value|
adoc << ":#{key}: #{value}\n"
end
adoc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just:

to_hash.map do |key, value|
  ":#{key}: #{value}"
end.join("\n")

metanorma#15 done
metanorma#16 added cross_references parser + transformer
metanorma#25 done
metanorma#31 missing parser code for parsing inline ellements in text
metanorma#36 created parser for attribute list for further use
metanorma#37 done parser for definition lists

- moved some code from lib/coradoc/parser/asciidoc/content.rb info appropriate files like block.rb, list.rb, paragraph.rb, table.rb
- created parser rules for comments, include + Coradoc::Element classes
- created parser rules for attribute list, comments, admonition
- created rspec for attribute list
- created parser rules for definition list, with the goal of it replacing glossaries rules
- created parser rules for bold / highlight / italic, cross_reference
- created transformer rules for attribute list, comments, include, text elements, inlines
- fixed some things required for round-trip, for example  to_adoc method in Coradoc::Element::TextElement now outputs all the information
- created parslet rule called "text_formatted", it's purpose will be to handle parsing inline elements within the text, that's still WIP
- fixed some minor bugs that popped out during development of other things, for example olist_item parsing collided with sidebar block delimiter (****)
- changed maybe to repeat(0) in multiple methods in Parser::Asciidoc::Section, this way instead of sometimes returning an empty string they always return an array even if it has 0 elements, this should allow to decrease number of transformer rules

Co-authored-by: hmdne <[email protected]>
@xyz65535 xyz65535 changed the title draft parser development, added support for multiple elements Jun 27, 2024
fixed failed rake in ruby 3.4
@webdev778 webdev778 requested a review from ronaldtse June 29, 2024 15:16
@webdev778 webdev778 merged commit d365dd0 into metanorma:main Jun 29, 2024
14 of 16 checks passed
hmdne added a commit to hmdne/coradoc that referenced this pull request Jul 1, 2024
hmdne added a commit to hmdne/coradoc that referenced this pull request Jul 1, 2024
This corrects metanorma#106

Co-authored-by: xyz65535 <[email protected]>
@hmdne hmdne mentioned this pull request Jul 1, 2024
4 tasks
ronaldtse pushed a commit that referenced this pull request Jul 1, 2024
This corrects #106

Co-authored-by: xyz65535 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants