Last active
March 27, 2017 12:01
-
-
Save clone1018/b17ef51ca1fd2e84e32754d35dd3956c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<template> | |
Everything inside of here would be tag_contents | |
<template> <-- this is where the parser fails with a syntax error | |
everything inside of here would still be tag_contents | |
</template> | |
</template> | |
<script> | |
everything in here would be tag_contents | |
</script> |
This file contains hidden or 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
Definitions. | |
% Helper Regexes (non-token) | |
ValidInTagName = [A-Za-z0-9] | |
ValidTagAttributeName = [A-Za-z\-] | |
ValidTagAttributeValue = [A-Za-z0-9\s="\-/:;,\.?\(\)@] | |
ValidTagAttribute = {ValidTagAttributeName}+=("|')?{ValidTagAttributeValue}+("|')? | |
ValidTags = (\s{ValidTagAttribute})* | |
ValidInsideTag = (.) | |
% Core HTML tokens | |
ROOT_TAG = \<root{ValidTags}\> | |
TEMPLATE_TAG = \<template{ValidTags}\> | |
SCRIPT_TAG = \<script{ValidTags}\> | |
START_TAG = \<{ValidInTagName}+{ValidTags}\> | |
END_TAG = \<\/{ValidInTagName}+\> | |
CHARACTER = {ValidInsideTag} | |
% Useful tokens | |
NEW_LINE = [\r\n]\s* | |
SELF_CLOSING_TAG = \<{ValidInTagName}+{ValidTags}\s\/\> | |
Rules. | |
{START_TAG} : {token, {start_tag, TokenLine, TokenChars}}. | |
{END_TAG} : {token, {end_tag, TokenLine, TokenChars}}. | |
{CHARACTER} : {token, {char, TokenLine, TokenChars}}. | |
{NEW_LINE} : skip_token. | |
Erlang code. |
This file contains hidden or 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
Terminals start_tag end_tag char. | |
Nonterminals tag tag_contents chars. | |
Rootsymbol tag. | |
tag -> start_tag end_tag : {unwrap('$1'), []}. | |
tag -> start_tag tag_contents end_tag : {unwrap('$1'), '$2'}. | |
tag_contents -> chars : ['$1']. | |
chars -> char chars : unicode:characters_to_binary([unwrap('$1')|'$2']). | |
chars -> char : unwrap('$1'). | |
Erlang code. | |
unwrap({_,_,V}) -> V. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment