Skip to content

Commit

Permalink
Add support for --idl-version=X where X is default 3, can be set to 4…
Browse files Browse the repository at this point in the history
…. When set to 4 the IDL4 keywords are added

    * lib/ridl/runner.rb:
    * lib/ridl/scanner.rb:
  • Loading branch information
jwillemsen committed Jul 11, 2023
1 parent 2769b45 commit 7028169
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 57 deletions.
8 changes: 7 additions & 1 deletion lib/ridl/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ module IDL
search_incpath: false,
backend: nil,
macros: {
}
},
idlversion: 3
})
CORE_OPTIONS = OPTIONS.keys

Expand Down Expand Up @@ -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') { |_|
Expand Down
120 changes: 64 additions & 56 deletions lib/ridl/scanner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 7028169

Please sign in to comment.