Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
89224401
Commit
89224401
authored
Jan 29, 2014
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #38, Lexer & parser now handles metrics segments that begin with numbers or only have numbers
parent
1c17c866
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
18 deletions
+33
-18
src/app/services/graphite/lexer.js
+4
-4
src/app/services/graphite/parser.js
+3
-3
src/test/specs/lexer-specs.js
+15
-11
src/test/specs/parser-specs.js
+11
-0
No files found.
src/app/services/graphite/lexer.js
View file @
89224401
...
...
@@ -116,6 +116,7 @@ define([
for
(
var
i
=
0
;
i
<
128
;
i
++
)
{
identifierStartTable
[
i
]
=
i
>=
48
&&
i
<=
57
||
// 0-9
i
===
36
||
// $
i
>=
65
&&
i
<=
90
||
// A-Z
i
===
95
||
// _
...
...
@@ -183,10 +184,10 @@ define([
}
match
=
this
.
scanIdentifier
()
||
this
.
scanTemplateSequence
()
||
this
.
scanPunctuator
()
||
this
.
scanNumericLiteral
();
this
.
scanNumericLiteral
()
||
this
.
scanIdentifier
()
||
this
.
scanTemplateSequence
();
if
(
match
)
{
this
.
skip
(
match
.
value
.
length
);
...
...
@@ -402,7 +403,6 @@ define([
}
// Numbers must start either with a decimal digit or a point.
if (char !== "
.
" && !isDecimalDigit(char)) {
return null;
}
...
...
src/app/services/graphite/parser.js
View file @
89224401
...
...
@@ -66,7 +66,7 @@ define([
return
curly
;
}
if
(
this
.
match
(
'identifier'
))
{
if
(
this
.
match
(
'identifier'
)
||
this
.
match
(
'number'
)
)
{
return
{
type
:
'segment'
,
value
:
this
.
consumeToken
().
value
...
...
@@ -97,7 +97,7 @@ define([
},
metricExpression
:
function
()
{
if
(
!
this
.
match
(
'templateStart'
)
&&
!
this
.
match
(
'identifier'
))
{
if
(
!
this
.
match
(
'templateStart'
)
&&
!
this
.
match
(
'identifier'
)
&&
!
this
.
match
(
'number'
)
)
{
return
null
;
}
...
...
@@ -153,8 +153,8 @@ define([
var
param
=
this
.
functionCall
()
||
this
.
metricExpression
()
||
this
.
numericLiteral
()
||
this
.
metricExpression
()
||
this
.
stringLiteral
();
if
(
!
this
.
match
(
','
))
{
...
...
src/test/specs/lexer-specs.js
View file @
89224401
...
...
@@ -31,21 +31,25 @@ define([
expect
(
tokens
[
6
].
value
).
to
.
be
(
'second'
);
});
it
(
'should tokenize metric expression with number segments'
,
function
()
{
var
lexer
=
new
Lexer
(
"metric.10.12_10.test"
);
var
tokens
=
lexer
.
tokenize
();
expect
(
tokens
[
0
].
type
).
to
.
be
(
'identifier'
);
expect
(
tokens
[
2
].
type
).
to
.
be
(
'identifier'
);
expect
(
tokens
[
2
].
value
).
to
.
be
(
'10'
);
expect
(
tokens
[
4
].
value
).
to
.
be
(
'12_10'
);
expect
(
tokens
[
4
].
type
).
to
.
be
(
'identifier'
);
});
it
(
'should tokenize func
tions and args
'
,
function
()
{
var
lexer
=
new
Lexer
(
"s
um(metric.test, 12, 'test'
)"
);
it
(
'should tokenize func
call with numbered metric and number arg
'
,
function
()
{
var
lexer
=
new
Lexer
(
"s
cale(metric.10, 15
)"
);
var
tokens
=
lexer
.
tokenize
();
expect
(
tokens
[
0
].
value
).
to
.
be
(
'sum'
);
expect
(
tokens
[
0
].
type
).
to
.
be
(
'identifier'
);
expect
(
tokens
[
1
].
value
).
to
.
be
(
'(
'
);
expect
(
tokens
[
1
].
type
).
to
.
be
(
'(
'
);
expect
(
tokens
[
5
].
type
).
to
.
be
(
',
'
);
expect
(
tokens
[
5
].
value
).
to
.
be
(
',
'
);
expect
(
tokens
[
2
].
type
).
to
.
be
(
'identifier
'
);
expect
(
tokens
[
2
].
value
).
to
.
be
(
'metric
'
);
expect
(
tokens
[
4
].
value
).
to
.
be
(
'10
'
);
expect
(
tokens
[
4
].
type
).
to
.
be
(
'number
'
);
expect
(
tokens
[
6
].
type
).
to
.
be
(
'number'
);
expect
(
tokens
[
6
].
value
).
to
.
be
(
'12'
);
expect
(
tokens
[
8
].
type
).
to
.
be
(
'string'
);
expect
(
tokens
[
8
].
value
).
to
.
be
(
'test'
);
expect
(
tokens
[
tokens
.
length
-
1
].
value
).
to
.
be
(
')'
);
});
it
(
'should tokenize metric with template parameter'
,
function
()
{
...
...
src/test/specs/parser-specs.js
View file @
89224401
...
...
@@ -13,6 +13,17 @@ define([
expect
(
rootNode
.
segments
[
0
].
value
).
to
.
be
(
'metric'
);
});
it
(
'simple metric expression with numbers in segments'
,
function
()
{
var
parser
=
new
Parser
(
'metric.10.15_20.5'
);
var
rootNode
=
parser
.
getAst
();
expect
(
rootNode
.
type
).
to
.
be
(
'metric'
);
expect
(
rootNode
.
segments
.
length
).
to
.
be
(
4
);
expect
(
rootNode
.
segments
[
1
].
value
).
to
.
be
(
'10'
);
expect
(
rootNode
.
segments
[
2
].
value
).
to
.
be
(
'15_20'
);
expect
(
rootNode
.
segments
[
3
].
value
).
to
.
be
(
'5'
);
});
it
(
'simple metric expression with curly braces'
,
function
()
{
var
parser
=
new
Parser
(
'metric.se1-{count, max}'
);
var
rootNode
=
parser
.
getAst
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment