Created
May 12, 2019 13:10
-
-
Save localhostdotdev/da8ed61c2c4d05a7ebc99f59af9e8480 to your computer and use it in GitHub Desktop.
liquid simplified peg from https://github.com/edgurgel/solid/blob/master/src/solid_parser.peg (erlang, works with https://github.com/seancribbs/neotoma)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
text <- string:blob (object:object text:text | |
/ tag:tag text:text | |
% / open_tag:open_tag text:text | |
/ open_object:open_object text:text)? | |
blob <- (!open_object !open_tag .)* | |
object <- open_object:open_object space (argument:argument filters:filters / argument:argument)? space close_object:close_object | |
tag <- cond_if_tag / cond_unless_tag / cond_case_tag / assign_tag / comment_tag | |
comment_tag <- open_tag space comment space close_tag text:text | |
open_tag space endcomment space close_tag | |
assign_tag <- open_tag space assign space field space "=" space argument space close_tag | |
cond_case_tag <- case_tag | |
when_tag+ | |
else_tag? | |
open_tag space endcase space close_tag | |
case_tag <- open_tag space case space argument space close_tag text:text | |
when_tag <- open_tag space when value close_tag text:text | |
cond_if_tag <- if_tag | |
elsif_tag* | |
else_tag? | |
open_tag space endif space close_tag | |
if_tag <- open_tag space if expression:boolean_expression close_tag text:text | |
elsif_tag <- open_tag space elsif expression:boolean_expression close_tag text:text | |
else_tag <- (open_tag space else space close_tag text:text) | |
unless_tag <- open_tag space unless expression:boolean_expression close_tag text:text | |
cond_unless_tag <- unless_tag | |
elsif_tag* | |
else_tag? | |
open_tag space endunless space close_tag | |
expression <- space (argument space operator space argument / boolean) space | |
boolean_expression <- expression ((and / or) expression)* | |
filters <- (space "|" space filter (":" space arguments)? )+ | |
arguments <- argument (space "," space argument)* | |
argument <- value:value / field | |
field <- [0-9a-zA-Z\._]* access* | |
access <- "[" int "]" | |
value <- space (string / number / true / false / null) space | |
string <- single_quoted_string / double_quoted_string | |
operator <- "==" / "!=" / ">=" / "<=" / ">" / "<" / "contains" | |
open_object <- "{{" | |
close_object <- "}}" | |
open_tag <- "{%" | |
close_tag <- "%}" | |
if <- "if" | |
else <- "else" | |
elsif <- "elsif" | |
endif <- "endif" | |
unless <- "unless" | |
endunless <- "endunless" | |
case <- "case" | |
when <- "when" | |
endcase <- "endcase" | |
assign <- "assign" | |
comment <- "comment" | |
endcomment <- "endcomment" | |
filter <- [a-zA-Z_]* | |
space <- [ \t\n\s\r]* | |
double_quoted_string <- '"' string:(!'"' ("\\\\" / '\\"' / .))* '"' | |
single_quoted_string <- "'" string:(!"'" ("\\\\" / "\\'" / .))* "'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment