2017-05-28 02:01:43 +00:00
|
|
|
package zclsyntax
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/zclconf/go-zcl/zcl"
|
|
|
|
)
|
|
|
|
|
2017-05-28 14:11:24 +00:00
|
|
|
// This file is generated from scan_tokens.rl. DO NOT EDIT.
|
2017-05-28 02:01:43 +00:00
|
|
|
%%{
|
2017-05-28 14:11:24 +00:00
|
|
|
# (except you are actually in scan_tokens.rl here, so edit away!)
|
2017-05-28 02:01:43 +00:00
|
|
|
|
|
|
|
machine zcltok;
|
|
|
|
write data;
|
|
|
|
}%%
|
|
|
|
|
2017-05-28 14:11:24 +00:00
|
|
|
func scanTokens(data []byte, filename string, start zcl.Pos) []Token {
|
|
|
|
f := &tokenAccum{
|
2017-05-28 02:01:43 +00:00
|
|
|
Filename: filename,
|
|
|
|
Bytes: data,
|
2017-05-28 15:38:13 +00:00
|
|
|
Pos: start,
|
2017-05-28 02:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
%%{
|
2017-05-28 16:16:53 +00:00
|
|
|
include UnicodeDerived "unicode_derived.rl";
|
2017-05-28 02:01:43 +00:00
|
|
|
|
|
|
|
UTF8Cont = 0x80 .. 0xBF;
|
|
|
|
AnyUTF8 = (
|
|
|
|
0x00..0x7F |
|
|
|
|
0xC0..0xDF . UTF8Cont |
|
|
|
|
0xE0..0xEF . UTF8Cont . UTF8Cont |
|
|
|
|
0xF0..0xF7 . UTF8Cont . UTF8Cont . UTF8Cont
|
|
|
|
);
|
|
|
|
BrokenUTF8 = any - AnyUTF8;
|
|
|
|
|
2017-05-28 15:56:43 +00:00
|
|
|
NumberLit = digit (digit|'.'|('e'|'E') ('+'|'-')? digit)*;
|
2017-05-28 16:16:53 +00:00
|
|
|
Ident = ID_Start ID_Continue*;
|
2017-05-28 15:56:43 +00:00
|
|
|
|
2017-05-28 16:34:20 +00:00
|
|
|
# Symbols that just represent themselves are handled as a single rule.
|
|
|
|
SelfToken = "{" | "}" | "[" | "]" | "(" | ")" | "." | "*" | "/" | "+" | "-" | "=" | "<" | ">" | "!" | "?" | ":" | "\n" | "&" | "|" | "~" | "^" | ";" | "`";
|
|
|
|
|
2017-05-28 02:01:43 +00:00
|
|
|
# Tabs are not valid, but we accept them in the scanner and mark them
|
|
|
|
# as tokens so that we can produce diagnostics advising the user to
|
|
|
|
# use spaces instead.
|
2017-05-28 15:38:13 +00:00
|
|
|
Tabs = 0x09+;
|
2017-05-28 02:01:43 +00:00
|
|
|
|
2017-05-28 15:38:13 +00:00
|
|
|
Spaces = ' '+;
|
2017-05-28 02:01:43 +00:00
|
|
|
|
2017-05-28 15:38:13 +00:00
|
|
|
main := |*
|
2017-05-28 15:56:43 +00:00
|
|
|
Spaces => {};
|
|
|
|
NumberLit => { token(TokenNumberLit) };
|
2017-05-28 16:16:53 +00:00
|
|
|
Ident => { token(TokenIdent) };
|
2017-05-28 16:34:20 +00:00
|
|
|
SelfToken => { selfToken() };
|
2017-05-28 15:56:43 +00:00
|
|
|
Tabs => { token(TokenTabs) };
|
|
|
|
AnyUTF8 => { token(TokenInvalid) };
|
|
|
|
BrokenUTF8 => { token(TokenBadUTF8) };
|
2017-05-28 15:38:13 +00:00
|
|
|
*|;
|
2017-05-28 02:01:43 +00:00
|
|
|
|
|
|
|
}%%
|
|
|
|
|
|
|
|
// Ragel state
|
|
|
|
cs := 0 // Current State
|
|
|
|
p := 0 // "Pointer" into data
|
|
|
|
pe := len(data) // End-of-data "pointer"
|
|
|
|
ts := 0
|
|
|
|
te := 0
|
|
|
|
act := 0
|
|
|
|
eof := pe
|
|
|
|
|
|
|
|
// Make Go compiler happy
|
|
|
|
_ = ts
|
|
|
|
_ = te
|
|
|
|
_ = act
|
|
|
|
_ = eof
|
|
|
|
|
2017-05-28 15:38:13 +00:00
|
|
|
token := func (ty TokenType) {
|
|
|
|
f.emitToken(ty, ts, te)
|
|
|
|
}
|
2017-05-28 16:34:20 +00:00
|
|
|
selfToken := func () {
|
|
|
|
b := data[ts:te]
|
|
|
|
if len(b) != 1 {
|
|
|
|
// should never happen
|
|
|
|
panic("selfToken only works for single-character tokens")
|
|
|
|
}
|
|
|
|
f.emitToken(TokenType(b[0]), ts, te)
|
|
|
|
}
|
2017-05-28 15:38:13 +00:00
|
|
|
|
2017-05-28 02:01:43 +00:00
|
|
|
%%{
|
|
|
|
write init;
|
|
|
|
write exec;
|
|
|
|
}%%
|
|
|
|
|
2017-05-28 14:11:24 +00:00
|
|
|
// If we fall out here without being in a final state then we've
|
|
|
|
// encountered something that the scanner can't match, which we'll
|
|
|
|
// deal with as an invalid.
|
|
|
|
if cs < zcltok_first_final {
|
|
|
|
f.emitToken(TokenInvalid, p, len(data))
|
|
|
|
}
|
|
|
|
|
2017-05-28 15:38:13 +00:00
|
|
|
// We always emit a synthetic EOF token at the end, since it gives the
|
|
|
|
// parser position information for an "unexpected EOF" diagnostic.
|
|
|
|
f.emitToken(TokenEOF, len(data), len(data))
|
|
|
|
|
2017-05-28 14:11:24 +00:00
|
|
|
return f.Tokens
|
2017-05-28 02:01:43 +00:00
|
|
|
}
|