You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently developing a parser that can parse certain mathematical expressions. On top of that, I want to be able to parse these expressions within html files. To do this, I copied a pest grammar for HTML and copied it into my existing grammar. The main problem that I am having with this is the fact that the COMMENT (and also WHITESPACE) rules are now unusable for me because the HTML and the mathematical expression have different comment and whitespacing needs. I also don't like the fact that my grammar does now contain multiple languages without a clear separation.
My proposal:
Allow including one pest grammar in another (e.g. html = include html.pest)
All rules of the included grammar are usable in the other grammar, preferably with a prefix so there are no duplicate names (e.g. html:node instead of just node (which is defined in html.pest)
Both grammars do still use the COMMENT and WHITESPACE rules as described in their own file
Other cases
An html parser might for example also want to use a pest grammar for css and js, and that would be a lot easier with the include function.
Alternative
Including all rules might be a bit to much and give problems with contradicting COMMENT and WHITESPACE values, but just including one rule like expression or html_document or js_code or css_style from another grammar would help. The other rules defined in the subgrammars would still exist and be usable in the parsing code, but not in the main pest file itself.
Current solution
I currently parse the html with an HTML parser (with its own grammar) and have special rule expression. Each expression that I parse, is than parse with to parser for mathematical expressions. This works, but has some drawbacks like much harder line number detection etc.
What do you think? Is this something that seems useful or am I missing something?
The text was updated successfully, but these errors were encountered:
A little context
I am currently developing a parser that can parse certain mathematical expressions. On top of that, I want to be able to parse these expressions within html files. To do this, I copied a pest grammar for HTML and copied it into my existing grammar. The main problem that I am having with this is the fact that the
COMMENT
(and alsoWHITESPACE
) rules are now unusable for me because the HTML and the mathematical expression have different comment and whitespacing needs. I also don't like the fact that my grammar does now contain multiplelanguages
without a clear separation.My proposal:
html = include html.pest
)html:node
instead of justnode
(which is defined in html.pest)COMMENT
andWHITESPACE
rules as described in their own fileOther cases
Alternative
COMMENT
andWHITESPACE
values, but just including one rule likeexpression
orhtml_document
orjs_code
orcss_style
from another grammar would help. The other rules defined in thesubgrammars
would still exist and be usable in the parsing code, but not in themain
pest file itself.Current solution
I currently parse the html with an HTML parser (with its own grammar) and have special rule
expression
. Each expression that I parse, is than parse with to parser for mathematical expressions. This works, but has some drawbacks like much harder line number detection etc.What do you think? Is this something that seems useful or am I missing something?
The text was updated successfully, but these errors were encountered: