File: sample1.rex

package info (click to toggle)
rexical 1.0.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 316 kB
  • sloc: ruby: 1,124; makefile: 8; ansic: 5
file content (43 lines) | stat: -rw-r--r-- 1,065 bytes parent folder | download
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
#
# sample1.rex
# lexical definition sample for rex
#
# usage
#  rex  sample1.rex  --stub
#  ruby sample1.rex.rb  sample1.c
#

class Sample1
macro
  BLANK         \s+
  REM_IN        \/\*
  REM_OUT       \*\/
  REM           \/\/

rule

# [:state]  pattern  [actions]

# remark
                {REM_IN}        { self.state = :REMS; [:rem_in, text] }
  :REMS         {REM_OUT}       { self.state = nil;   [:rem_out, text] }
  :REMS         .*(?={REM_OUT}) {                [:remark, text] }
                {REM}           { self.state = :REM;  [:rem_in, text] }
  :REM          \n              { self.state = nil;   [:rem_out, text] }
  :REM          .*(?=$)         {                [:remark, text] }

# literal
                \"[^"]*\"       { [:string, text] } # "
                \'[^']\'        { [:character, text] } # '

# skip
                {BLANK}         # no action

# numeric
                \d+             { [:digit, text.to_i] }

# identifier
                \w+             { [:word, text] }
                .               { [text, text] }

end