From 70281697aa2b33fed14f7a5a2266b90f03566932 Mon Sep 17 00:00:00 2001 From: Johnny Willemsen Date: Tue, 11 Jul 2023 11:58:06 +0200 Subject: [PATCH] Add support for --idl-version=X where X is default 3, can be set to 4. When set to 4 the IDL4 keywords are added * lib/ridl/runner.rb: * lib/ridl/scanner.rb: --- lib/ridl/runner.rb | 8 ++- lib/ridl/scanner.rb | 120 +++++++++++++++++++++++--------------------- 2 files changed, 71 insertions(+), 57 deletions(-) diff --git a/lib/ridl/runner.rb b/lib/ridl/runner.rb index 61a711c..65e15e7 100644 --- a/lib/ridl/runner.rb +++ b/lib/ridl/runner.rb @@ -28,7 +28,8 @@ module IDL search_incpath: false, backend: nil, macros: { - } + }, + idlversion: 3 }) CORE_OPTIONS = OPTIONS.keys @@ -365,6 +366,11 @@ def init_optparser 'Default: off') { |_| self.options[:debug] = true } + opts.on('--idl-version=VERSION', Integer, + 'Set IDL version', + 'Default: 3') { |v| + self.options[:idlversion] = v + } opts.on('--search-includepath', 'Use include paths to find main IDL source.', 'Default: off') { |_| diff --git a/lib/ridl/scanner.rb b/lib/ridl/scanner.rb index 2791259..c36c848 100644 --- a/lib/ridl/scanner.rb +++ b/lib/ridl/scanner.rb @@ -221,10 +221,67 @@ def initialize(idl_id, checked_id, unescaped_idl_id = nil) end end + LFCR = [ ("\n"), ("\r") ] + SPACES = [ ("\ "), ("\t") ] + WHITESPACE = SPACES + LFCR + + ANNOTATION = '@' + ANNOTATION_STR = '@' + + BREAKCHARS = [ + '(', ')', '[', ']', '{', '}', + '^', '~', + '*', '%', '&', '|', + '<', '=', '>', + ',', ';' ] + + SHIFTCHARS = [ '<', '>' ] + + DIGITS = ('0'..'9').to_a + ALPHA_LC = ('a'..'z').to_a + ALPHA_UC = ('A'..'Z').to_a + OCTALS = ('0'..'7').to_a + HEXCHARS = DIGITS + ('a'..'f').to_a + ('A'..'F').to_a + SIGNS = ['-', '+'] + DOT = '.' + + IDCHARS = ['_' ] + ALPHA_LC + ALPHA_UC + FULL_IDCHARS = IDCHARS + DIGITS + + ESCTBL = CharRegistry.new({ + n: "\n", t: "\t", v: "\v", b: "\b", + r: "\r", f: "\f", a: "\a" + }) + + KEYWORDS = %w( + abstract alias any attribute boolean case char component connector const consumes context custom default double + exception emits enum eventtype factory FALSE finder fixed float getraises home import in inout interface local + long manages mirrorport module multiple native Object octet oneway out port porttype primarykey private provides + public publishes raises readonly setraises sequence short string struct supports switch TRUE truncatable typedef + typeid typename typeprefix unsigned union uses ValueBase valuetype void wchar wstring + ).inject(TokenRegistry.new) { |h, a| h[a.downcase.to_sym] = a + h } + + LITERALS = [ + :integer_literal, + :string_literal, + # :wide_string_literal, + :character_literal, + # :wide_character_literal, + :fixed_pt_literal, + :floating_pt_literal, + :boolean_literal] + + BOOL_LITERALS = { + false: false, + true: true + } + # Scanner def initialize(src, directiver, params = {}) @includepaths = params[:includepaths] || [] @xincludepaths = params[:xincludepaths] || [] + @idlversion = params[:idlversion] || 3 @stack = [] @expansions = [] @prefix = nil @@ -258,6 +315,13 @@ def initialize(src, directiver, params = {}) @in = In.new(i, nm) @scan_comment = false # true if parsing commented annotation @in_annotation = false # true if parsing annotation + + # Extend the IDL keywords with IDL4 when enabled + if @idlversion >= 4 + %w(bitfield bitmask bitset map + ).inject(KEYWORDS) { |h, a| h[a.downcase.to_sym] = a +h } + end end def find_include(fname, all = true) @@ -359,62 +423,6 @@ def parse_error(msg, ex = nil) raise e end - LFCR = [ ("\n"), ("\r") ] - SPACES = [ ("\ "), ("\t") ] - WHITESPACE = SPACES + LFCR - - ANNOTATION = '@' - ANNOTATION_STR = '@' - - BREAKCHARS = [ - '(', ')', '[', ']', '{', '}', - '^', '~', - '*', '%', '&', '|', - '<', '=', '>', - ',', ';' ] - - SHIFTCHARS = [ '<', '>' ] - - DIGITS = ('0'..'9').to_a - ALPHA_LC = ('a'..'z').to_a - ALPHA_UC = ('A'..'Z').to_a - OCTALS = ('0'..'7').to_a - HEXCHARS = DIGITS + ('a'..'f').to_a + ('A'..'F').to_a - SIGNS = ['-', '+'] - DOT = '.' - - IDCHARS = ['_' ] + ALPHA_LC + ALPHA_UC - FULL_IDCHARS = IDCHARS + DIGITS - - ESCTBL = CharRegistry.new({ - n: "\n", t: "\t", v: "\v", b: "\b", - r: "\r", f: "\f", a: "\a" - }) - - KEYWORDS = %w( - abstract alias any attribute boolean case char component connector const consumes context custom default double - exception emits enum eventtype factory FALSE finder fixed float getraises home import in inout interface local - long manages mirrorport module multiple native Object octet oneway out port porttype primarykey private provides - public publishes raises readonly setraises sequence short string struct supports switch TRUE truncatable typedef - typeid typename typeprefix unsigned union uses ValueBase valuetype void wchar wstring - ).inject(TokenRegistry.new) { |h, a| h[a.downcase.to_sym] = a - h } - - LITERALS = [ - :integer_literal, - :string_literal, - # :wide_string_literal, - :character_literal, - # :wide_character_literal, - :fixed_pt_literal, - :floating_pt_literal, - :boolean_literal] - - BOOL_LITERALS = { - false: false, - true: true - } - def is_literal?(o) LITERALS.include?(o) end