Skip to content

Commit

Permalink
Improved Sh lexer.
Browse files Browse the repository at this point in the history
  • Loading branch information
jgm committed Mar 11, 2010
1 parent f4bd744 commit 099582d
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions Text/Highlighting/Illuminate/Sh.x
Expand Up @@ -13,9 +13,7 @@ $symbol = [\~ \! \% \^ \* \( \) \+ \= \[ \] \\ \: \; \, \. \/ \? \& \< \> \| \%]
$hexdigit = [$digit A-F a-f]

@hexnumber = "0x" $hexdigit+
@number = [\+ \-]? (@hexnumber |
(($digit* \.)? $digit+ ([eE] [\+\-]? $digit+)?)
) u? (("int" ("8"|"16"|"32"|"64")) | L)?
@number = [\+ \-]? (@hexnumber | (($digit* \.)? $digit+ ([eE] [\+\-]? $digit+)?))
@keyword =("alias"|"bg"|"bind"|"break"|"builtin"|"caller"|"case"|"command"|"compgen"|
"complete"|"continue"|"declare"|"dirs"|"disown"|"do"|"done"|"elif"|"else"|"enable"|
"esac"|"eval"|"exec"|"exit"|"export"|"false"|"fc"|"fg"|"fi"|"for"|"getopts"|"hash"|"help"|
Expand All @@ -29,36 +27,24 @@ $hexdigit = [$digit A-F a-f]
tokens :-
<strsq> {
\'\'\' { tok String ==> popContext }
$white+ { tok Whitespace }
}
<strdq> {
\"\"\" { tok String ==> popContext }
$white+ { tok Whitespace }
}
<linecomment> {
@alert { tok Alert }
\n { tok Whitespace ==> popContext }
}
<def> {
[$alpha \_] $wordchar* { tok Function ==> popContext }
}
<0> {
\# { tok Comment ==> pushContext (linecomment, Comment) }
"import" / $white { tok Preproc }
@keyword / ~$wordchar { tok Keyword }
@number { tok Number }
@string { tok String }
\\ [\" \'] { tok Symbol }
$symbol { tok Symbol }
@string { tok String }
"function" $white+ @ident $white* ("()")? { tok Function }
@ident $white* "()" { tok Function }
-- # it is considered a variable if there's a =, which is discarded anyway
@ident / \= { tok VarId }
\$\{ [^ $white]+ \} { tok VarId }
\$ @ident { tok VarId }
\$ [^ $white]{1} { tok VarId }
@ident / \= { tok Variable }
\$\{ [^ $white]+ \} { tok Variable }
\$ @ident { tok Variable }
\$ [\* \? \@ \!] { tok Variable }
$symbol { tok Symbol }
[$alpha \_]$wordchar* { tok Plain }
$white+ { tok Whitespace }
Expand Down

0 comments on commit 099582d

Please sign in to comment.