aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2013-06-22 23:51:28 +0000
committerdos-reis <gdr@axiomatics.org>2013-06-22 23:51:28 +0000
commitf18f51d6c959ee88a43166d5e5898ae2e84a49fd (patch)
tree71a0d55677de28e06cb7761b6eaaedd6ef3396c7 /src
parent309b1c778c8a822e40986eabf1d89c402a59df44 (diff)
downloadopen-axiom-f18f51d6c959ee88a43166d5e5898ae2e84a49fd.tar.gz
Use token::value more.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog6
-rw-r--r--src/include/token.H25
-rw-r--r--src/utils/sexpr.H41
-rw-r--r--src/utils/sexpr.cc7
4 files changed, 43 insertions, 36 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 0564199a..61db4288 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,11 @@
2013-06-22 Gabriel Dos Reis <gdr@integrable-solutions.net>
+ * include/token.H (token::base_type): Renam from class_type.
+ (token::value): Add unary, binary, and ternary overloads.
+ * utils/sexpr.H (Sexpr::Token): Use token::value. Clean up.
+
+2013-06-22 Gabriel Dos Reis <gdr@integrable-solutions.net>
+
* include/SourceFile.H: New.
2013-06-21 Gabriel Dos Reis <gdr@integrable-solutions.net>
diff --git a/src/include/token.H b/src/include/token.H
index f9fbe873..9cd6ee9d 100644
--- a/src/include/token.H
+++ b/src/include/token.H
@@ -39,28 +39,31 @@
namespace OpenAxiom {
namespace token {
// -- Underlying representation of a token class.
- using class_type = uint32_t;
+ using base_type = uint32_t;
// -- 8-bit byte data type
using u8 = uint8_t;
- // -- Number of bits per basic char value
- constexpr auto char_bits = 8;
+ constexpr base_type value(u8 c) { return c; }
+ constexpr base_type value(u8 hi, u8 lo) { return (hi << 8) | lo; }
+ constexpr base_type value(u8 hi, u8 mi, u8 lo) {
+ return (value(hi, mi) << 8) | lo;
+ }
// -- Type of literal strings of given number of characters.
template<int N>
using text_chunk = const char(&)[N+1];
// -- Return the token value of certain literal strings.
- constexpr class_type value(text_chunk<0>) { return u8(); }
- constexpr class_type value(text_chunk<1> s) { return u8(s[0]); }
- constexpr class_type value(text_chunk<2> s) {
- return (u8(s[0]) << char_bits) | u8(s[0]);
+ constexpr base_type value(text_chunk<0>) { return u8(); }
+ constexpr base_type value(text_chunk<1> s) {
+ return value(s[0]);
+ }
+ constexpr base_type value(text_chunk<2> s) {
+ return value(s[0], s[1]);
}
- constexpr class_type value(text_chunk<3> s) {
- return (u8(s[0]) << (2 * char_bits))
- | (u8(s[1]) << char_bits)
- | u8(s[2]);
+ constexpr base_type value(text_chunk<3> s) {
+ return value(s[0], s[1], s[2]);
}
// -- Abstract values of tokens.
diff --git a/src/utils/sexpr.H b/src/utils/sexpr.H
index d9ba3b33..5c9934d5 100644
--- a/src/utils/sexpr.H
+++ b/src/utils/sexpr.H
@@ -1,5 +1,6 @@
-// Copyright (C) 2010-2011, Gabriel Dos Reis.
+// Copyright (C) 2010-2013, Gabriel Dos Reis.
// All rights reserved.
+// Written by Gabriel Dos Reis.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -45,11 +46,7 @@
#include <vector>
#include <set>
#include <open-axiom/string-pool>
-
-// Helpers for defining token type values for lexeme with more
-// than characters.
-#define OPENAXIOM_SEXPR_TOKEN1(C) (C)
-#define OPENAXIOM_SEXPR_TOKEN2(C1,C2) (C1 * 256 + C2)
+#include <open-axiom/token>
namespace OpenAxiom {
namespace Sexpr {
@@ -66,22 +63,22 @@ namespace OpenAxiom {
struct Token {
enum Type {
unknown, // unidentified token
- semicolon = OPENAXIOM_SEXPR_TOKEN1(';'), // comment
- dot = OPENAXIOM_SEXPR_TOKEN1('.'), // "."
- comma = OPENAXIOM_SEXPR_TOKEN1(','), // ","
- open_paren = OPENAXIOM_SEXPR_TOKEN1('('), // "("
- close_paren = OPENAXIOM_SEXPR_TOKEN1(')'), // ")"
- apostrophe = OPENAXIOM_SEXPR_TOKEN1('\''), // "'"
- backquote = OPENAXIOM_SEXPR_TOKEN1('`'), // "`"
- backslash = OPENAXIOM_SEXPR_TOKEN1('\\'), // "\\"
- sharp_open_paren = OPENAXIOM_SEXPR_TOKEN2('#','('), // "#("
- sharp_apostrophe = OPENAXIOM_SEXPR_TOKEN2('#','\''), // "#'"
- sharp_colon = OPENAXIOM_SEXPR_TOKEN2('#',':'), // "#:"
- sharp_plus = OPENAXIOM_SEXPR_TOKEN2('#','+'), // "#+"
- sharp_minus = OPENAXIOM_SEXPR_TOKEN2('#','-'), // "#-"
- sharp_dot = OPENAXIOM_SEXPR_TOKEN2('#','.'), // "#."
- comma_at = OPENAXIOM_SEXPR_TOKEN2(',','@'), // ",@"
- digraph_end = OPENAXIOM_SEXPR_TOKEN2(256,256),
+ semicolon = token::value(";"), // comment
+ dot = token::value("."),
+ comma = token::value(","),
+ open_paren = token::value("("),
+ close_paren = token::value(")"),
+ apostrophe = token::value("'"),
+ backquote = token::value("`"),
+ backslash = token::value("\\"),
+ sharp_open_paren = token::value("#("),
+ sharp_apostrophe = token::value("#'"),
+ sharp_colon = token::value("#:"),
+ sharp_plus = token::value("#+"),
+ sharp_minus = token::value("#-"),
+ sharp_dot = token::value("#."),
+ comma_at = token::value(",@"),
+ digraph_end = token::value(0xff,0xff),
integer, // integer literal
character, // character literal
string, // string literal
diff --git a/src/utils/sexpr.cc b/src/utils/sexpr.cc
index 499b566c..3e6b5e90 100644
--- a/src/utils/sexpr.cc
+++ b/src/utils/sexpr.cc
@@ -1,5 +1,6 @@
-// Copyright (C) 2010-2011, Gabriel Dos Reis.
+// Copyright (C) 2010-2013, Gabriel Dos Reis.
// All rights reserved.
+// Written by Gabriel Dos Reis.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -271,7 +272,7 @@ namespace OpenAxiom {
}
case '.': case '(': case ')': case '\'': case '`':
- t.type = Token::Type(OPENAXIOM_SEXPR_TOKEN1(*cur));
+ t.type = Token::Type(token::value(*cur));
t.lexeme = intern(cur, 1);
++cur;
break;
@@ -295,7 +296,7 @@ namespace OpenAxiom {
case '#': {
const Byte* start = cur;
if (cur + 1 < end and special_after_sharp(cur[1])) {
- t.type = Token::Type(OPENAXIOM_SEXPR_TOKEN2(cur[0], cur[1]));
+ t.type = Token::Type(token::value(cur[0], cur[1]));
t.lexeme = intern(cur, 2);
cur += 2;
}