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

Add Grammar Include Support #457

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
text=lf
*.js linguist-vendored eol=lf
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files.eol": "\n"
}
2 changes: 1 addition & 1 deletion packages/ohm-js/dist/ohm-grammar.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions packages/ohm-js/src/ohm-grammar.ohm
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Ohm {

Document
= Includes? Grammars

Includes
= IncludeStatement+

IncludeStatement
= include "'" relativeFilePath "'"

Grammars
= Grammar*

Expand Down Expand Up @@ -61,6 +70,12 @@ Ohm {
| terminal -- terminal
| "(" Alt ")" -- paren

include
= caseInsensitive<"include">
LiamRiddell marked this conversation as resolved.
Show resolved Hide resolved

relativeFilePath
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for choosing to allow these specific characters? Maybe I'm wrong, but it seems like it may be overly restrictive.

An alternative would be for Ohm to be completely agnostic about paths, and accept any character inside the quotes.

Copy link
Author

Choose a reason for hiding this comment

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

This is following security standards to always use an allowlist when you know the expected content format. If you want to accept the risk and open it to any character between the quotes we can do that.

= ~"'" (letter | digit | "-" | "\\" | "/" | ".")+

ruleDescr (a rule description)
= "(" ruleDescrText ")"

Expand Down
2 changes: 2 additions & 0 deletions ~/.gitconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[core]
autocrlf = false