Skip to content

Commit

Permalink
Simplify creation of numerics
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Aug 2, 2023
1 parent 7d0c39f commit e5f6ffa
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 147 deletions.
16 changes: 12 additions & 4 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ tokens:
comment: "=~"
- name: FLOAT
comment: "a floating point number"
- name: FLOAT_IMAGINARY
comment: "a floating pointer number with an imaginary suffix"
- name: FLOAT_RATIONAL
comment: "a floating pointer number with a rational suffix"
- name: FLOAT_RATIONAL_IMAGINARY
comment: "a floating pointer number with a rational and imaginary suffix"
- name: GLOBAL_VARIABLE
comment: "a global variable"
- name: GREATER
Expand All @@ -106,12 +112,16 @@ tokens:
comment: "an identifier"
- name: IGNORED_NEWLINE
comment: "an ignored newline"
- name: IMAGINARY_NUMBER
comment: "an imaginary number literal"
- name: INSTANCE_VARIABLE
comment: "an instance variable"
- name: INTEGER
comment: "an integer (any base)"
- name: INTEGER_IMAGINARY
comment: "an integer with an imaginary suffix"
- name: INTEGER_RATIONAL
comment: "an integer with a rational suffix"
- name: INTEGER_RATIONAL_IMAGINARY
comment: "an integer with a rational and imaginary suffix"
- name: KEYWORD_ALIAS
comment: "alias"
- name: KEYWORD_AND
Expand Down Expand Up @@ -266,8 +276,6 @@ tokens:
comment: "+="
- name: QUESTION_MARK
comment: "?"
- name: RATIONAL_NUMBER
comment: "a rational number literal"
- name: REGEXP_BEGIN
comment: "the beginning of a regular expression"
- name: REGEXP_END
Expand Down
11 changes: 1 addition & 10 deletions include/yarp/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ typedef struct yp_lex_mode {

// This state is used when we are lexing a string or a string-like
// token, as in string content with either quote or an xstring.
YP_LEX_STRING,

// you lexed a number with extra information attached
YP_LEX_NUMERIC,
YP_LEX_STRING
} mode;

union {
Expand Down Expand Up @@ -163,12 +160,6 @@ typedef struct yp_lex_mode {
char breakpoints[6];
} string;

struct {
yp_token_type_t type;
const char *start;
const char *end;
} numeric;

struct {
// These pointers point to the beginning and end of the heredoc
// identifier.
Expand Down
10 changes: 8 additions & 2 deletions lib/yarp/lex_compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class LexCompat
EQUAL_GREATER: :on_op,
EQUAL_TILDE: :on_op,
FLOAT: :on_float,
FLOAT_IMAGINARY: :on_imaginary,
FLOAT_RATIONAL: :on_rational,
FLOAT_RATIONAL_IMAGINARY: :on_imaginary,
GREATER: :on_op,
GREATER_EQUAL: :on_op,
GREATER_GREATER: :on_op,
Expand All @@ -64,8 +67,10 @@ class LexCompat
HEREDOC_START: :on_heredoc_beg,
IDENTIFIER: :on_ident,
IGNORED_NEWLINE: :on_ignored_nl,
IMAGINARY_NUMBER: :on_imaginary,
INTEGER: :on_int,
INTEGER_IMAGINARY: :on_imaginary,
INTEGER_RATIONAL: :on_rational,
INTEGER_RATIONAL_IMAGINARY: :on_imaginary,
INSTANCE_VARIABLE: :on_ivar,
INVALID: :INVALID,
KEYWORD___ENCODING__: :on_kw,
Expand Down Expand Up @@ -145,7 +150,8 @@ class LexCompat
PLUS: :on_op,
PLUS_EQUAL: :on_op,
QUESTION_MARK: :on_op,
RATIONAL_NUMBER: :on_rational,
RATIONAL_FLOAT: :on_rational,
RATIONAL_INTEGER: :on_rational,
REGEXP_BEGIN: :on_regexp_beg,
REGEXP_END: :on_regexp_end,
SEMICOLON: :on_semicolon,
Expand Down
Loading

0 comments on commit e5f6ffa

Please sign in to comment.