1 %{ 2 // Copyright 2018 The Prometheus Authors 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package textparse 16 17 import ( 18 "fmt" 19 ) 20 21 // Lex is called by the parser generated by "go tool yacc" to obtain each 22 // token. The method is opened before the matching rules block and closed at 23 // the end of the file. func(l * openMetricsLexer)24func (l *openMetricsLexer) Lex() token { 25 if l.i >= len(l.b) { 26 return tEOF 27 } 28 c := l.b[l.i] 29 l.start = l.i 30 31 %} 32 33 D [0-9] 34 L [a-zA-Z_] 35 M [a-zA-Z_:] 36 C [^\n] 37 S [ ] 38 39 %x sComment sMeta1 sMeta2 sLabels sLValue sValue sTimestamp sExemplar sEValue sETimestamp 40 41 %yyc c 42 %yyn c = l.next() 43 %yyt l.state 44 45 46 %% 47 48 #{S} l.state = sComment 49 <sComment>HELP{S} l.state = sMeta1; return tHelp 50 <sComment>TYPE{S} l.state = sMeta1; return tType 51 <sComment>UNIT{S} l.state = sMeta1; return tUnit 52 <sComment>"EOF"\n? l.state = sInit; return tEOFWord 53 <sMeta1>{M}({M}|{D})* l.state = sMeta2; return tMName 54 <sMeta2>{S}{C}*\n l.state = sInit; return tText 55 56 {M}({M}|{D})* l.state = sValue; return tMName 57 <sValue>\{ l.state = sLabels; return tBraceOpen 58 <sLabels>{L}({L}|{D})* return tLName 59 <sLabels>\} l.state = sValue; return tBraceClose 60 <sLabels>= l.state = sLValue; return tEqual 61 <sLabels>, return tComma 62 <sLValue>\"(\\.|[^\\"\n])*\" l.state = sLabels; return tLValue 63 <sValue>{S}[^ \n]+ l.state = sTimestamp; return tValue 64 <sTimestamp>{S}[^ \n]+ return tTimestamp 65 <sTimestamp>\n l.state = sInit; return tLinebreak 66 <sTimestamp>{S}#{S}\{ l.state = sExemplar; return tComment 67 68 <sExemplar>{L}({L}|{D})* return tLName 69 <sExemplar>\} l.state = sEValue; return tBraceClose 70 <sExemplar>= l.state = sEValue; return tEqual 71 <sEValue>\"(\\.|[^\\"\n])*\" l.state = sExemplar; return tLValue 72 <sExemplar>, return tComma 73 <sEValue>{S}[^ \n]+ l.state = sETimestamp; return tValue 74 <sETimestamp>{S}[^ \n]+ return tTimestamp 75 <sETimestamp>\n l.state = sInit; return tLinebreak 76 77 %% 78 79 return tInvalid 80 } 81