Skip to content

Commit

Permalink
Fix "use parser many times" and heredoc
Browse files Browse the repository at this point in the history
  • Loading branch information
btwael committed Aug 25, 2014
1 parent 2c882e2 commit 81cd35c
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 17 deletions.
23 changes: 21 additions & 2 deletions extras/mammouth.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ require["./context"] = (function() {var exports = {}, module = {exports: exports
[x] Fileinfo
[x] Filesystem
[x] Inotify
[ ] Mimetype
[x] Mimetype
[ ] Proctitle
[ ] xattr
[ ] xdiff
Expand Down Expand Up @@ -2579,13 +2579,31 @@ require["./lexer"] = (function() {var exports = {}, module = {exports: exports};
IDENTIFIER: /(([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)( [^\n\S]* : (?!:) )?)/,
NUMBER: /(0b[01]+|0o[0-7]+|0(x|X)[\da-fA-F]+|\d*\.?\d+(?:(e|E)[+-]?\d+)?)/,
STRING: /('[^\\']*(?:\\[\s\S][^\\']*)*'|"[^\\"]*(?:\\[\s\S][^\\"]*)*")/,
HEREDOC: /(((?!(\`))(.|[\n\r\u2028\u2029]|[\u0020\u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000]))*)/,
HEREDOC: /(((?!(\`|{{|}}))([\n\r\u2028\u2029]|.))*)/,
LineTerminator: /[\n\r\u2028\u2029]/,
Zs: /[\u0020\u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000]/,
SingleComment: /#(.*)+[\n\r\u2028\u2029]/,
MultiComment: /###(([\n\r\u2028\u2029]|.)*)###/
};

lexer.addRule(/^/, function(lexeme) {
IntoArray = false;
IntoMammouth = false;
IntoHereDoc = false;
Levels = [
{
IndentStack: [],
CurrentIndent: -1,
OpenedIndent: 0
}
];
OpenedParens = [];
lastIsIdentifier = false;
captureTypeCasting = false;
tokenStack = [];
return this.reject = true;
});

lexer.addRule(RegularExpression.PlainText, function(lexeme) {
if (!IntoMammouth) {
col += lexeme.length;
Expand Down Expand Up @@ -2667,6 +2685,7 @@ require["./lexer"] = (function() {var exports = {}, module = {exports: exports};
OpenedIndent: 0
}
];
OpenedParens = [];
lastIsIdentifier = false;
ShouldCloseCall = false;
captureTypeCasting = false;
Expand Down
4 changes: 2 additions & 2 deletions extras/mammouth.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/context.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion lib/lexer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 27 additions & 2 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Levels = [
OpenedParens = []

lastIsIdentifier = false
captureTypeCasting =false
captureTypeCasting = false
tokenStack = []

setToken = (token) ->
Expand Down Expand Up @@ -71,9 +71,11 @@ RegularExpression =
(
?!(
\`
|{{
|}}
)
)
(.|[\n\r\u2028\u2029]|[\u0020\u00A0\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000])
([\n\r\u2028\u2029]|.)
)*
) ///

Expand All @@ -83,6 +85,27 @@ RegularExpression =
SingleComment: /#(.*)+[\n\r\u2028\u2029]/
MultiComment: /###(([\n\r\u2028\u2029]|.)*)###/

# End of string
lexer.addRule /^/, (lexeme) ->
IntoArray = false
IntoMammouth = false
IntoHereDoc = false

Levels = [
{
IndentStack: []
CurrentIndent: -1
OpenedIndent: 0
}
]

OpenedParens = []

lastIsIdentifier = false
captureTypeCasting = false
tokenStack = []
@reject = true

# check for plain text
lexer.addRule RegularExpression.PlainText, (lexeme) ->
if not IntoMammouth
Expand Down Expand Up @@ -159,6 +182,8 @@ lexer.addRule RegularExpression.MammouthStart, ->
}
]

OpenedParens = []

lastIsIdentifier = false
ShouldCloseCall = false
captureTypeCasting =false
Expand Down
15 changes: 6 additions & 9 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ function heredoc (f) {
v = heredoc(function() {
/*
{{
switch day
when "Mon"
go(work)
when "Tue"
go(relax)
when "Thu"
go(iceFishing)
else
walloooo()
`sdfsdfsdfdsfsdsdfssdfssf
dsfsdfs
dd
fsdfsdfsd`
}}
*/
})
Expand Down

0 comments on commit 81cd35c

Please sign in to comment.