lib/qlang/lexer/tokens.rb in qlang-0.0.27182000 vs lib/qlang/lexer/tokens.rb in qlang-0.0.27182100
- old
+ new
@@ -4,19 +4,22 @@
# NUM
INT = /[0-9]+/
FLO = /[0-9]+\.[0-9]+/
E = /e/
PI = /pi/
- NUM = /(#{FLO}|#{INT}|#{E}|#{PI})/
+ NUM = /(?:#{FLO}|#{INT}|#{E}|#{PI})/
# FUNCTION
- EMBEDDED_FUNC = /(sin|cos|tan|log)/
+ LPRN = /\(/
+ RPRN = /\)/
+ EMBEDDED_FUNC = /(?:sin|cos|tan|log)/
USER_FUNC = /[a-zA-Z]/
- FUNCV = /(#{EMBEDDED_FUNC}|#{USER_FUNC})/
+ # h(x + y) != h * (x + y)
+ FUNCV = /(?:#{EMBEDDED_FUNC}|#{USER_FUNC})(?=#{LPRN})/
# VARIABLE
- VAR = /([a-d]|[f-z])/
+ VAR = /(?:[a-d]|[f-z])/
#VAR_MUL2 = /(?!pi)#{VAR}{2}/
# #VAR_MUL3 = /(?!#{EMBEDDED_FUNC})#{VAR}{3}/
# # FIX:
#VAR_MUL = /(?!#{EMBEDDED_FUNC})#{VAR_MUL2}/
@@ -28,34 +31,43 @@
PLS = /\+/
SUB = /-/
MUL = /\*/
DIV = /\//
EXP = /(\*\*|\^)/
- OPE = /(#{PLS}|#{SUB}|#{MUL}|#{DIV}|#{EXP})/
+ OPE = /(?:#{PLS}|#{SUB}|#{MUL}|#{DIV}|#{EXP})/
- VARNUM = /(#{NUM}|#{VAR})/
+ VARNUM = /(?:#{NUM}|#{VAR})/
ANYSP = ' *'
ANYSTR = /.+/
NONL = /[^\r\n]/
- LPRN = /\(/
- RPRN = /\)/
- PRN = /(#{LPRN}|#{RPRN})/
- LBRC = /\{/
- RBRC = /\}/
- BRC = /(#{LBRC}|#{RBRC})/
+ PRN = /(?:#{LPRN}|#{RPRN})/
+ LBRCS = /\{/
+ RBRCS = /\}/
+ BRCS = /(?:#{LBRCS}|#{RBRCS})/
+
+ LBRCT = /\[/
+ RBRCT = /\]/
+ BRCT = /(?:#{LBRCT}|#{RBRCT})/
+
CLN = /\:/
SCLN = /;/
CMA = /\,/
+ EQL = /\=/
SP = / /
+ NLIN = /(\r|\n)/
+ ITGRLSYM = 'S'
+ # FIXIT
+ SCLN_OR_NELN = /(?:#{SCLN}|#{NLIN})/
+
# TODO: what is better
class Util
def self.string_out(str, partition)
- /#{ANYSP}#{str}(#{ANYSP}#{partition}#{ANYSP}#{str})*#{ANYSP}/
+ /#{ANYSP}#{str}(?:#{ANYSP}#{partition}#{ANYSP}#{str})*#{ANYSP}/
end
def self.func_call(args)
/#{FUNCV}#{LPRN}#{ANYSP}#{args}#{ANYSP}#{RPRN}/
end
@@ -68,11 +80,11 @@
FUNCCN = Util.func_call(NUMS_BY_CMA)
FUNCCV = Util.func_call(VARS_BY_CMA)
FUNCCVN = Util.func_call(VARNUMS_BY_CMA)
- NUMS_BY_SP_BY_SCLN = Util.string_out(NUMS_BY_SP, SCLN)
+ NUMS_BY_SP_BY_SCLN_OR_NELN = Util.string_out(NUMS_BY_SP, SCLN_OR_NELN)
- FORMULA = /(#{OPE}|#{FUNCV}|#{VAR}|#{NUM}|#{PRN}|#{ANYSP})+/
+ FORMULA = /(?:#{OPE}|#{FUNCV}|#{VAR}|#{NUM}|#{PRN}|#{ANYSP})+/
end
end
end