File: txtin_lexer.mll

package info (click to toggle)
orpie 1.5.2-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,924 kB
  • ctags: 2,720
  • sloc: ml: 13,872; ansic: 3,754; makefile: 310; sh: 11; python: 11
file content (80 lines) | stat: -rw-r--r-- 2,254 bytes parent folder | download | duplicates (2)
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
47
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
73
74
75
76
77
78
79
80
(*  Orpie -- a fullscreen RPN calculator for the console
 *  Copyright (C) 2003-2004, 2005, 2006-2007, 2010 Paul Pelzl
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License, Version 2,
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Please send bug reports, patches, etc. to Paul Pelzl at 
 *  <pelzlpj@gmail.com>.
 *)

(* txtin_lexer.mll
 *
 * Orpie can handle input of data from a textfile created by an external editor.
 * editor_lexer.mll generates a lexer that tokenizes this data.
 *)

{
   open Txtin_parser
}

(* space, tab, CR, linefeed, vertical tab *)
let whitespace    = [' ' '\010' '\013' '\009' '\012']
let digit         = ['0'-'9']
let hex_digit     = ['0'-'9' 'a'-'f' 'A'-'F']
let base_ident    = ['b' 'o' 'd' 'h']
let sign          = ['-' '+']
let variable_char = ['a'-'z' 'A'-'Z' '0'-'9' '-' '_']
let units         = ['a'-'z' 'A'-'Z' '0'-'9' '.' '-' '*' '/' '^']

rule token =
   parse whitespace+ {token lexbuf}
   | '#' sign? hex_digit+ '`' base_ident {
      let s = Lexing.lexeme lexbuf in
      let int_str = String.sub s 1 (String.length s - 1) in
      INTEGER int_str}

   | '@' variable_char+ {
      let s = Lexing.lexeme lexbuf in
      let var_str = String.sub s 1 (String.length s - 1) in
      VARIABLE var_str}

   | ((sign? digit+ ('.' digit*)?) | (sign? digit* '.' digit+)) ('e' sign? digit+)? {
      FLOAT (Lexing.lexeme lexbuf)}

   | '_' units* {
      UNITS (Lexing.lexeme lexbuf)}

   | '(' 
      { BEGINCOMPLEX }

   | ')'
      { ENDCOMPLEX }

   | ','
      { SEPARATOR }

   | '<'
      { ANGLE }

   | '['
      { BEGINMATRIX }

   | ']'
      { ENDMATRIX }

   | eof 
      { EOF}


(* arch-tag: DO_NOT_CHANGE_d4979b04-40d1-47e1-aab6-a04c0ded49ff *)