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
e19d3a53
Commit
e19d3a53
authored
Dec 24, 2013
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parser and lexer is working ok
parent
2ded42e9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
53 deletions
+68
-53
grafana.sublime-project
+16
-16
src/app/services/graphite/lexer.js
+11
-5
src/app/services/graphite/parser.js
+23
-30
src/test/specs/lexer-specs.js
+1
-0
src/test/specs/parser-specs.js
+17
-2
No files found.
grafana.sublime-project
View file @
e19d3a53
{
"folders":
[
{
"follow_symlinks": true,
"path": ".",
"folder_exclude_patterns": [
"node_modules"
]
}
],
"settings":
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
}
"folders":
[
{
"follow_symlinks": true,
"path": ".",
"folder_exclude_patterns": [
"node_modules"
]
}
],
"settings":
{
"tab_size": 2,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
}
}
src/app/services/graphite/lexer.js
View file @
e19d3a53
...
...
@@ -339,7 +339,8 @@ define([
return
{
type
:
type
,
value
:
id
value
:
id
,
pos
:
this
.
char
};
},
...
...
@@ -407,7 +408,8 @@ define([
return {
type: 'number',
value: value,
isMalformed: true
isMalformed: true,
pos: this.char
};
}
...
...
@@ -422,7 +424,8 @@ define([
type: 'number',
value: value,
base: 16,
isMalformed: false
isMalformed: false,
pos: this.char
};
}
...
...
@@ -538,6 +541,7 @@ define([
type: 'number',
value: value,
base: 10,
pos: this.char,
isMalformed: !isFinite(value)
};
},
...
...
@@ -554,7 +558,8 @@ define([
case "
}
":
return {
type: ch1,
value: ch1
value: ch1,
pos: this.char
};
}
...
...
@@ -658,7 +663,8 @@ define([
type: '
string
',
value: value,
isUnclosed: false,
quote: quote
quote: quote,
pos: this.char
};
},
...
...
src/app/services/graphite/parser.js
View file @
e19d3a53
...
...
@@ -54,23 +54,17 @@ define([
if
(
this
.
match
(
'.'
))
{
this
.
index
++
;
var
rest
=
this
.
metricExpression
();
if
(
!
rest
)
{
this
.
errorMark
(
'Expected metric identifier'
);
return
null
;
}
node
.
segments
=
node
.
segments
.
concat
(
rest
.
segments
)
}
return
node
;
},
matchToken
:
function
(
type
,
index
)
{
var
token
=
this
.
tokens
[
this
.
index
+
index
];
return
(
token
===
undefined
&&
type
===
''
)
||
token
&&
token
.
type
===
type
;
},
match
:
function
(
token1
,
token2
)
{
return
this
.
matchToken
(
token1
,
0
)
&&
(
!
token2
||
this
.
matchToken
(
token2
,
1
))
},
functionCall
:
function
()
{
if
(
!
this
.
match
(
'identifier'
,
'('
))
{
return
null
;
...
...
@@ -86,7 +80,7 @@ define([
node
.
params
=
this
.
functionParameters
();
if
(
!
this
.
match
(
')'
))
{
this
.
error
=
'missing closing paranthesis'
;
this
.
error
Mark
(
'Expected closing paranthesis'
)
;
return
null
;
}
...
...
@@ -140,27 +134,26 @@ define([
};
},
isUnexpectedToken
:
function
(
expected
,
value
)
{
if
(
this
.
token
===
null
)
{
this
.
error
=
"Expected token: "
+
expected
+
" instead found end of string"
;
return
true
;
}
if
(
this
.
token
.
type
===
expected
)
{
return
false
;
}
if
(
value
&&
this
.
token
.
value
===
value
)
{
return
false
;
}
errorMark
:
function
(
text
)
{
var
currentToken
=
this
.
tokens
[
this
.
index
];
var
type
=
currentToken
?
currentToken
.
type
:
'end of string'
;
this
.
error
=
{
text
:
text
+
" instead found "
+
type
,
pos
:
currentToken
?
currentToken
.
pos
:
this
.
lexer
.
char
};
},
this
.
error
=
"Expected token "
+
expected
+
' instead found token '
+
this
.
token
.
type
+
' ("'
+
this
.
token
.
value
+
'")'
+
" at position: "
+
this
.
lexer
.
char
;
matchToken
:
function
(
type
,
index
)
{
var
token
=
this
.
tokens
[
this
.
index
+
index
];
return
(
token
===
undefined
&&
type
===
''
)
||
token
&&
token
.
type
===
type
;
},
return
true
;
match
:
function
(
token1
,
token2
)
{
return
this
.
matchToken
(
token1
,
0
)
&&
(
!
token2
||
this
.
matchToken
(
token2
,
1
))
},
};
return
Parser
;
...
...
src/test/specs/lexer-specs.js
View file @
e19d3a53
...
...
@@ -11,6 +11,7 @@ define([
expect
(
tokens
[
1
].
value
).
to
.
be
(
'.'
);
expect
(
tokens
[
2
].
type
).
to
.
be
(
'identifier'
);
expect
(
tokens
[
4
].
type
).
to
.
be
(
'identifier'
);
expect
(
tokens
[
4
].
pos
).
to
.
be
(
13
);
});
it
(
'should tokenize functions and args'
,
function
()
{
...
...
src/test/specs/parser-specs.js
View file @
e19d3a53
...
...
@@ -2,7 +2,7 @@ define([
'../../app/services/graphite/Parser'
],
function
(
Parser
)
{
describe
(
'when parsing
graphite expression
'
,
function
()
{
describe
(
'when parsing'
,
function
()
{
it
(
'simple metric expression'
,
function
()
{
var
parser
=
new
Parser
(
'metric.test.*.asd.count'
);
...
...
@@ -12,7 +12,6 @@ define([
expect
(
rootNode
.
type
).
to
.
be
(
'metric'
);
expect
(
rootNode
.
segments
.
length
).
to
.
be
(
5
);
expect
(
rootNode
.
segments
[
0
].
value
).
to
.
be
(
'metric'
);
});
it
(
'simple function'
,
function
()
{
...
...
@@ -60,6 +59,22 @@ define([
expect
(
rootNode
.
params
[
1
].
type
).
to
.
be
(
'metric'
);
});
it
(
'invalid metric expression'
,
function
()
{
var
parser
=
new
Parser
(
'metric.test.*.asd.'
);
var
rootNode
=
parser
.
getAst
();
expect
(
parser
.
error
.
text
).
to
.
be
(
'Expected metric identifier instead found end of string'
);
expect
(
parser
.
error
.
pos
).
to
.
be
(
19
);
});
it
(
'invalid function expression missing closing paranthesis'
,
function
()
{
var
parser
=
new
Parser
(
'sum(test'
);
var
rootNode
=
parser
.
getAst
();
expect
(
parser
.
error
.
text
).
to
.
be
(
'Expected closing paranthesis instead found end of string'
);
expect
(
parser
.
error
.
pos
).
to
.
be
(
9
);
});
});
});
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