RelAst.flex 2.01 KB
Newer Older
Johannes Mey's avatar
Johannes Mey committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package org.jastadd.ros2rag.scanner;

import org.jastadd.ros2rag.parser.RelAstParser.Terminals;

%%

%public
%final
%class RelAstScanner
%extends beaver.Scanner

%type beaver.Symbol
%function nextToken
%yylexthrow beaver.Scanner.Exception
%scanerror RelAstScanner.ScannerError

%line
%column
%{
  private StringBuilder stringLitSb = new StringBuilder();

  private beaver.Symbol sym(short id) {
    return new beaver.Symbol(id, yyline + 1, yycolumn + 1, yylength(), yytext());
  }

  private beaver.Symbol sym(short id, String text) {
    return new beaver.Symbol(id, yyline + 1, yycolumn + 1, yylength(), text);
  }


  public static class ScannerError extends Error {
    public ScannerError(String message) {
      super(message);
    }
  }
%}

WhiteSpace = [ ] | \t | \f | \n | \r | \r\n
TraditionalComment   = [/][*][^*]*[*]+([^*/][^*]*[*]+)*[/]
EndOfLineComment = "//" [^\n\r]*
Comment = {TraditionalComment} | {EndOfLineComment}

ID = [a-zA-Z$_][a-zA-Z0-9$_]*

%%
{WhiteSpace} { /* ignore */ }
Johannes Mey's avatar
Johannes Mey committed
47
{Comment}    { return sym(Terminals.COMMENT); }
Johannes Mey's avatar
Johannes Mey committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

"abstract"   { return sym(Terminals.ABSTRACT); }
"rel"        { return sym(Terminals.RELATION); }

";"          { return sym(Terminals.SCOL); }
":"          { return sym(Terminals.COL); }
"::="        { return sym(Terminals.ASSIGN); }
"*"          { return sym(Terminals.STAR); }
"."          { return sym(Terminals.DOT); }
","          { return sym(Terminals.COMMA); }
"<"          { return sym(Terminals.LT); }
">"          { return sym(Terminals.GT); }
"["          { return sym(Terminals.LBRACKET); }
"]"          { return sym(Terminals.RBRACKET); }
"/"          { return sym(Terminals.SLASH); }
"?"          { return sym(Terminals.QUESTION_MARK); }
"->"         { return sym(Terminals.RIGHT); }
"<-"         { return sym(Terminals.LEFT); }
"<->"        { return sym(Terminals.BIDIRECTIONAL); }

// ID
{ID}         { return sym(Terminals.ID); }
<<EOF>>      { return sym(Terminals.EOF); }

[^]            { throw new ScannerError((yyline+1) +"," + (yycolumn+1) + ": Illegal character <"+yytext()+">"); }